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 human_game(player_names, perspective): perspective_hand = None players = [] for player_name in player_names: if player_name == perspective: perspective_hand = manual_hand() player_is_perspective = (player_name == perspective) players.append( HumanPlayer(name=player_name, reference_player=reference_player, known_hand=player_is_perspective, ai_before=player_is_perspective)) game = LandlordGame(players, kitty_callback=manual_kitty) first_player = get_first_player(game) game.force_current_position(first_player) game.force_hand(perspective_position(game, perspective), perspective_hand) while not game.is_round_over(): current_player = game.get_current_player() current_position = game.get_current_position() best_move, best_move_q = current_player.decide_best_move(game) print(current_player.get_name(), "(" + game.get_position_role_name(current_position) + ", " \ + str(len(game.get_hand(current_position))) + "):", best_move, '(' + str(best_move_q) + ')') # play with known hand if it matches perspective game.play_move(best_move, hand_known=current_player.get_name() == perspective) if type(game.get_last_played()) == KittyReveal: print(game.get_last_played()) if game.has_winners(): for winner in game.get_winners(): print('WINNERS:', game.get_ai_players()[winner].get_name())
def play_against_two(players, show_q=True): game = LandlordGame(players) while not game.is_round_over(): current_player = game.get_current_player() current_position = game.get_current_position() best_move, best_move_q = current_player.decide_best_move(game) if show_q: best_move_q_str = '(' + str(best_move_q) + ')' else: best_move_q_str = '' print(current_player.get_name(), "(" + game.get_position_role_name(current_position) + ", " \ + str(len(game.get_hand(current_position))) + "):", best_move, best_move_q_str) game.play_move(best_move) if type(game.get_last_played()) == KittyReveal: print(game.get_last_played()) if game.has_winners(): for winner in game.get_winners(): print('WINNERS:', game.get_ai_players()[winner].get_name())
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)