def recreate_state(self): """Loads observation and return a current_state that agrees with the observation. Warning: this method is ambiguous, that is, many states can have the same observation (they may differ in the order of hidden cards).""" state = State(all_cards=StochasticObservation.all_cards, all_nobles=StochasticObservation.all_nobles, prepare_state=False) cards_on_board_names = self.observation_dict['cards_on_board_names'] nobles_on_board_names = self.observation_dict['nobles_on_board_names'] for card_name in cards_on_board_names: card = name_to_card_dict[card_name] state.board.cards_on_board.add(card) state.board.deck.decks_dict[card.row].remove(card) for noble_name in nobles_on_board_names: noble = name_to_noble_dict[noble_name] state.board.nobles_on_board.add(noble) state.board.deck.deck_of_nobles.remove(noble) state.board.gems_on_board = self.observation_dict['gems_on_board'] players_hands = [] for player_observation in self.observation_dict['players_hands']: players_hand = PlayersHand() players_hand.gems_possessed = player_observation['gems_possessed'] for card_name in player_observation['cards_possessed_names']: card = name_to_card_dict[card_name] players_hand.cards_possessed.add(card) state.board.deck.decks_dict[card.row].remove(card) for card_name in player_observation['cards_reserved_names']: card = name_to_card_dict[card_name] players_hand.cards_reserved.add(card) state.board.deck.decks_dict[card.row].remove(card) for noble_name in player_observation['nobles_possessed_names']: noble = name_to_noble_dict[noble_name] players_hand.nobles_possessed.add(noble) state.board.deck.deck_of_nobles.remove(noble) players_hands.append(players_hand) state.active_player_id = self.observation_dict['active_player_id'] state.list_of_players_hands = players_hands return state
# w1 = GemsCollecion({GemColor.GOLD: 1, GemColor.RED: 2, GemColor.GREEN: 5, GemColor.BLUE: 3, GemColor.WHITE: 4, GemColor.BLACK: 5}) # w2 = GemsCollecion({GemColor.GOLD: 2, GemColor.RED: 1, GemColor.GREEN: 6, GemColor.BLUE: 3, GemColor.WHITE: 7, GemColor.BLACK: 5}) # print(w1 <= w2) from gym_splendor_code.envs.graphics.splendor_gui import SplendorGUI, GemColor from gym_splendor_code.envs.mechanics.action_space_generator import generate_all_legal_reservations from gym_splendor_code.envs.mechanics.players_hand import PlayersHand from gym_splendor_code.envs.mechanics.state import State s = State() f = SplendorGUI() f.draw_board(s.board, 200, 10) f.keep_window_open() #testing action generator pla = PlayersHand() pla.gems_possessed.gems_dict[GemColor.BLUE] = 4 pla.gems_possessed.gems_dict[GemColor.GREEN] = 4 pla.gems_possessed.gems_dict[GemColor.RED] = 2 pla.gems_possessed.gems_dict[GemColor.WHITE] = 0 pla.gems_possessed.gems_dict[GemColor.BLACK] = 0 pla.gems_possessed.gems_dict[GemColor.GOLD] = 0 d = State() d.list_of_players_hands = [pla, PlayersHand()] print(d.active_players_hand().gems_possessed) f = generate_all_legal_reservations(d) print(len(f)) for du in f: print(du)