# store the desired action in `transition_action_on_cellexit' (only if the desired transition is allowed! otherwise DO_NOTHING!)
agent.old_direction=agent.direction
# Then in any case (if agent.moving) and the `transition_action_on_cellexit' is valid, increment the position_fraction by the speed of the agent (regardless of action taken, as long as no STOP_MOVING, but that makes agent.moving=False)
agent.old_position=agent.position
# If the new position fraction is >= 1, reset to 0, and perform the stored transition_action_on_cellexit
agent.position=new_position
agent.direction=new_direction
ifagent.speed_data['position_fraction']<0.01:
else:
# Is the desired transition valid?
# Logic: if the chosen action is invalid,
# and it was LEFT or RIGHT, and the agent was moving, then keep moving FORWARD.