diff --git a/coup.py b/coup.py index f255200..2d48644 100755 --- a/coup.py +++ b/coup.py @@ -20,8 +20,8 @@ def main(): - # Create game handler with 3 players - handler = ResistanceCoupGameHandler(3) + # Create game handler with 5 players + handler = ResistanceCoupGameHandler(5) print(f"First player is {handler.current_player}") # Create AI players diff --git a/src/handler/game_handler.py b/src/handler/game_handler.py index edc6009..fe06910 100644 --- a/src/handler/game_handler.py +++ b/src/handler/game_handler.py @@ -167,23 +167,42 @@ def _deactivate_player(self) -> Optional[Player]: def _determine_win_state(self) -> bool: return sum(player.is_active for player in self._players.values()) == 1 +<<<<<<< Updated upstream def validate_action(self, action: Action, current_player: Player, target_player: Optional[Player]) -> bool: if action.action_type in [ActionType.coup, ActionType.steal, ActionType.assassinate] and not target_player: return False # Can't take coin if the treasury has none +======= + def _validate_action( + self, action: Action, current_player: Player, target_player: Optional[Player] + ): + if current_player.coins >= 10 and action.action_type != ActionType.coup: + raise Exception(f"Invalid action: You have more than 10 coins and have to perform {ActionType.coup} action.") + + if ( + action.action_type in [ActionType.coup, ActionType.steal, ActionType.assassinate] and not target_player + ): + raise Exception(f"Invalid action: You need a `target_player` for the action {action.action_type}") + + # Can't take coin if the treasury has none + if ( + action.action_type in [ActionType.income, ActionType.foreign_aid, ActionType.tax] and self._treasury == 0 + ): + raise Exception(f"Invalid action: The treasury has no coin to give") +>>>>>>> Stashed changes # You can only do a coup if you have at least 7 coins. if action.action_type == ActionType.coup and current_player.coins < 7: - return False + raise Exception(f"Invalid action: You need more coins to be able to perform the {ActionType.coup} action.") # You can only do an assassination if you have at least 3 coins. if action.action_type == ActionType.assassinate and current_player.coins < 3: - return False + raise Exception(f"Invalid action: You need more coins to be able to perform the {ActionType.assassinate} action.") # Can't steal from player with 0 coins if action.action_type == ActionType.steal and target_player.coins == 0: - return False + raise Exception(f"Invalid action: You cannot steal from a player with no coins.") return True @@ -198,8 +217,12 @@ def perform_action(self, player_name: str, action_name: ActionType, target_playe if player_name != self.current_player.name: raise Exception(f"Wrong player, it is currently {self.current_player.name}'s turn.") +<<<<<<< Updated upstream if not self.validate_action(action, self.current_player, target_player): raise Exception("Invalid action") +======= + self._validate_action(action, self.current_player, target_player) +>>>>>>> Stashed changes result_action_str = ""