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)
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)
def test_full_game(self): players = [LearningPlayer(name='random') for _ in range(3)] game = LandlordGame(players=players) game.play_round() while np.sum(np.abs(game.get_scores())) == 0: players = [LearningPlayer(name='random') for _ in range(3)] game = LandlordGame(players=players) game.play_round() # game is over for i in range(3): # print(players[i].record_future_q[-1]) # self.assertTrue(np.abs(players[i].record_future_q[-1]) > 0.5) features = players[i]._derive_features(game) self.assertTrue( np.sum(features[:, players[i].get_feature_index('I_AM_LANDLORD' )]) != 0) # it is possible this guy never plays, eventually self.assertTrue( np.sum(features[:, players[i]. get_feature_index('I_AM_BEFORE_LANDLORD')]) != 0)