예제 #1
0
    def test_flop_check(self):
        logic = Game_Helpers()
        # 1 SB -> 2SB -> 6SB -> 4SB
        blocking = np.zeros(52, dtype=int)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        stack = logic.chips_bitmask(500)
        legal_moves_arr = logic.legal_moves(stack, history, blocking, 'FLOP')
        legal_moves_expected = np.ones(52)
        legal_moves_expected[0] = 0

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #2
0
    def test_blinds_and_call_covered(self):
        logic = Game_Helpers()
        blocking = np.zeros(52)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        history[0, 0, 0:1] = 1
        history[1, 0, 0:2] = 1
        history[2, 0, 0:2] = 1
        stack = logic.chips_bitmask(500)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[3:] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #3
0
    def test_normal_raise_uncovered_call_covered(self):
        # 1 SB -> 2SB -> 16SB -> minraise = 28 SB but we only have a stack of 19 SB
        logic = Game_Helpers()
        blocking = np.zeros(52)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        history[0, 0, 0:1] = 1
        history[1, 0, 0:2] = 1
        history[2, 0:4, 0:4] = 1
        stack = logic.chips_bitmask(190)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[15] = 1
        legal_moves_expected[18] = 1
        legal_moves_expected[51] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #4
0
    def test_just_blinds_covered(self):
        logic = Game_Helpers()
        blocking = np.zeros(50, dtype=int)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        # Small Blind
        history[0, 0, 0:1] = 1
        # Big Blind
        history[1, 0, 0:2] = 1
        stack = logic.chips_bitmask(500)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[1] = 1
        legal_moves_expected[3:50] = 1
        legal_moves_expected[51] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #5
0
    def test_37sb_raise(self):
        logic = Game_Helpers()
        blocking = np.zeros(52)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        history[0, 0, 0:1] = 1
        history[1, 0, 0:2] = 1
        history[2, 0:9, 0:4] = 1
        history[2, 9, 0:3] = 1
        stack = logic.chips_bitmask(500)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[38] = 1
        legal_moves_expected[49] = 1
        legal_moves_expected[51] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #6
0
    def test_8sb_45sb_raises(self):
        logic = Game_Helpers()
        # 1 SB -> 2SB -> 6SB -> 4SB
        blocking = np.zeros(52, dtype=int)
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        history[0, 0, 0:1] = 1
        history[1, 0, 0:2] = 1
        history[2, :12, :] = 1
        stack = logic.chips_bitmask(410)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[40] = 1
        legal_moves_expected[51] = 1
        #legal_moves_expected[49] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #7
0
    def test_blinds_underraise(self):
        # 1 SB -> 2SB -> 3 SB
        logic = Game_Helpers()
        blocking = np.zeros(50, dtype=int)
        blocking[2] = 1
        history = np.zeros(1300)
        history = history.reshape(25, 13, 4)
        history[0, 0, 0:1] = 1
        history[1, 0, 0:2] = 1
        history[2, 0, 0:3] = 1
        stack = logic.chips_bitmask(500)
        legal_moves_arr = logic.legal_moves(stack, history, blocking,
                                            'PREFLOP')
        legal_moves_expected = np.zeros(52)
        legal_moves_expected[2] = 1
        legal_moves_expected[51] = 1

        self.assertEqual(legal_moves_expected.tolist(),
                         legal_moves_arr.tolist())
예제 #8
0
class Player():
    def __init__(self, name, chips,agent):
        self.agent = agent
        self.name = name
        self.cards = None
        self.hand = np.zeros(shape = (1,13,4))
        self.chips_preflop = np.zeros(shape = (1,13,4))
        self.chips_flop = np.zeros(shape = (1,13,4))
        self.chips_turn = np.zeros(shape = (1,13,4))
        self.chips_river = np.zeros(shape = (1,13,4))
        self.chips_dict = {'PREFLOP': self.chips_preflop,'FLOP':self.chips_flop,'TURN':self.chips_turn
            ,'RIVER':self.chips_river}
        self.is_bb = np.zeros(shape = (1,13,4))
        self.chips = chips
        self.id = id
        self.has_acted = False
        self.active =  True
        self.is_allin = False
        self.has_folded = False
        self.is_blocking = False
        self.next_player = None
        self.position = None
        self.current_stack = None
        self.game_helpers = Game_Helpers()
        self.game_state = None
        self.chips_dict['PREFLOP'] = self.game_helpers.chips_bitmask_plane(chips)
        self.state_memory = []


    def reset(self,chips):
        self.cards = None
        self.hand = np.zeros(shape = (1,13,4))
        self.chips_preflop = np.zeros(shape = (1,13,4))
        self.chips_flop = np.zeros(shape = (1,13,4))
        self.chips_turn = np.zeros(shape = (1,13,4))
        self.chips_river = np.zeros(shape = (1,13,4))
        self.chips_dict = {'PREFLOP': self.chips_preflop, 'FLOP': self.chips_flop, 'TURN': self.chips_turn
            , 'RIVER': self.chips_river}
        self.is_bb = np.zeros(shape = (1,13,4))
        self.chips = chips
        self.id = id
        self.has_acted = False
        self.active = True
        self.is_allin = False
        self.has_folded = False
        self.is_blocking = False
        self.next_player = None
        self.position = None
        self.current_stack = None
        self.game_helpers = Game_Helpers()
        self.game_state = None
        self.chips_dict['PREFLOP'] = self.game_helpers.chips_bitmask_plane(chips)
        self.agent.reset()
        self.state_memory = []

    def set_hand(self,cardA,cardB):
        self.hand = self.hand.flatten()
        self.hand[cardA] = 1
        self.hand[cardB] = 1
        self.hand = self.hand.reshape(1, 13, 4)

    def build_player_game_state(self,public_state):
        self.game_state = public_state
        self.game_state = np.concatenate((self.game_state, self.is_bb))
        self.game_state = np.concatenate((self.game_state, self.hand))

    def set_street_stacks(self,history,street,player_number):
        current_stack = self.game_helpers.get_stack(history, self.chips, self.position, player_number, street)
        self.chips_dict[street] = self.game_helpers.chips_bitmask_plane(current_stack)

    def set_reward(self,reward):
        for i in range(0,len(self.state_memory)):
            rl_state = None
            if i <= len(self.state_memory) -2:
                rl_state = {'state0': self.state_memory[i]['state'],'action0':self.state_memory[i]['action'],
                            'state1':self.state_memory[i+1]['state'],'reward':0}
            elif i == len(self.state_memory) -1:
                rl_state = {'state0': self.state_memory[i]['state'], 'action0': self.state_memory[i]['action'],
                            'state1': 'Terminal', 'reward': reward}

            self.agent.save_rl_transition(rl_state)

    def get_move(self,history,blocking,player_number,street,public_state):

        self.set_street_stacks(history, street, player_number)
        current_history = history[street]
        current_stack = self.game_helpers.get_stack(history,self.chips,self.position,player_number,street)
        bitmask_stack = self.game_helpers.chips_bitmask(current_stack)
        legals = self.game_helpers.legal_moves(bitmask_stack, current_history , blocking, street)
        legals = np.argwhere(legals == 1)
        self.build_player_game_state(public_state)

        moves,game_state_dict = self.agent.get_move(history,blocking,player_number,street,self.game_state,legals,None)
        self.state_memory.append(game_state_dict)

        return moves,bitmask_stack