def test_PlayerGameStateCanTopDeck(self): game_state = setup.SinglePlayerEmptyGameState()._replace( development_cards={ Deck.LEVEL_1: [setup.EmptyBlueDevelopmentCard()] * 5, Deck.LEVEL_2: [setup.EmptyBlueDevelopmentCard()] * 4, }) state = player_game_state.PlayerGameState(game_state, game_rules.GAME_RULES) self.assertEquals( state.revealed_cards, { Deck.LEVEL_1: [setup.EmptyBlueDevelopmentCard()] * 4, Deck.LEVEL_2: [setup.EmptyBlueDevelopmentCard()] * 4, }) self.assertTrue(state.CanTopDeck(Deck.LEVEL_1)) self.assertFalse(state.CanTopDeck(Deck.LEVEL_2))
def RunNextTurn(self): """Returns the next agent's PlayerAction and updates the game state.""" turn = self._game_state.turn agent_to_play = self._agents[turn] game_view = player_game_state.PlayerGameState(self._game_state, self._game_rules) # Get the agent's PlayerAction for this turn. player_action = agent_to_play.PlayTurn(game_view) # Validate that player_action is valid. engine.check_player_action(game_view, player_action) # Update game state with player_action. self._game_state = engine.update_game_state(self._game_state, player_action, self._game_rules) self._game_state._replace(turn=turn + 1 % len(self._agents)) return player_action
def RunNextTurn(self): """Returns the next agent's PlayerAction and updates the game state.""" turn = self._game_state.turn agent_to_play = self._agents[turn] game_view = player_game_state.PlayerGameState(self._game_state, self._game_rules) # Get the agent's PlayerAction for this turn. player_action = agent_to_play.PlayTurn(game_view) # TODO: check if player_action is valid. if False: raise ValueError("Agent " + str(turn) + "'s PlayerAction is invalid") # TODO: update game state with player_action. self._game_state = self._game_state self._game_state._replace(turn=turn + 1 % len(self._agents)) return player_action
def test_PlayerGameStateHasOpponentStates(self): player_states = [ setup.NewPlayerState()._replace(gems={GemType.RED: 1}), setup.NewPlayerState()._replace(gems={GemType.BLUE: 1}), setup.NewPlayerState()._replace(gems={GemType.GREEN: 1}), setup.NewPlayerState()._replace(gems={GemType.WHITE: 1}), ] game_state = setup.SinglePlayerEmptyGameState()._replace( player_states=player_states, turn=1) state = player_game_state.PlayerGameState(game_state, game_rules.GAME_RULES) opponent_gems = [] for opp in state.opponent_states: opponent_gems.append(opp.gem_counts) expected_opponent_gems = [ player_states[2].gems, player_states[3].gems, player_states[0].gems, ] self.assertEquals(opponent_gems, expected_opponent_gems)
def test_PlayerGameStateCanTakeTwo(self): game_state = setup.SinglePlayerEmptyGameState()._replace( available_gems={GemType.RED: 4}) state = player_game_state.PlayerGameState(game_state, game_rules.GAME_RULES) self.assertTrue(state.CanTakeTwo(GemType.RED))
def test_PlayerGameStateCanPurchaseCard(self): owned_dev_card_1 = DevelopmentCard(asset_id="", level=Deck.LEVEL_1, points=0, gem=GemType.RED, cost={GemType.GREEN: 1}) player_states = [ setup.NewPlayerState()._replace(gems={ GemType.RED: 4, GemType.BLUE: 2, GemType.GOLD: 1 }, purchased_cards=[owned_dev_card_1 ]), setup.NewPlayerState()._replace(gems={GemType.BLUE: 1}), setup.NewPlayerState()._replace(gems={GemType.GREEN: 1}), setup.NewPlayerState()._replace(gems={GemType.WHITE: 1}), ] game_state = setup.SinglePlayerEmptyGameState()._replace( player_states=player_states, turn=0) state = player_game_state.PlayerGameState(game_state, game_rules.GAME_RULES) dev_card_1 = DevelopmentCard(asset_id="", level=Deck.LEVEL_1, points=0, gem=GemType.RED, cost={ GemType.BLUE: 1, GemType.GREEN: 1, GemType.RED: 1, GemType.WHITE: 1 }) self.assertFalse(state.CanPurchaseCard(dev_card_1)) dev_card_2 = DevelopmentCard(asset_id="", level=Deck.LEVEL_1, points=0, gem=GemType.RED, cost={ GemType.BLUE: 2, GemType.RED: 3, GemType.WHITE: 1 }) self.assertFalse(state.CanPurchaseCard(dev_card_2)) dev_card_3 = DevelopmentCard(asset_id="", level=Deck.LEVEL_1, points=0, gem=GemType.RED, cost={ GemType.BLUE: 2, GemType.RED: 3 }) self.assertTrue(state.CanPurchaseCard(dev_card_3)) dev_card_4 = DevelopmentCard(asset_id="", level=Deck.LEVEL_1, points=0, gem=GemType.RED, cost={ GemType.BLUE: 2, GemType.RED: 5 }) self.assertTrue(state.CanPurchaseCard(dev_card_4))