#S0017. 游戏内物品交易

游戏内物品交易

1. Description & Background

🎮 In-Game Item Trading

In games like Animal Crossing, players exchange items. The system must:

  • Verify both players have the required items
  • Update inventories after successful trades

🛠️ Task

Implement a trading system with commands:

  1. add player item
  2. trade from_player to_player give_item request_item
  3. end to finish

Rules:

  • Trade fails if items are missing (output [Failed] Conditions not met)
  • Output [Success] Trade details on success

2. Input & Output

Input:

  • Multiple commands ending with end

Output:

  1. Immediate result for each trade attempt
  2. Final inventories sorted by player name

Example

# Input:  
add Alice apple  
add Alice apple  
add Bob wood  
trade Alice Bob apple wood  
trade Bob Alice wood stone  
end  

# Process Output:  
[Success] Alice traded apple for Bob's wood  
[Failed] Conditions not met  

# Final Output:  
Alice: wood, apple  
Bob: apple