예제 #1
0
def test_turn():
    game = Game(players=2)
    game.deal()
    game.flop()
    game.turn()
    assert len(game.board) == 4
    assert len(game.deck.cards) == 44
예제 #2
0
def test_river():
    game = Game(players=5)
    game.deal()
    game.flop()
    game.turn()
    game.river()
    assert len(game.board) == 5
    assert len(game.deck.cards) == 37
예제 #3
0
def test_big_blinds_and_button_and_pot():
    game = Game(players=4, button_position=2)
    game.deal()
    game.post_blinds()

    assert game.pot == 1.5
    assert game.players[0].stack == 99
    assert game.players[1].stack == 100
    assert game.players[2].stack == 100
    assert game.players[3].stack == 99.5
예제 #4
0
def test_player_hand_has_right_number_cards():
    game = Game(players=3)

    game.deal()
    hand = game.get_player_hand(player=2)
    assert len(hand) == 2

    game.flop()
    hand = game.get_player_hand(player=2)
    assert len(hand) == 5

    game.turn()
    hand = game.get_player_hand(player=2)
    assert len(hand) == 6

    game.river()
    hand = game.get_player_hand(player=2)
    assert len(hand) == 7
예제 #5
0
def test_flop():
    game = Game(players=2)
    game.deal()
    game.flop()
    assert len(game.board) == 3
예제 #6
0
def test_game_has_deck():
    game = Game(players=2)
    deck = game.deck
    assert len(deck.cards)
예제 #7
0
def test_game_can_deal_cards():
    game = Game(players=2)
    game.deal()
    assert len(game.deck) == 48
    assert len(game.players[0].hole_cards) == 2
    assert len(game.players[1].hole_cards) == 2
예제 #8
0
def test_game():
    game = Game(players=2)
    assert len(game.players)
예제 #9
0
def test_player():
    game = Game(players=2)
    second_player = game.players[1]
    assert second_player.stack == 100
예제 #10
0

class RandomModel(Agent):
    def choose(self, state):
        valid_moves = self.get_moves()

        # player i [手牌] // [出牌]
        hand_card = []
        for i, n in enumerate(Card.all_card_name):
            hand_card.extend([n]*self.get_hand_card()[i])
        print("Player {}".format(self.player_id), ' ', hand_card, end=' // ')

        i = np.random.choice(len(valid_moves))
        move = valid_moves[i]
        print(Card.visual_card(move))
        print(move)
        return move, None


if __name__=="__main__":
    game = Game([RandomModel(i) for i in range(3)])

    for i_episode in range(1):
        game.game_reset()
        game.show()
        for i in range(100):
            pid, state, cur_moves, cur_move, winner, info = game.step()
            #game.show()
            if winner != -1:
                print('Winner:{}'.format(winner))
                break
예제 #11
0
    def choose(self, state):
        valid_moves = self.get_moves()

        # player i [手牌] // [出牌]
        hand_card = []
        for i, n in enumerate(Card.all_card_name):
            hand_card.extend([n] * self.get_hand_card()[i])
        print("Player {}".format(self.player_id), ' ', hand_card, end=' // ')

        i = np.random.choice(len(valid_moves))
        move = valid_moves[i]
        print(Card.visual_card(move))

        return move, None


if __name__ == "__main__":
    #   game = Game([RandomModel(i) for i in range(3)])
    game = Game([MctsModel(0), RandomModel(1), RandomModel(2)])
    # win_count = [0, 0, 0]
    for i_episode in range(1):
        game.game_reset()
        # game.show()
        for i in range(100):
            pid, state, cur_moves, cur_move, winner, info = game.step()
            #game.show()
            if winner != -1:
                print(str(i_episode) + ': ' + 'Winner:{}'.format(winner))
                #  win_count[winner] += 1
                break
    #  print(win_count)
예제 #12
0
    def choose(self, state):
        valid_moves = self.get_moves()

        # player i [手牌] // [出牌]
        hand_card = []
        for i, n in enumerate(Card.all_card_name):
            hand_card.extend([n] * self.get_hand_card()[i])
        #  print("Player {}".format(self.player_id), ' ', hand_card, end=' // ')

        i = np.random.choice(len(valid_moves))
        move = valid_moves[i]
        #  print(Card.visual_card(move))

        return move, None


if __name__ == "__main__":
    #   game = Game([RandomModel(i) for i in range(3)])
    game = Game([RandomModel(0), RandomModel(1), RandomModel(2)])
    # win_count = [0, 0, 0]
    for i_episode in range(1):
        game.game_reset()
        # game.show()
        for i in range(100):
            pid, state, cur_moves, cur_move, winner, info = game.step()
            #game.show()
            if winner != -1:
                print(str(i_episode) + ': ' + 'Winner:{}'.format(winner))
                #  win_count[winner] += 1
                break
    #  print(win_count)
예제 #13
0
    print('{} Using device: {}'.format(__name__, device))

    # Seeding
    if args.seed is not None:
        # logger.info('{} Setting random seed'.format(__name__))
        print('{} Setting random seed'.format(__name__))
        seed = args.seed
        np.random.seed(seed)
        torch.manual_seed(seed)
        if torch.cuda.is_available():
            torch.cuda.manual_seed(seed)

    # game = Game([RandomModel(i) for i in range(3)])
    # game should be a combine of Agents to form a Game
    game = Game([CNNModel(0)] + [RandomModel(i) for i in range(1, 3)])
    MAX_ROUNDS = 100
    TRAIND_ID = 0  # 进行训练的模型,0代表地主,1代表地主下家,2代表地主上家

    for i_episode in range(1):
        game.game_reset()
        game.show()
        for i in range(MAX_ROUNDS):
            pid, state, cur_moves, cur_move, winner, info = game.step()
            game.show()
            if winner != -1:
                print('Winner: {}'.format(winner))
                if TRAIND_ID == 0 and winner == 0:
                    # do some positive reward
                    pass
                elif TRAIND_ID != 0 and winner != 0:
    def choose(self, state):
        valid_moves = self.get_moves()
        hand_card = []
        for i, n in enumerate(Card.all_card_name):
            hand_card.extend([n] * self.get_hand_card()[i])
        i = np.random.choice(len(valid_moves))
        move = valid_moves[i]
        # player i [手牌] // [出牌]
        print("Player {}".format(self.player_id), ' ', hand_card, end=' // ')
        print(Card.visual_card(move))
        return move, None


if __name__ == "__main__":
    cnt = 0
    game = Game([MixModel(0), RuleBasedModel(1), RuleBasedModel(2)])
    for i_episode in range(1000):
        game.game_reset()
        game.show()
        game.players[0].set_new_game()
        for i in range(100):
            pid, state, cur_moves, cur_move, winner, info = game.step()
            # game.show()
            if winner != -1:
                print('Winner:{}'.format(winner))
                if winner == 0:
                    cnt += 1
                break
        print("Winning Rate = ", cnt, "/", i_episode + 1,
              " = {:.2f}%\n".format(100 * cnt / (i_episode + 1)))