Esempio n. 1
0
    def test_player_game(self):
        players = [
            LearningPlayer(name='random',
                           estimation_mode=LearningPlayer.ACTUAL_Q)
        ] * 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, 3)
        game.main_game()
        players[0].compute_future_q(game)
        self.assertTrue(np.sum(np.abs(game.get_scores())) > 0)
        # game is over
        self.assertTrue(np.abs(players[0]._record_future_q[-1]) > 0.5)

        features = players[0]._derive_features(game)
        self.assertTrue(
            np.sum(features[:, players[0].get_feature_index('I_AM_LANDLORD')])
            != 0)
        # it is possible this guy never plays, eventually
        self.assertTrue(
            np.sum(features[:, players[0].
                            get_feature_index('I_AM_BEFORE_LANDLORD')]) != 0)
Esempio n. 2
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)
Esempio n. 3
0
    def test_hand_vector_v2(self):
        players = [
            LearningPlayer_v2(name='random',
                              estimation_mode=LearningPlayer.ACTUAL_Q)
            for _ in range(3)
        ]
        game = LandlordGame(players=players)
        hands = {
            TurnPosition.FIRST: [Card.ACE] * 4,
            TurnPosition.SECOND: [Card.TEN] * 3 + [Card.THREE],
            TurnPosition.THIRD: [Card.FIVE] * 3 + [Card.THREE] + [Card.FOUR]
        }
        game._betting_complete = True
        game.force_setup(TurnPosition.SECOND, hands, 3)
        best_move = SpecificMove(RankedMoveType(MoveType.TRIPLE_SINGLE_KICKER,
                                                Card.TEN),
                                 cards=Counter({
                                     Card.TEN: 3,
                                     Card.THREE: 1
                                 }))
        move_vector = players[1].compute_move_vector(
            TurnPosition.SECOND, game.get_landlord_position(), best_move)
        remaining_hand_vector = players[1].compute_remaining_hand_vector(
            game, move_vector, TurnPosition.SECOND)[:-3]

        self.assertEqual(np.sum(remaining_hand_vector), 0)
Esempio n. 4
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)
Esempio n. 5
0
 def test_landlord_bombing(self):
     players = [LearningPlayer('v1')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 4 + [Card.THREE],
         TurnPosition.SECOND: [Card.TEN] * 4 + [Card.THREE],
         TurnPosition.THIRD: [Card.FIVE] * 4 + [Card.THREE]
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 2)
     game.play_move(
         SpecificMove(RankedMoveType(MoveType.BOMB, Card.FIVE),
                      Counter({Card.FIVE: 4})))
     self.assertTrue(game._bet_amount == 4)
Esempio n. 6
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)
Esempio n. 7
0
 def test_landlord_game_ending(self):
     players = [LearningPlayer('v1')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * 4,
         TurnPosition.SECOND: [Card.TEN] * 4,
         TurnPosition.THIRD: [Card.FIVE] * 4
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 2)
     self.assertTrue(
         game.move_ends_game(
             SpecificMove(RankedMoveType(MoveType.BOMB, Card.FIVE),
                          Counter({Card.FIVE: 4}))))
     self.assertFalse(
         game.move_ends_game(
             SpecificMove(RankedMoveType(MoveType.BOMB, Card.TEN),
                          Counter({Card.TEN: 4}))))
Esempio n. 8
0
 def test_sweep(self):
     players = [LearningPlayer('v1')] * 3
     game = LandlordGame(players=players)
     hands = {
         TurnPosition.FIRST: [Card.ACE] * LandlordGame.DEAL_SIZE,
         TurnPosition.SECOND: [Card.TEN] * LandlordGame.DEAL_SIZE,
         TurnPosition.THIRD: [Card.FIVE] * 4
     }
     game._betting_complete = True
     game.force_setup(TurnPosition.THIRD, hands, 2)
     game.play_move(
         SpecificMove(RankedMoveType(MoveType.BOMB, Card.FIVE),
                      Counter({Card.FIVE: 4})))
     self.assertTrue(game.peasants_have_no_plays())
     self.assertTrue(game.get_scores()[TurnPosition.THIRD] == 2 * 2 * 2 *
                     LandlordGame.SWEEP_MULTIPLIER)
     self.assertEqual(game.get_r(), 24)
     self.assertEqual(game.get_winbased_r(), 1)
Esempio n. 9
0
 def test_player_move(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 + [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, 3)
     game2 = copy(game)
     game.play_move(
         SpecificMove(RankedMoveType(MoveType.BOMB, Card.FIVE),
                      Counter({Card.FIVE: 4})))
     self.assertNotEqual(game2.get_hand(TurnPosition.THIRD),
                         game.get_hand(TurnPosition.THIRD))
Esempio n. 10
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)
Esempio n. 11
0
 def test_betting(self):
     players = [LearningPlayer('v1')] * 3
     game = LandlordGame(players=players)
     game.force_current_position(TurnPosition.SECOND)
     game.force_kitty([Card.LITTLE_JOKER, Card.BIG_JOKER, Card.THREE])
     game._make_bet_move(BetMove(2))
     game._make_bet_move(None)
     self.assertEqual(game.get_last_played(), BetMove(2))
     game._make_bet_move(BetMove(3))
     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] * 1
     }
     game.force_setup(TurnPosition.FIRST, hands, 2)
     game.play_move(
         SpecificMove(RankedMoveType(MoveType.BOMB, Card.ACE),
                      cards=Counter({Card.ACE: 4})))
     feature_matrix = players[1]._derive_features(game)
     self.assertTrue(feature_matrix[0][-3] == 2)
     self.assertTrue(np.sum(players[1]._derive_features(game)) == 16)