Skip to content

Commit

Permalink
Handle touchdown by throwing
Browse files Browse the repository at this point in the history
We only checked positions when running to the end zone
but sometimes the receiver receives the catch in the end zone
  • Loading branch information
IBBoard committed Jul 27, 2021
1 parent 44deb8d commit b6ace5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bbreplay/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,6 @@ def _process_turn(self, cmds, log_entries, board, start_next_turn=True):
player = self.get_team(cmd.team).get_player(cmd.player_idx)
# We stop when the movement stops, so the returned command is the EndMovementCommand
yield from self._process_movement(player, cmd, cmds, None, log_entries, board)
if board.get_ball_carrier() == player and \
(player.position.y == NEAR_ENDZONE_IDX or player.position.y == FAR_ENDZONE_IDX):
board.touchdown(player)
yield Touchdown(player, board)
end_reason = END_REASON_TOUCHDOWN
elif cmd_type is Command or cmd_type is PreKickoffCompleteCommand:
continue
elif cmd_type is DeclineRerollCommand or (cmd_type is DiceChoiceCommand
Expand All @@ -372,7 +367,12 @@ def _process_turn(self, cmds, log_entries, board, start_next_turn=True):
end_reason = END_REASON_ABANDON
else:
raise NotImplementedError(f"No handling for {cmd}")
break

if board.is_touchdown_state():
player = board.get_ball_carrier()
board.touchdown(player)
yield Touchdown(player, board)
end_reason = END_REASON_TOUCHDOWN

if end_reason == END_REASON_ABANDON:
yield from board.abandon_match(cmd.team)
Expand Down
11 changes: 10 additions & 1 deletion bbreplay/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under GPLv3 or later - see COPYING

from collections import namedtuple, defaultdict
from . import other_team, Skills, TeamType, Weather, ActionResult, PITCH_LENGTH, PITCH_WIDTH, OFF_PITCH_POSITION
from . import BEFORE_HALFWAY_IDX, FAR_ENDZONE_IDX, NEAR_ENDZONE_IDX, other_team, Skills, TeamType, Weather, ActionResult, PITCH_LENGTH, PITCH_WIDTH, OFF_PITCH_POSITION


WeatherTuple = namedtuple('Weather', ['result'])
Expand Down Expand Up @@ -41,6 +41,7 @@ def __init__(self, home_team, away_team, receiving_team):
self.__used_reroll = False
self.__leader_reroll = [False, False]
self.__kicked_off = False
self.__touchdown_row = [-1, -1]

@property
def turn(self):
Expand Down Expand Up @@ -112,9 +113,17 @@ def setup_complete(self):
self.__leader_reroll[TeamType.AWAY.value] = True
else:
self.__leader_reroll[TeamType.AWAY.value] = False
if any(pos.y > BEFORE_HALFWAY_IDX for _, pos in self.__setups[TeamType.HOME.value]):
self.__touchdown_row = [NEAR_ENDZONE_IDX, FAR_ENDZONE_IDX]
else:
self.__touchdown_row = [FAR_ENDZONE_IDX, NEAR_ENDZONE_IDX]
self.__last_setup_turn = self.turn
self.__kicked_off = False

def is_touchdown_state(self):
ball_carrier = self.get_ball_carrier()
return ball_carrier and ball_carrier.position.y == self.__touchdown_row[ball_carrier.team.team_type.value]

def touchdown(self, player):
team = player.team.team_type
team_value = team.value
Expand Down

0 comments on commit b6ace5a

Please sign in to comment.