(self)
return _observation_space, obs_idx_dict, obs_parts_idxs_dict
The maximum all chip-values can reach is n_seats, because we normalize by dividing by the average starting stack
The maximum all chip-values can reach is n_seats, because we normalize by dividing by the average starting stack
The maximum all chip - values can reach is n_seats because we normalize by dividing by the average starting stack
def _construct_obs_space(self):
        """
        The maximum all chip-values can reach is n_seats, because we normalize by dividing by the average starting stack
        """
        obs_idx_dict = {}
        obs_parts_idxs_dict = {
            "board": [],
            "players": [[] for _ in range(self.N_SEATS)],
            "table_state": [],
        }
        next_idx = [0]  # list is a mutatable object. int not.

        def get_discrete(size, name, _curr_idx):
            obs_idx_dict[name] = _curr_idx[0]
            _curr_idx[0] += 1
            return spaces.Discrete(size)

        def get_new_box(name, _curr_idx, high, low=0):
            obs_idx_dict[name] = _curr_idx[0]
            _curr_idx[0] += 1
            return spaces.Box(low=low, high=high, shape=(1,), dtype=np.float32)

        if (self.N_SEATS == 2) and self._USE_SIMPLE_HU_OBS:
            # __________________________  Public Information About Game State  _________________________
            _k = next_idx[0]
            _table_space = [  # (blinds are in obs to give the agent a perspective on starting stack after normalization
                get_new_box("ante", next_idx, self.N_SEATS),  # .................................... self.ANTE
                get_new_box("small_blind", next_idx, self.N_SEATS),  # ............................. self.SMALL_BLIND
                get_new_box("big_blind", next_idx, self.N_SEATS),  # ............................... self.BIG_BLIND
                get_new_box("min_raise", next_idx, self.N_SEATS),  # ............................... min total raise
                get_new_box("pot_amt", next_idx, self.N_SEATS),  # ................................. main_pot amount
                get_new_box("total_to_call", next_idx, self.N_SEATS),  # ........................... total_to_call
                get_new_box("last_action_how_much", next_idx, self.N_SEATS),  # .................... self.last_action[1]
            ]
            for i in range(3):  # .................................................................. self.last_action[0]
                _table_space.append(get_discrete(1, "last_action_what_" + str(i), next_idx))

            for i in range(
                self.N_SEATS):  # ....................................................... self.last_action[2]
                _table_space.append(get_discrete(1, "last_action_who_" + str(i), next_idx))

            for i in range(
                self.N_SEATS):  # ....................................................... curr_player.seat_id
                _table_space.append(get_discrete(1, "p" + str(i) + "_acts_next", next_idx))

            for i in range(max(self.ALL_ROUNDS_LIST) + 1):  # ...................................... round onehot
                _table_space.append(get_discrete(1, "round_" + Poker.INT2STRING_ROUND[i], next_idx)),

            # add to parts_dict for possible slicing for agents.
            obs_parts_idxs_dict["table_state"] += list(range(_k, next_idx[0]))

            # __________________________  Public Information About Each Player  ________________________
            _player_space = []
            for i in range(self.N_SEATS):
                _k = next_idx[0]
                _player_space += [
                    get_new_box("stack_p" + str(i), next_idx, self.N_SEATS),  # ..................... stack
                    get_new_box("curr_bet_p" + str(i), next_idx, self.N_SEATS),  # .................. current_bet
                    get_discrete(1, "is_allin_p" + str(i), next_idx),  # ............................ is_allin
                ]

                # add to parts_dict for possible slicing for agents
                obs_parts_idxs_dict["players"][i] += list(range(_k, next_idx[0]))

            # _______________________________  Public cards (i.e. board)  ______________________________
            _board_space = []
            _k = next_idx[0]
            for i in range(self.N_TOTAL_BOARD_CARDS):

                x = []
                for j in range(self.N_RANKS):  # .................................................... rank
                    x.append(get_discrete(1, str(i) + "th_board_card_rank_" + str(j), next_idx))

                for j in range(self.N_SUITS):  # .................................................... suit
                    x.append(get_discrete(1, str(i) + "th_board_card_suit_" + str(j), next_idx))

                _board_space += x

            # add to parts_dict for possible slicing for agents
            obs_parts_idxs_dict["board"] += list(range(_k, next_idx[0]))

            # __________________________  Return Complete _Observation Space  __________________________
            # Tuple (lots of spaces.Discrete and spaces.Box)
            _observation_space = spaces.Tuple(_table_space + _player_space + _board_space)
            _observation_space.shape = [len(_observation_space.spaces)]

        else:
            # __________________________  Public Information About Game State  _________________________
            _k = next_idx[0]
            _table_space = [  # (blinds are in obs to give the agent a perspective on starting stack after normalization
                get_new_box("ante", next_idx, self.N_SEATS),  # .................................... self.ANTE
                get_new_box("small_blind", next_idx, self.N_SEATS),  # ............................. self.SMALL_BLIND
                get_new_box("big_blind", next_idx, self.N_SEATS),  # ............................... self.BIG_BLIND
                get_new_box("min_raise", next_idx, self.N_SEATS),  # ............................... min total raise
                get_new_box("pot_amt", next_idx, self.N_SEATS),  # ................................. main_pot amount
                get_new_box("total_to_call", next_idx, self.N_SEATS),  # ........................... total_to_call
                get_new_box("last_action_how_much", next_idx, self.N_SEATS),  # .................... self.last_action[1]
            ]
            for i in range(3):  # .................................................................. self.last_action[0]
                _table_space.append(get_discrete(1, "last_action_what_" + str(i), next_idx))

            for i in range(self.N_SEATS):  # ....................................................... self.last_action[2]
                _table_space.append(get_discrete(1, "last_action_who_" + str(i), next_idx))

            for i in range(self.N_SEATS):  # ....................................................... curr_player.seat_id
                _table_space.append(get_discrete(1, "p" + str(i) + "_acts_next", next_idx))

            for i in range(max(self.ALL_ROUNDS_LIST) + 1):  # ...................................... round onehot
                _table_space.append(get_discrete(1, "round_" + Poker.INT2STRING_ROUND[i], next_idx)),

            for i in range(self.N_SEATS):  # ....................................................... side pots
                _table_space.append(get_new_box("side_pot_" + str(i), next_idx, 1))

            # add to parts_dict for possible slicing for agents.
            obs_parts_idxs_dict["table_state"] += list(range(_k, next_idx[0]))

            # __________________________  Public Information About Each Player  ________________________
            _player_space = []
            for i in range(self.N_SEATS):
                _k = next_idx[0]
                _player_space += [
                    get_new_box("stack_p" + str(i), next_idx, self.N_SEATS),  # ..................... stack
                    get_new_box("curr_bet_p" + str(i), next_idx, self.N_SEATS),  # .................. current_bet
                    get_discrete(1, "has_folded_this_episode_p" + str(i), next_idx),  # ............. folded_this_epis
                    get_discrete(1, "is_allin_p" + str(i), next_idx),  # ............................ is_allin
                ]
                for j in range(self.N_SEATS):
                    _player_space.append(
                        get_discrete(1, "side_pot_rank_p" + str(i) + "_is_" + str(j), next_idx))  # . side_pot_rank

                # add to parts_dict for possible slicing for agents
                obs_parts_idxs_dict["players"][i] += list(range(_k, next_idx[0]))

            # _______________________________  Public cards (i.e. board)  ______________________________
            _board_space = []
            _k = next_idx[0]
            for i in range(self.N_TOTAL_BOARD_CARDS):

                x = []
                for j in range(self.N_RANKS):  # .................................................... rank
                    x.append(get_discrete(1, str(i) + "th_board_card_rank_" + str(j), next_idx))

                for j in range(self.N_SUITS):  # .................................................... suit
                    x.append(get_discrete(1, str(i) + "th_board_card_suit_" + str(j), next_idx))

                _board_space += x

            # add to parts_dict for possible slicing for agents
            obs_parts_idxs_dict["board"] += list(range(_k, next_idx[0]))

            # __________________________  Return Complete _Observation Space  __________________________
            # Tuple (lots of spaces.Discrete and spaces.Box)
            _observation_space = spaces.Tuple(_table_space + _player_space + _board_space)
            _observation_space.shape = [len(_observation_space.spaces)]
        return _observation_space, obs_idx_dict, obs_parts_idxs_dict
