def potential_move_actions(player: m.Player, game: g.Game, paths: List[pf.Path]) -> List[ActionSequence]: ''' Return set of all scored possible "MOVE" actions for given player :param player: :param game: :param paths: :return: ''' move_actions: List[ActionSequence] = [] for path in paths: path_steps = path.steps action_steps: List[m.Action] = [] action_steps.append(m.Action(t.ActionType.START_MOVE, player=player)) if not player.state.up: action_steps.append(m.Action(t.ActionType.STAND_UP, player=player)) for step in path_steps: # Note we need to add 1 to x and y because the outermost layer of squares is not actually reachable action_steps.append( m.Action(t.ActionType.MOVE, pos=game.state.pitch.get_square(step.x, step.y), player=player)) action_steps.append( m.Action(t.ActionType.END_PLAYER_TURN, player=player)) move_actions.append( ActionSequence(action_steps, score=len(path.steps) * (1.0 - path.cost) + random.randint(1, 100) / 1000, description='Move ' + player.name + ' to ' + str(path_steps[-1].x) + ',' + str(path_steps[-1].y))) # potential action -> sequence of steps such as "START_MOVE, MOVE (to square) etc return move_actions
def touchback(self, game: g.Game): """ Select player to give the ball to. """ for player in game.get_players_on_pitch(self.my_team, up=True): if m.Skill.BLOCK in player.skills: return m.Action(t.ActionType.SELECT_PLAYER, player=player) return m.Action(t.ActionType.SELECT_NONE)
def interception(self, game: g.Game): """ Select interceptor. """ for action in game.state.available_actions: if action.action_type == t.ActionType.INTERCEPTION: for player, agi_rolls in zip(action.players, action.agi_rolls): return m.Action(t.ActionType.INTERCEPTION, player=player) return m.Action(t.ActionType.SELECT_NONE)
def place_ball(self, game: g.Game): """ Place the ball when kicking. """ left_center = m.Square(7, 8) right_center = m.Square(20, 8) if game.is_team_side(left_center, self.opp_team): return m.Action(t.ActionType.PLACE_BALL, pos=left_center) return m.Action(t.ActionType.PLACE_BALL, pos=right_center)
def high_kick(self, game: g.Game): """ Select player to move under the ball. """ ball_pos = game.get_ball_position() if game.is_team_side(game.get_ball_position(), self.my_team) and \ game.get_player_at(game.get_ball_position()) is None: for player in game.get_players_on_pitch(self.my_team, up=True): if m.Skill.BLOCK in player.skills: return m.Action(t.ActionType.PLACE_PLAYER, player=player, pos=ball_pos) return m.Action(t.ActionType.SELECT_NONE)
def setup(self, game: g.Game): """ Move players from the reserves to the pitch """ i = len(game.get_players_on_pitch(self.my_team)) reserves = game.get_reserves(self.my_team) if i == 11 or len(reserves) == 0: return m.Action(t.ActionType.END_SETUP) player = reserves[0] y = 3 x = 13 if game.is_team_side(m.Square(13, 3), self.my_team) else 14 return m.Action(t.ActionType.PLACE_PLAYER, player=player, pos=m.Square(x, y + i))
def potential_blitz_actions(player: m.Player, game: g.Game, paths: List[pf.Path]) -> List[ActionSequence]: ''' Return set of all scored possible "MOVE" actions for given player :param player: :param game: :param paths: :return: ''' move_actions: List[ActionSequence] = [] for path in paths: path_steps = path.steps end_square: m.Square = game.state.pitch.get_square( path.steps[-1].x, path.steps[-1].y) blockable_squares = game.state.pitch.adjacent_player_squares_at( player, end_square, include_own=False, include_opp=True, manhattan=False, only_blockable=True, only_foulable=False) for blockable_square in blockable_squares: action_steps: List[m.Action] = [] action_steps.append( m.Action(t.ActionType.START_BLITZ, player=player)) if not player.state.up: action_steps.append( m.Action(t.ActionType.STAND_UP, player=player)) for step in path_steps: # Note we need to add 1 to x and y because the outermost layer of squares is not actually reachable action_steps.append( m.Action(t.ActionType.MOVE, pos=game.state.pitch.get_square(step.x, step.y), player=player)) action_steps.append( m.Action(t.ActionType.BLOCK, pos=blockable_square, player=player)) action_steps.append( m.Action(t.ActionType.END_PLAYER_TURN, player=player)) move_actions.append( ActionSequence(action_steps, score=len(path.steps) * (1.0 - path.cost) + random.randint(1, 100) / 100, description='Blitz ' + player.name + ' to ' + str(blockable_square.x) + ',' + str(blockable_square.y))) # potential action -> sequence of steps such as "START_MOVE, MOVE (to square) etc return move_actions
def potential_pass_actions(player: m.Player, game: g.Game, paths: List[pf.Path]) -> List[ActionSequence]: ''' Return set of all scored possible "MOVE" actions for given player :param player: :param game: :param paths: :return: ''' move_actions: List[ActionSequence] = [] for path in paths: path_steps = path.steps end_square: m.Square = game.state.pitch.get_square( path.steps[-1].x, path.steps[-1].y) # Need possible receving players to_squares, distances = game.state.pitch.passes_at( player, game.state.weather, end_square) for to_square in to_squares: action_steps: List[m.Action] = [] action_steps.append( m.Action(t.ActionType.START_PASS, player=player)) if not player.state.up: action_steps.append( m.Action(t.ActionType.STAND_UP, player=player)) for step in path_steps: # Note we need to add 1 to x and y because the outermost layer of squares is not actually reachable action_steps.append( m.Action(t.ActionType.MOVE, pos=game.state.pitch.get_square(step.x, step.y), player=player)) action_steps.append( m.Action(t.ActionType.PASS, pos=to_square, player=player)) action_steps.append( m.Action(t.ActionType.END_PLAYER_TURN, player=player)) to_player: m.Player = game.state.pitch.get_player_at(to_square) if to_player is not None and to_player.state.up and to_player.team == player.team: # Favourable score to pass to a standing player on the same team cur_score = 60 + len(path.steps) * ( 1.0 - path.cost) + random.randint(1, 100) / 1000 else: cur_score = -1 move_actions.append( ActionSequence(action_steps, score=cur_score, description='Pass ' + player.name + ' to ' + str(to_square.x) + ',' + str(to_square.y))) # potential action -> sequence of steps such as "START_MOVE, MOVE (to square) etc return move_actions
def push(self, game: g.Game): """ Select square to push to. """ # Loop through available squares for position in game.state.available_actions[0].positions: return m.Action(t.ActionType.PUSH, pos=position)
def follow_up(self, game: g.Game): """ Follow up or not. ActionType.FOLLOW_UP must be used together with a position. """ player = game.state.active_player for position in game.state.available_actions[0].positions: # Always follow up if player.position != position: return m.Action(t.ActionType.FOLLOW_UP, pos=position)
def setup(self, game: game.Game) -> Model.Action: if (self.current_move and self.current_move.is_empty() == False): return self.current_move.popleft() else: formation = game.config.offensive_formations[0] \ if game.state.receiving_this_drive == self.my_team else \ game.config.defensive_formations[0] actions = formation.actions(game, self.my_team) actions.append(Model.Action(Table.ActionType.END_SETUP)) self.current_move = ActionSequence(actions)
def potential_end_turn_action(game: g.Game) -> List[ActionSequence]: ''' Returns a scored end-turn action :param game: :return: ''' actions: List[ActionSequence] = [] action_steps: List[m.Action] = [] action_steps.append(m.Action(t.ActionType.END_TURN)) actions.append( ActionSequence(action_steps, score=-1, description='End Turn')) return actions
def block(self, game: g.Game): """ Select block die or reroll. """ # Loop through available dice results actions = set() for action_choice in game.state.available_actions: actions.add(action_choice.action_type) if t.ActionType.SELECT_DEFENDER_DOWN in actions: return m.Action(t.ActionType.SELECT_DEFENDER_DOWN) if t.ActionType.SELECT_DEFENDER_STUMBLES in actions: return m.Action(t.ActionType.SELECT_DEFENDER_STUMBLES) if t.ActionType.SELECT_PUSH in actions: return m.Action(t.ActionType.SELECT_PUSH) if t.ActionType.SELECT_BOTH_DOWN in actions: return m.Action(t.ActionType.SELECT_BOTH_DOWN) if t.ActionType.USE_REROLL in actions: return m.Action(t.ActionType.USE_REROLL) if t.ActionType.SELECT_ATTACKER_DOWN in actions: return m.Action(t.ActionType.SELECT_ATTACKER_DOWN)
def potential_block_actions(player: m.Player, game: g.Game) -> List[ActionSequence]: ''' Return set of all scored possible "MOVE" actions for given player :param player: :param game: :param paths: :return: ''' move_actions: List[ActionSequence] = [] if not player.state.up: # There is currently a bug in the controlling logic. Prone players shouldn't be able to block return move_actions blockable_squares: List[ m.Player] = game.state.pitch.adjacent_player_squares( player, include_own=False, include_opp=True, manhattan=False, only_blockable=True, only_foulable=False) for blockable_square in blockable_squares: action_steps: List[m.Action] = [] action_steps.append(m.Action(t.ActionType.START_BLOCK, player=player)) action_steps.append( m.Action(t.ActionType.BLOCK, pos=blockable_square, player=player)) action_steps.append( m.Action(t.ActionType.END_PLAYER_TURN, player=player)) move_actions.append( ActionSequence(action_steps, score=random.randint(1, 100) / 20, description='Block ' + player.name + ' to ' + str(blockable_square.x) + ',' + str(blockable_square.y))) # potential action -> sequence of steps such as "START_MOVE, MOVE (to square) etc return move_actions
def interception(self, game): return Model.Action(Table.ActionType.END_TURN)
def catch(self, game): return Model.Action(Table.ActionType.END_TURN)
def pass_action(self, game): return Model.Action(Table.ActionType.END_TURN)
def apothecary(self, game): return Model.Action(Table.ActionType.END_TURN)
def follow_up(self, game): return Model.Action(Table.ActionType.END_TURN)
def block(self, game): return Model.Action(Table.ActionType.END_TURN)
def quick_snap(self, game): return Model.Action(Table.ActionType.END_TURN)
def touchback(self, game): return Model.Action(Table.ActionType.END_TURN)
def high_kick(self, game): return Model.Action(Table.ActionType.END_TURN)
def place_ball(self, game: game.Game): center_opposite = Model.Square(helper.reverse_x_for_left(game, self.my_team, 7), 8) return Model.Action(Table.ActionType.PLACE_BALL, pos=center_opposite)
def coin_toss_kick_receive(self, game: game.Game) -> Model.Action: if (game.state.weather != Table.WeatherType.NICE): return Model.Action(Table.ActionType.KICK) else: return Model.Action(Table.ActionType.RECEIVE)
def coin_toss_flip(self, game: g.Game): """ Select heads/tails and/or kick/receive """ return m.Action(t.ActionType.TAILS)
def dodge(self, game): return Model.Action(Table.ActionType.END_TURN)
def coin_toss_kick_receive(self, game: g.Game): """ Select heads/tails and/or kick/receive """ return m.Action(t.ActionType.RECEIVE)
def pickup(self, game): return Model.Action(Table.ActionType.END_TURN)
def coin_toss_flip(self, game: game.Game) -> Model.Action: return Model.Action(Table.ActionType.HEADS)