gym_splendor_code/envs/mechanics/action_space_generator_classic.py
def generate_all_legal_trades_classic(state: State) -> List[ActionTradeGems]:
    """Returns the list of all possible actions of trade in a given current_state"""
    list_of_actions_trade = []
    n_non_empty_stacks = len(state.board.gems_on_board.non_empty_stacks_except_gold())
    n_gems_to_get_netto = min(MAX_GEMS_ON_HAND - state.active_players_hand().gems_possessed.sum(),
                              MAX_GEMS_IN_ONE_MOVE,
                              n_non_empty_stacks)

    max_gems_to_take = min(MAX_GEMS_IN_ONE_MOVE, n_non_empty_stacks)

    for n_gems_to_get in range(n_gems_to_get_netto, max_gems_to_take + 1):
        n_gems_to_return = n_gems_to_get - n_gems_to_get_netto

        # choose gems to get:
        options_of_taking = list(combinations(state.board.gems_on_board.non_empty_stacks_except_gold(), n_gems_to_get))
        for option_of_taking in options_of_taking:
            # now we have chosen which gems to take, so we need to decide which to return
            gem_colors_not_taken = {gem_color for gem_color in GemColor if gem_color not in option_of_taking}
            # find gems collection to take:
            gems_to_take = tuple_of_gems_to_gems_collection(option_of_taking)
            # find possible options of returning gems:
            options_of_returning = list(combinations_with_replacement(gem_colors_not_taken, n_gems_to_return))
            for option_of_returning in options_of_returning:
                # now we create gem collection describing transfer and check if it satisfies conditions of legal trade
                gems_to_return = tuple_of_gems_to_gems_collection(option_of_returning)

                gems_collection_to_trade = gems_to_take - gems_to_return
                # check if there is enough gems on the board to take:
                condition_1 = state.board.gems_on_board >= gems_collection_to_trade
                # check if the player has enough gems to return:
                condition_2 = state.active_players_hand().gems_possessed >= -gems_collection_to_trade
                condition3 = gems_collection_to_trade != GemsCollection()
                if condition_1 and condition_2 and condition3:
                    list_of_actions_trade.append(ActionTradeGems(gems_collection_to_trade))


    return list_of_actions_trade
Returns the list of all possible actions of trade in a given current_state
Returns the list of all possible actions of trade in a given current_state
Returns the list of all possible actions of trade in a given current_state
def generate_all_legal_trades_classic(state: State) -> List[ActionTradeGems]:
    list_of_actions_trade = []
    n_non_empty_stacks = len(state.board.gems_on_board.non_empty_stacks_except_gold())
    n_gems_to_get_netto = min(MAX_GEMS_ON_HAND - state.active_players_hand().gems_possessed.sum(),
                              MAX_GEMS_IN_ONE_MOVE,
                              n_non_empty_stacks)
    max_gems_to_take = min(MAX_GEMS_IN_ONE_MOVE, n_non_empty_stacks)
    for n_gems_to_get in range(n_gems_to_get_netto, max_gems_to_take + 1):
        n_gems_to_return = n_gems_to_get - n_gems_to_get_netto
        options_of_taking = list(combinations(state.board.gems_on_board.non_empty_stacks_except_gold(), n_gems_to_get))
        for option_of_taking in options_of_taking:
            gem_colors_not_taken = {gem_color for gem_color in GemColor if gem_color not in option_of_taking}
            gems_to_take = tuple_of_gems_to_gems_collection(option_of_taking)
            options_of_returning = list(combinations_with_replacement(gem_colors_not_taken, n_gems_to_return))
            for option_of_returning in options_of_returning:
                gems_to_return = tuple_of_gems_to_gems_collection(option_of_returning)
                gems_collection_to_trade = gems_to_take - gems_to_return
                condition_1 = state.board.gems_on_board >= gems_collection_to_trade
                condition_2 = state.active_players_hand().gems_possessed >= -gems_collection_to_trade
                condition3 = gems_collection_to_trade != GemsCollection()
                if condition_1 and condition_2 and condition3:
                    list_of_actions_trade.append(ActionTradeGems(gems_collection_to_trade))
    return list_of_actions_trade
def generate_all_legal_trades_classic ( state : State ) -> List [ ActionTradeGems ] : list_of_actions_trade = [ ] n_non_empty_stacks = len ( state . board . gems_on_board . non_empty_stacks_except_gold ( ) ) n_gems_to_get_netto = min ( MAX_GEMS_ON_HAND - state . active_players_hand ( ) . gems_possessed . sum ( ) , MAX_GEMS_IN_ONE_MOVE , n_non_empty_stacks ) max_gems_to_take = min ( MAX_GEMS_IN_ONE_MOVE , n_non_empty_stacks ) for n_gems_to_get in range ( n_gems_to_get_netto , max_gems_to_take + 1 ) : n_gems_to_return = n_gems_to_get - n_gems_to_get_netto options_of_taking = list ( combinations ( state . board . gems_on_board . non_empty_stacks_except_gold ( ) , n_gems_to_get ) ) for option_of_taking in options_of_taking : gem_colors_not_taken = { gem_color for gem_color in GemColor if gem_color not in option_of_taking } gems_to_take = tuple_of_gems_to_gems_collection ( option_of_taking ) options_of_returning = list ( combinations_with_replacement ( gem_colors_not_taken , n_gems_to_return ) ) for option_of_returning in options_of_returning : gems_to_return = tuple_of_gems_to_gems_collection ( option_of_returning ) gems_collection_to_trade = gems_to_take - gems_to_return condition_1 = state . board . gems_on_board >= gems_collection_to_trade condition_2 = state . active_players_hand ( ) . gems_possessed >= - gems_collection_to_trade condition3 = gems_collection_to_trade != GemsCollection ( ) if condition_1 and condition_2 and condition3 : list_of_actions_trade . append ( ActionTradeGems ( gems_collection_to_trade ) ) return list_of_actions_trade
Returns the list of all possible actions of trade in a given current_state
Returns the list of all possible actions of trade in a given current_state
"""Returns the list of all possible actions of trade in a given current_state""" # choose gems to get: # now we have chosen which gems to take, so we need to decide which to return # find gems collection to take: # find possible options of returning gems: # now we create gem collection describing transfer and check if it satisfies conditions of legal trade # check if there is enough gems on the board to take: # check if the player has enough gems to return:
state
State