def create_all_next_surviving_actions(self, game: Game) -> List[Action]: """Calculates not only one but all actions that will let the player survive for the next rounds. Args: game: The current state of the game. Returns: A list of actions which will let the player survive for the next rounds. """ root = SearchTreeRoot(game.copy()) player_ids_to_watch = game.get_other_player_ids( self.player, self.__distance_to_check, True) combinations = Action.get_combinations(len(player_ids_to_watch)) search_tree_actions = [] for action in Action.get_actions(): if root.calculate_action(self.player, player_ids_to_watch, combinations, self.__depth, self._turn_ctr, True, [action], self._max_speed, True) is not None: search_tree_actions.append(action) return search_tree_actions
def test_create_combinations_as_product(self): player_count = 4 result = Action.get_combinations(player_count) self.assertEqual(pow(len(Action), player_count), len(result)) self.assertEqual(player_count, len(result[0]))
def create_next_action(self, game: Game, return_value: Value): """See base class.""" self._turn_ctr += 1 root = SearchTreeRoot(game.copy()) player_ids_to_watch = game.get_other_player_ids( self.player, self.__distance_to_check, True) combinations = Action.get_combinations(len(player_ids_to_watch)) action = root.calculate_action(self.player, player_ids_to_watch, combinations, self.__depth, self._turn_ctr, True, [], self._max_speed, self.__randomize) return_value.value = (action if action is not None else Action.get_random_action()).get_index()