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())
def play_game(self): while True: players = self.pick_players() game = LandlordGame(players=players) # play a meaningful game game.play_round() if game.has_winners(): players_to_record = game._winners if random.random() < self.record_everyone_pct: players_to_record = list(TurnPosition) for pos in players_to_record: player = game.get_ai(pos) self.record_player(game, player) self.track_stats(game) break # clear out in case a full game wasn't played for player in players: player._reset_records()
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)
if __name__ == "__main__": #players = [load_net('4_11_actualq4_model20'), # load_net('4_11_actualq4_model20'), # load_net('4_11_actualq4_model20')] players = [ load_v2_net('4_13_stream2_model3_170', '../stream_models/'), load_v2_net('4_13_stream2_model2_194', '../stream_models/'), load_v2_net('4_13_stream2_model1_141', '../stream_models/') ] while True: game = LandlordGame(players=players) game.play_round(debug=True) if game.has_winners(): break def printout_floats(array): print(', '.join(["%.3f" % val for val in array])) print('\n') for i in range(3): players[i].compute_future_q(game) print(players[i].get_name()) printout_floats(players[i].get_estimated_qs()) printout_floats(players[i]._record_state_q) print('\n') print('')
def test_best_montecarlo(self): players = [LearningPlayer(name='random')] * 3 game = LandlordGame(players=players) game.play_round(debug=False)
def test_nobet_game(self): game = LandlordGame(players=[NoBetPlayer(name='random')] * 3) game.play_round() self.assertTrue(np.sum(np.abs(game._scores)) == 0)
def test_many_games(self): for i in range(10): game = LandlordGame(players=[RandomPlayer(name='random')] * 3) game.play_round()