コード例 #1
0
ファイル: driver_test.py プロジェクト: kpeng94/splendor-ai
 def test_DriverInitializesWithGameState(self):
   agents = [FakeAgent(), FakeAgent()]
   game_state = setup.SinglePlayerEmptyGameState()._replace(
     player_states=[
       setup.NewPlayerState(), setup.NewPlayerState()])
   self.assertIsNotNone(driver.Driver(
     agents, game_state=game_state, game_rules=game_rules.GAME_RULES))
コード例 #2
0
ファイル: driver_test.py プロジェクト: kpeng94/splendor-ai
 def test_DriverInitializesWithGameStateWrongNumAgentsFails(self):
   agents = [FakeAgent(), FakeAgent(), FakeAgent()]
   game_state = setup.SinglePlayerEmptyGameState()._replace(
     player_states=[
       setup.NewPlayerState(), setup.NewPlayerState()])
   with self.assertRaises(IndexError):
     driver.Driver(
       agents, game_state=game_state,
       game_rules=game_rules.GAME_RULES)
コード例 #3
0
ファイル: driver_test.py プロジェクト: kpeng94/splendor-ai
 def test_DriverGetWinnersNone(self):
   agents = [FakeAgent(), FakeAgent()]
   game_state = setup.SinglePlayerEmptyGameState()._replace(
     player_states=[
       setup.NewPlayerState(),
       setup.NewPlayerState(),
     ],
     turn=0,
   )
   game_driver = driver.Driver(
     agents, game_state=game_state,
     game_rules=game_rules.GAME_RULES)
   winners = game_driver.GetWinners()
   self.assertEquals(winners, tuple())
コード例 #4
0
 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)
コード例 #5
0
ファイル: driver_test.py プロジェクト: kpeng94/splendor-ai
 def _GetWinningPlayerState(self):
   """Helper method that returns a winning player state."""
   player_state = setup.NewPlayerState()._replace(
     purchased_cards=[
       setup.EmptyBlueDevelopmentCard()._replace(points=5),
       setup.EmptyBlueDevelopmentCard()._replace(points=4),
     ],
     noble_tiles=[
       setup.EmptyNobleTile()._replace(points=3),
       setup.EmptyNobleTile()._replace(points=3),
     ])
   return player_state
コード例 #6
0
 def test_OpponentStateHidesHiddenReservedCards(self):
     player_state = setup.NewPlayerState()
     player_state.hidden_reserved_cards.append(
         DevelopmentCard(asset_id="",
                         level=Deck.LEVEL_1,
                         points=0,
                         gem=GemType.RED,
                         cost={}))
     opponent_state = player_game_state.OpponentState(player_state)
     with self.assertRaises(AttributeError):
         _ = opponent_state.player_state
     with self.assertRaises(AttributeError):
         _ = opponent_state.hidden_reserved_cards
     self.assertEquals(opponent_state.num_hidden_reserved_cards, 1)
コード例 #7
0
ファイル: driver_test.py プロジェクト: kpeng94/splendor-ai
 def test_DriverGetWinnersWithTieBreak(self):
   agents = [FakeAgent(), FakeAgent()]
   game_state = setup.SinglePlayerEmptyGameState()._replace(
     player_states=[
       self._GetWinningPlayerState(),
       setup.NewPlayerState()._replace(
         purchased_cards=[
           setup.EmptyBlueDevelopmentCard()._replace(points=15),
         ]),
     ],
     turn=0,
   )
   game_driver = driver.Driver(
     agents, game_state=game_state,
     game_rules=game_rules.GAME_RULES)
   winners = game_driver.GetWinners()
   self.assertEquals(winners, (1,))
コード例 #8
0
ファイル: setup_test.py プロジェクト: kpeng94/splendor-ai
 def _AssertPlayerStates(self, game_state, num_players):
     self.assertEquals(len(game_state.player_states), num_players)
     for player_state in game_state.player_states:
         self.assertEquals(player_state, setup.NewPlayerState())
     self.assertEquals(game_state.turn, 0)
コード例 #9
0
 def test_OpponentStateIsSelfState(self):
     opponent_state = player_game_state.OpponentState(
         setup.NewPlayerState())
     self.assertIsInstance(opponent_state, player_game_state.SelfState)
コード例 #10
0
    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))