def _construct_obs_space ( self ) : obs_idx_dict = { } obs_parts_idxs_dict = { "board" : [ ] , "players" : [ [ ] for _ in range ( self . N_SEATS ) ] , "table_state" : [ ] , } next_idx = [ 0 ] # list is a mutatable object. int not. def get_discrete ( size , name , _curr_idx ) : obs_idx_dict [ name ] = _curr_idx [ 0 ] _curr_idx [ 0 ] += 1 return spaces . Discrete ( size ) def get_new_box ( name , _curr_idx , high , low = 0 ) : obs_idx_dict [ name ] = _curr_idx [ 0 ] _curr_idx [ 0 ] += 1 return spaces . Box ( low = low , high = high , shape = ( 1 , ) , dtype = np . float32 ) if ( self . N_SEATS == 2 ) and self . _USE_SIMPLE_HU_OBS : # __________________________  Public Information About Game State  _________________________ _k = next_idx [ 0 ] _table_space = [ # (blinds are in obs to give the agent a perspective on starting stack after normalization get_new_box ( "ante" , next_idx , self . N_SEATS ) , # .................................... self.ANTE get_new_box ( "small_blind" , next_idx , self . N_SEATS ) , # ............................. self.SMALL_BLIND get_new_box ( "big_blind" , next_idx , self . N_SEATS ) , # ............................... self.BIG_BLIND get_new_box ( "min_raise" , next_idx , self . N_SEATS ) , # ............................... min total raise get_new_box ( "pot_amt" , next_idx , self . N_SEATS ) , # ................................. main_pot amount get_new_box ( "total_to_call" , next_idx , self . N_SEATS ) , # ........................... total_to_call get_new_box ( "last_action_how_much" , next_idx , self . N_SEATS ) , # .................... self.last_action[1] ] for i in range ( 3 ) : # .................................................................. self.last_action[0] _table_space . append ( get_discrete ( 1 , "last_action_what_" + str ( i ) , next_idx ) ) for i in range ( self . N_SEATS ) : # ....................................................... self.last_action[2] _table_space . append ( get_discrete ( 1 , "last_action_who_" + str ( i ) , next_idx ) ) for i in range ( self . N_SEATS ) : # ....................................................... curr_player.seat_id _table_space . append ( get_discrete ( 1 , "p" + str ( i ) + "_acts_next" , next_idx ) ) for i in range ( max ( self . ALL_ROUNDS_LIST ) + 1 ) : # ...................................... round onehot _table_space . append ( get_discrete ( 1 , "round_" + Poker . INT2STRING_ROUND [ i ] , next_idx ) ) , # add to parts_dict for possible slicing for agents. obs_parts_idxs_dict [ "table_state" ] += list ( range ( _k , next_idx [ 0 ] ) ) # __________________________  Public Information About Each Player  ________________________ _player_space = [ ] for i in range ( self . N_SEATS ) : _k = next_idx [ 0 ] _player_space += [ get_new_box ( "stack_p" + str ( i ) , next_idx , self . N_SEATS ) , # ..................... stack get_new_box ( "curr_bet_p" + str ( i ) , next_idx , self . N_SEATS ) , # .................. current_bet get_discrete ( 1 , "is_allin_p" + str ( i ) , next_idx ) , # ............................ is_allin ] # add to parts_dict for possible slicing for agents obs_parts_idxs_dict [ "players" ] [ i ] += list ( range ( _k , next_idx [ 0 ] ) ) # _______________________________  Public cards (i.e. board)  ______________________________ _board_space = [ ] _k = next_idx [ 0 ] for i in range ( self . N_TOTAL_BOARD_CARDS ) : x = [ ] for j in range ( self . N_RANKS ) : # .................................................... rank x . append ( get_discrete ( 1 , str ( i ) + "th_board_card_rank_" + str ( j ) , next_idx ) ) for j in range ( self . N_SUITS ) : # .................................................... suit x . append ( get_discrete ( 1 , str ( i ) + "th_board_card_suit_" + str ( j ) , next_idx ) ) _board_space += x # add to parts_dict for possible slicing for agents obs_parts_idxs_dict [ "board" ] += list ( range ( _k , next_idx [ 0 ] ) ) # __________________________  Return Complete _Observation Space  __________________________ # Tuple (lots of spaces.Discrete and spaces.Box) _observation_space = spaces . Tuple ( _table_space + _player_space + _board_space ) _observation_space . shape = [ len ( _observation_space . spaces ) ] else : # __________________________  Public Information About Game State  _________________________ _k = next_idx [ 0 ] _table_space = [ # (blinds are in obs to give the agent a perspective on starting stack after normalization get_new_box ( "ante" , next_idx , self . N_SEATS ) , # .................................... self.ANTE get_new_box ( "small_blind" , next_idx , self . N_SEATS ) , # ............................. self.SMALL_BLIND get_new_box ( "big_blind" , next_idx , self . N_SEATS ) , # ............................... self.BIG_BLIND get_new_box ( "min_raise" , next_idx , self . N_SEATS ) , # ............................... min total raise get_new_box ( "pot_amt" , next_idx , self . N_SEATS ) , # ................................. main_pot amount get_new_box ( "total_to_call" , next_idx , self . N_SEATS ) , # ........................... total_to_call get_new_box ( "last_action_how_much" , next_idx , self . N_SEATS ) , # .................... self.last_action[1] ] for i in range ( 3 ) : # .................................................................. self.last_action[0] _table_space . append ( get_discrete ( 1 , "last_action_what_" + str ( i ) , next_idx ) ) for i in range ( self . N_SEATS ) : # ....................................................... self.last_action[2] _table_space . append ( get_discrete ( 1 , "last_action_who_" + str ( i ) , next_idx ) ) for i in range ( self . N_SEATS ) : # ....................................................... curr_player.seat_id _table_space . append ( get_discrete ( 1 , "p" + str ( i ) + "_acts_next" , next_idx ) ) for i in range ( max ( self . ALL_ROUNDS_LIST ) + 1 ) : # ...................................... round onehot _table_space . append ( get_discrete ( 1 , "round_" + Poker . INT2STRING_ROUND [ i ] , next_idx ) ) , for i in range ( self . N_SEATS ) : # ....................................................... side pots _table_space . append ( get_new_box ( "side_pot_" + str ( i ) , next_idx , 1 ) ) # add to parts_dict for possible slicing for agents. obs_parts_idxs_dict [ "table_state" ] += list ( range ( _k , next_idx [ 0 ] ) ) # __________________________  Public Information About Each Player  ________________________ _player_space = [ ] for i in range ( self . N_SEATS ) : _k = next_idx [ 0 ] _player_space += [ get_new_box ( "stack_p" + str ( i ) , next_idx , self . N_SEATS ) , # ..................... stack get_new_box ( "curr_bet_p" + str ( i ) , next_idx , self . N_SEATS ) , # .................. current_bet get_discrete ( 1 , "has_folded_this_episode_p" + str ( i ) , next_idx ) , # ............. folded_this_epis get_discrete ( 1 , "is_allin_p" + str ( i ) , next_idx ) , # ............................ is_allin ] for j in range ( self . N_SEATS ) : _player_space . append ( get_discrete ( 1 , "side_pot_rank_p" + str ( i ) + "_is_" + str ( j ) , next_idx ) ) # . side_pot_rank # add to parts_dict for possible slicing for agents obs_parts_idxs_dict [ "players" ] [ i ] += list ( range ( _k , next_idx [ 0 ] ) ) # _______________________________  Public cards (i.e. board)  ______________________________ _board_space = [ ] _k = next_idx [ 0 ] for i in range ( self . N_TOTAL_BOARD_CARDS ) : x = [ ] for j in range ( self . N_RANKS ) : # .................................................... rank x . append ( get_discrete ( 1 , str ( i ) + "th_board_card_rank_" + str ( j ) , next_idx ) ) for j in range ( self . N_SUITS ) : # .................................................... suit x . append ( get_discrete ( 1 , str ( i ) + "th_board_card_suit_" + str ( j ) , next_idx ) ) _board_space += x # add to parts_dict for possible slicing for agents obs_parts_idxs_dict [ "board" ] += list ( range ( _k , next_idx [ 0 ] ) ) # __________________________  Return Complete _Observation Space  __________________________ # Tuple (lots of spaces.Discrete and spaces.Box) _observation_space = spaces . Tuple ( _table_space + _player_space + _board_space ) _observation_space . shape = [ len ( _observation_space . spaces ) ] return _observation_space , obs_idx_dict , obs_parts_idxs_dict