コード例 #1
0
ファイル: landlord.py プロジェクト: seokhohong/landlord_ai
 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())
コード例 #2
0
ファイル: player.py プロジェクト: seokhohong/landlord_ai
 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))
コード例 #3
0
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())
コード例 #4
0
ファイル: play_vs_ai.py プロジェクト: seokhohong/landlord_ai
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())