def infer_action(player_before, player_after):
    """Reconstruct that action that leads to the next state."""
    if not player_before.active:
        return "inactive"
    if player_after.speed > player_before.speed:
        return "speed_up"
    if player_after.speed < player_before.speed:
        return "slow_down"
    if player_after.direction == player_before.direction.turn_left():
        return "turn_left"
    if player_after.direction == player_before.direction.turn_right():
        return "turn_right"
    if player_before.x == player_after.x and player_before.y == player_after.y and not player_after.active:
        return "invalid"
    return "change_nothing"