<commit_before>#include "PreventDoubleTouch.hpp"

#include <boost/foreach.hpp>

using namespace std;

Gameplay::PreventDoubleTouch::PreventDoubleTouch(GameplayModule *gameplay, SingleRobotBehavior *kicker):
	backoff(gameplay)
{
	_gameplay = gameplay;
	_kicker = kicker;
	_keepRunning = false;
	_kicked = false;
	_wasReady = false;
}

void Gameplay::PreventDoubleTouch::run()
{
	const GameState &gameState = state()->gameState;
	const Ball &ball = state()->ball;
	
	if (!_kicker || !_kicker->robot)
	{
		// Don't get stuck in a play if we don't have a kicking robot
		_keepRunning = false;
		return;
	}
	
	if (_keepRunning && (gameState.state != GameState::Ready && gameState.state != GameState::Playing))
	{
		// We were waiting for another robot to touch the ball but the referee has cancelled the kickoff.
		// Allow applicable() to return false.
		_keepRunning = false;
	}
	
	if (gameState.state == GameState::Ready)
	{
		// At this point the _kicker should either kick or collide with the ball.
		// After that one other robot must touch it.
		_keepRunning = true;
		_wasReady = true;
	}
	
	if (_kicked)
	{
		backoff.run();
		if (_ruleTime.msecsTo(QTime::currentTime()) > 5000)
		{
			_keepRunning = false;
		}
	} else {
		if (!_kicker->run() || (gameState.state == GameState::Playing && _wasReady))
		{
			_kicked = true;
			_ruleTime = QTime::currentTime();
		}
	}
	
	Robot *best = 0;
	float bestDist = 0;
	BOOST_FOREACH(Robot *r, state()->self)
	{
		if (r->visible)
		{
			float dist = r->pos.distTo(ball.pos);
			if (bestDist == 0 || bestDist > dist)
			{
				bestDist = dist;
				best = r;
			}<commit_msg>Fixed a problem with PreventDoubleTouch that was causing it to indicate kicked when the kicking robot disappeared, which caused kickoff violations<commit_after>#include "PreventDoubleTouch.hpp"

#include <stdio.h>
#include <boost/foreach.hpp>

using namespace std;

Gameplay::PreventDoubleTouch::PreventDoubleTouch(GameplayModule *gameplay, SingleRobotBehavior *kicker):
	backoff(gameplay)
{
	_gameplay = gameplay;
	_kicker = kicker;
	_keepRunning = false;
	_kicked = false;
	_wasReady = false;
}

void Gameplay::PreventDoubleTouch::run()
{
	const GameState &gameState = state()->gameState;
	const Ball &ball = state()->ball;
	
	if (!_kicker || !_kicker->robot)
	{
		// Don't get stuck in a play if we don't have a kicking robot
		_keepRunning = false;
		return;
	}
	
	if (_keepRunning && (gameState.state != GameState::Ready && gameState.state != GameState::Playing))
	{
		// We were waiting for another robot to touch the ball but the referee has cancelled the kickoff.
		// Allow applicable() to return false.
		_keepRunning = false;
	}
	
	if (gameState.state == GameState::Ready)
	{
		// At this point the _kicker should either kick or collide with the ball.
		// After that one other robot must touch it.
		_keepRunning = true;
		_wasReady = true;
	}
	
	if (_kicked)
	{
		backoff.run();
		if (_ruleTime.msecsTo(QTime::currentTime()) > 5000)
		{
			_keepRunning = false;
		}
	} else {
		if ((_kicker->robot->visible && !_kicker->run()) || (gameState.state == GameState::Playing && _wasReady))
		{
			_kicked = true;
			_ruleTime = QTime::currentTime();
		}
	}
	
	Robot *best = 0;
	float bestDist = 0;
	BOOST_FOREACH(Robot *r, state()->self)
	{
		if (r->visible)
		{
			float dist = r->pos.distTo(ball.pos);
			if (bestDist == 0 || bestDist > dist)
			{
				bestDist = dist;
				best = r;
			}
{'fraction_non_alphanumeric': 0.13046027557900908, 'fraction_numerical': 0.004104368220463207, 'mean_word_length': 3.752089136490251, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704673', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1161, 'n_words': 323}