Feature/buy asset#11
Conversation
RomanCantu
commented
Jun 7, 2025
- Handle buy asset requests
- new update method for AssetRepos: update_owner
- add a message to justify the (un)successful BuyAssetRequest in BuyAssetResponse
| else: | ||
| success = True | ||
| message = f"Player {player.id} successfully bought asset {asset.id}." | ||
| game_state.players.add_money(player.id, -asset.purchase_cost) |
There was a problem hiding this comment.
Maybe it would be clearer to have a method like "subtract money".
Also it is always better to use keyword arguments rather than positional arguments in case somebody changes the orders of arguments in future
# Conflicts: # src/engine/engine.py # src/models/message.py
|
Generally speaking, a function that takes an object as an argument and does some operation should either:
In PlayerRepo._adjust_money I made a mistake by forgetting to add '.copy()' so it is BOTH mutating the object and returning a new object. In Engine.handle_buy_asset_message, you should not be mutating the game_state object that is passed to the function. The new game state should be generated something like this. Also note that for "players" and 'assets" we are also using the return-value, not expected a mutation of the original object |
|
Generally speaking, when you pass an argument to a function that acts on that argument either:
If you look at PlayerRepo._adjust_money you can see an example of where I did this wrong, I forgot to add ".copy()" after the df so this function is BOTH mutating the original object and returning a new one. |