def convert_state(self, state, to='id'): if isinstance(state, tuple): state = list(state) if isinstance(state, str): state = int(state) if isinstance(state, int): cur = 'id' elif isinstance(state, dict): cur = 'dic' elif isinstance(state, list): cur = 'list' else: game.warning("/!\ Invalid state format", state) return if cur == to: return state if cur == 'id': if to == 'list': return self.state_id_to_list(state) elif to == 'dic': return self.state_id_to_dic(state) elif cur == 'dic': if to == 'list': return self.state_dic_to_list(state) elif to == 'id': return self.state_dic_to_id(state) elif cur == 'list': if to == 'id': return self.state_list_to_id(state) elif to == 'dic': return self.state_list_to_dic(state)
def possible_transition(self, state, action): # Convert action object to string if 'type' in action: action = action['type'] if action == 'do_nothing': return True elif action in ['buy_card', 'buy_prestige', 'reserve', 'take_3', 'take_2']: return state['can_' + action] else: game.warning("/!\ Unknown action type :", action) return False
def heuristic(self, action, action_type): if action_type == 'take_3': return self._heuristic_take_3(action) elif action_type == 'take_2': return self._heuristic_take_2(action) elif action_type == 'reserve': return self._heuristic_reserve(action) elif action_type == 'buy_card': return self._heuristic_buy_card(action) elif action_type == 'buy_prestige': return self._heuristic_buy_prestige(action) elif action_type == 'do_nothing': return self._heuristic_do_nothing(action) else: game.warning("/!\ Unknown action type in heuristic filtering", action, action_type) return 0
def convert_action(self, action, to='id'): if isinstance(action, str): cur = 'name' elif isinstance(action, int): cur = 'id' else: game.warning('/!\ Unknown action type') return if cur == to: return action if cur == 'id' and to == 'name': return self.action_space[action] elif cur == 'name' and to == 'id': return self.action_space_inverted_index[action] else: game.warning('/!\ Unknown action type') return