def path_to_move_actions(game: botbowl.Game, player: botbowl.Player, path: Path, do_assertions=True) -> List[Action]: """ This function converts a path into a list of actions corresponding to that path. If you provide a handoff, foul or blitz path, then you have to manally set action type. :param game: :param player: player to move :param path: a path as returned by the pathfinding algorithms :param do_assertions: if False, it turns off the validation, can be helpful when the GameState will change before this path is executed. :returns: List of actions corresponding to 'path'. """ if path.block_dice is not None: action_type = ActionType.BLOCK elif path.handoff_roll is not None: action_type = ActionType.HANDOFF elif path.foul_roll is not None: action_type = ActionType.FOUL else: action_type = ActionType.MOVE active_team = game.state.available_actions[0].team player_at_target = game.get_player_at(path.get_last_step()) if do_assertions: if action_type is ActionType.MOVE: assert player_at_target is None or player_at_target is game.get_active_player( ) elif action_type is ActionType.BLOCK: assert game.get_opp_team(active_team) is player_at_target.team assert player_at_target.state.up elif action_type is ActionType.FOUL: assert game.get_opp_team(active_team) is player_at_target.team assert not player_at_target.state.up elif action_type is ActionType.HANDOFF: assert active_team is player_at_target.team assert player_at_target.state.up else: raise Exception(f"Unregonized action type {action_type}") final_action = Action(action_type, position=path.get_last_step()) if game._is_action_allowed(final_action): return [final_action] else: actions = [] if not player.state.up and path.steps[0] == player.position: actions.append(Action(ActionType.STAND_UP, player=player)) actions.extend( Action(ActionType.MOVE, position=sq) for sq in path.steps[1:-1]) else: actions.extend( Action(ActionType.MOVE, position=sq) for sq in path.steps[:-1]) actions.append(final_action) return actions
def expand_action(game: botbowl.Game, action: botbowl.Action, parent: ActionNode) -> Node: """ :param game: game object used for calculations. Will be reverted to original state. :param action: action to be evaluated. :param parent: parent node :returns - list of tuples containing (Steps, probability) for each possible outcome. - probabilities sums to 1.0 Not called recursively """ # noinspection PyProtectedMember assert game._is_action_allowed(action) assert game.trajectory.enabled game.config.fast_mode = False with only_fixed_rolls(game): game.step(action) return expand_none_action(game, parent)