Ejemplo n.º 1
0
 def test_setup(self):
     players = [LearningPlayer('v1', None)] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 4 + [Card.KING] * 4 +
         [Card.QUEEN] * 4 + [Card.JACK] * 4 + [Card.THREE],
         TurnPosition.SECOND: [Card.TEN] * 4 + [Card.NINE] * 4 +
         [Card.EIGHT] * 4 + [Card.SEVEN] * 4 + [Card.THREE],
         TurnPosition.THIRD: [Card.FIVE] * 4 + [Card.FOUR] * 4 +
         [Card.SIX] * 4 + [Card.TWO] * 4 + [Card.THREE] * 2 +
         [Card.LITTLE_JOKER] + [Card.BIG_JOKER]
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 2)
     self.assertTrue(game.get_current_position() == TurnPosition.THIRD)
     game.play_move(None)
     self.assertTrue(
         game.get_current_position() == TurnPosition.THIRD.next())
     self.assertTrue(len(game.get_move_logs()) == 1)
     self.assertTrue(game.get_move_logs()[0][1] is None)
     game.play_move(
         SpecificMove(RankedMoveType(MoveType.BOMB, Card.KING),
                      cards=Counter({Card.KING: 4})))
     self.assertTrue(game.get_current_position() == TurnPosition.SECOND)
     feature_matrix = players[1]._derive_features(game)
     self.assertTrue(feature_matrix[0][-6] == 1)
     self.assertTrue(feature_matrix[0][-2] == 1)
     self.assertTrue(feature_matrix[1][10] == 4)
     self.assertTrue(np.sum(feature_matrix) == 7)
Ejemplo n.º 2
0
 def test_extended_game(self):
     game = LandlordGame(players=[RandomPlayer(name='random')] * 3)
     game.play_round()
     game2 = copy(game)
     self.assertTrue(game.get_move_logs() == game2.get_move_logs())
     self.assertTrue(
         game.get_hand(TurnPosition.SECOND) == game2.get_hand(
             TurnPosition.SECOND))
     self.assertTrue(game.get_last_played() == game2.get_last_played())
Ejemplo n.º 3
0
 def test_endgame_scenario(self):
     players = [LearningPlayer('v1')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 1,
         TurnPosition.SECOND: [Card.TEN] * 1,
         TurnPosition.THIRD: [Card.JACK, Card.QUEEN]
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 2)
     game.main_game()
     self.assertTrue(TurnPosition.FIRST in game.get_winners())
     self.assertTrue(len(game.get_move_logs()) == 2)
Ejemplo n.º 4
0
 def test_llord_winning(self):
     players = [LearningPlayer(name='random')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 4 + [Card.KING] * 4 +
         [Card.QUEEN] * 4 + [Card.JACK] * 4 + [Card.THREE],
         TurnPosition.SECOND: [Card.TEN] * 4 + [Card.NINE] * 4 +
         [Card.EIGHT] * 4 + [Card.SEVEN] * 4 + [Card.THREE],
         TurnPosition.THIRD: [Card.FIVE] * 4
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 3)
     game.main_game()
     self.assertTrue(TurnPosition.THIRD in game.get_winners())
     self.assertTrue(len(game.get_move_logs()) == 1)
Ejemplo n.º 5
0
 def test_peasant_winning(self):
     players = [LearningPlayer(name='random')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 4,
         TurnPosition.SECOND: [Card.TEN] + [Card.THREE],
         TurnPosition.THIRD: [Card.FIVE] * 3 + [Card.THREE] + [Card.FOUR]
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 3)
     hand_vector = players[0].get_hand_vector(game, TurnPosition.FIRST)
     self.assertTrue(hand_vector[11] == 4)
     self.assertTrue(hand_vector[-2] == 2)
     self.assertTrue(hand_vector[-3] == 5)
     self.assertTrue(hand_vector[-1] == 4)
     # self.assertTrue(np.sum(hand_vector) == 4)
     game.main_game()
     self.assertTrue(TurnPosition.THIRD not in game.get_winners())
     self.assertTrue(TurnPosition.SECOND in game.get_winners())
     self.assertTrue(TurnPosition.FIRST in game.get_winners())
     self.assertTrue(len(game.get_move_logs()) == 2)