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_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. 3
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. 4
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)