gym_splendor_code/envs/mechanics/action_space_generator_fast.py
def generate_all_legal_buys_fast(state: State) -> List[ActionBuyCard]:
    """Returns the list of all possible actions of buys in a given current_state"""
    list_of_actions_buy = []
    discount = state.active_players_hand().discount()
    all_cards_can_afford = [card for card in state.board.cards_on_board if
                            state.active_players_hand().can_afford_card(card, discount)] + \
                           [reserved_card for reserved_card in state.active_players_hand().cards_reserved if
                            state.active_players_hand().can_afford_card(reserved_card, discount)]

    for card in all_cards_can_afford:
        card_price_after_discount = card.price % discount
        minimum_gold_needed = state.active_players_hand().min_gold_needed_to_buy_card(card)
        for n_gold_gems_to_use in range(minimum_gold_needed,
                                        state.active_players_hand().gems_possessed.gems_dict[GemColor.GOLD] + 1):
            # we choose combination of other gems:
            options_of_use_gold_as = combinations_with_replacement(
                card_price_after_discount.non_empty_stacks_except_gold(),
                n_gold_gems_to_use)
            for option_of_use_gold_as in options_of_use_gold_as:
                use_gold_as = tuple_of_gems_to_gems_collection(option_of_use_gold_as)
                # check if the option satisfies conditions:
                condition_1 = use_gold_as <= card_price_after_discount
                condition_2 = state.active_players_hand().gems_possessed >= card_price_after_discount - use_gold_as
                if condition_1 and condition_2:
                    list_of_actions_buy.append(ActionBuyCard(card, n_gold_gems_to_use, use_gold_as))

    return list_of_actions_buy
Returns the list of all possible actions of buys in a given current_state
Returns the list of all possible actions of buys in a given current_state
Returns the list of all possible actions of buys in a given current_state
def generate_all_legal_buys_fast(state: State) -> List[ActionBuyCard]:
    list_of_actions_buy = []
    discount = state.active_players_hand().discount()
    all_cards_can_afford = [card for card in state.board.cards_on_board if
                            state.active_players_hand().can_afford_card(card, discount)] + \
                           [reserved_card for reserved_card in state.active_players_hand().cards_reserved if
                            state.active_players_hand().can_afford_card(reserved_card, discount)]
    for card in all_cards_can_afford:
        card_price_after_discount = card.price % discount
        minimum_gold_needed = state.active_players_hand().min_gold_needed_to_buy_card(card)
        for n_gold_gems_to_use in range(minimum_gold_needed,
                                        state.active_players_hand().gems_possessed.gems_dict[GemColor.GOLD] + 1):
            options_of_use_gold_as = combinations_with_replacement(
                card_price_after_discount.non_empty_stacks_except_gold(),
                n_gold_gems_to_use)
            for option_of_use_gold_as in options_of_use_gold_as:
                use_gold_as = tuple_of_gems_to_gems_collection(option_of_use_gold_as)
                condition_1 = use_gold_as <= card_price_after_discount
                condition_2 = state.active_players_hand().gems_possessed >= card_price_after_discount - use_gold_as
                if condition_1 and condition_2:
                    list_of_actions_buy.append(ActionBuyCard(card, n_gold_gems_to_use, use_gold_as))
    return list_of_actions_buy
def generate_all_legal_buys_fast ( state : State ) -> List [ ActionBuyCard ] : list_of_actions_buy = [ ] discount = state . active_players_hand ( ) . discount ( ) all_cards_can_afford = [ card for card in state . board . cards_on_board if state . active_players_hand ( ) . can_afford_card ( card , discount ) ] + [ reserved_card for reserved_card in state . active_players_hand ( ) . cards_reserved if state . active_players_hand ( ) . can_afford_card ( reserved_card , discount ) ] for card in all_cards_can_afford : card_price_after_discount = card . price % discount minimum_gold_needed = state . active_players_hand ( ) . min_gold_needed_to_buy_card ( card ) for n_gold_gems_to_use in range ( minimum_gold_needed , state . active_players_hand ( ) . gems_possessed . gems_dict [ GemColor . GOLD ] + 1 ) : options_of_use_gold_as = combinations_with_replacement ( card_price_after_discount . non_empty_stacks_except_gold ( ) , n_gold_gems_to_use ) for option_of_use_gold_as in options_of_use_gold_as : use_gold_as = tuple_of_gems_to_gems_collection ( option_of_use_gold_as ) condition_1 = use_gold_as <= card_price_after_discount condition_2 = state . active_players_hand ( ) . gems_possessed >= card_price_after_discount - use_gold_as if condition_1 and condition_2 : list_of_actions_buy . append ( ActionBuyCard ( card , n_gold_gems_to_use , use_gold_as ) ) return list_of_actions_buy
Returns the list of all possible actions of buys in a given current_state
Returns the list of all possible actions of buys in a given current_state
"""Returns the list of all possible actions of buys in a given current_state""" # we choose combination of other gems: # check if the option satisfies conditions:
state
State