<commit_before>#include "Kick.hpp"

#include "../Window.hpp"

#include <boost/foreach.hpp>
#include <boost/format.hpp>

using namespace std;
using namespace Utils;
using namespace Geometry2d;

//#define DEBUG

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

Gameplay::Behaviors::Kick::Kick(GameplayModule *gameplay) :
	Behavior(gameplay, 1),
	_aimType(PIVOT),
	_kickType(KICK),
	_targetType(GOAL),
	_ballHandlingScale(1.0),
	_ballHandlingRange(0.5)
{
	automatic = true;
	_win = 0;
	_targetRobot = 0;
	_intercept = new Gameplay::Behaviors::Intercept(gameplay);
}

Gameplay::Behaviors::Kick::~Kick()
{
	if (_win)
	{
		delete _win;
	}
	if (_intercept)
	{
		delete _intercept;
	}
}

bool Gameplay::Behaviors::Kick::kickType(KickType mode) {
	if (mode == CHIP && robot()->hasChipper()) {
		_kickType = mode;
		return true;
	} else {
		return false;
	}
}

void Gameplay::Behaviors::Kick::setTarget() {
	_targetType = GOAL;
}

void Gameplay::Behaviors::Kick::setTarget(const Geometry2d::Segment& seg) {
	_targetType = SEGMENT;
	_target = seg;
}

void Gameplay::Behaviors::Kick::setTarget(Robot * r) {
	_targetType = ROBOT;
	_targetRobot = r;
}

bool Gameplay::Behaviors::Kick::assign(set<Robot *> &available)
{
	_robots.clear(); // clear existing robots
	if (!takeBest(available))
	{
	    return false;
	}

	if (!_win)
	{
		_win = new WindowEvaluator(_gameplay->state());
		_win->debug = false;
	}

	_state = Intercept;
	_intercept->assignOne(robot());
	_lastMargin = 0;

	return _robots.size() >= _minRobots;
}

bool Gameplay::Behaviors::Kick::run()
{
	if (!allVisible() || !ball().valid)
	{
		// No ball
		return false;
	}

	// Get ball information
	const Geometry2d::Point ballPos = ball().pos;
	const Geometry2d::Point ballVel = ball().vel;

	const Geometry2d::Point pos = robot()->pos();

	// find a target segment using window evaluators
	switch (_targetType) {
	case GOAL:
		_target = evaluateShot();
		break;
	case ROBOT:
		_target = evaluateShot();
		break;
	case SEGMENT:
		_target = evaluateSegment();
	}
	drawLine(_target, 255, 0, 0); // show the target segment

	Geometry2d::Point targetCenter = _target.center();

	//Determine how hard to kick given
	int kickStrength = calcKickStrength(targetCenter);

	// Always face the ball
	robot()->face(ballPos);

	// Vector that we would shoot along if we shot now
	// assume that the ball goes where we were facing
	//Geometry2d::Point shootDir = -(pos - ballPos);
	Point shootDir = Point::direction(robot()->angle() * DegreesToRadians);

	//shot segment is from us in direction of shootDir
	//it is sufficiently large to handle the entire field shot
	Segment shotLine (pos, pos + shootDir * 7.0);

	//the point of intersection of the shotLine and target
	Geometry2d::Point shootPoint;

	//see if the shot line intersects where we indent to shoot
	bool intersectedTarget = shotLine.intersects(_target, &shootPoint);

	// robot intersection tests
	bool intersectsRobot = checkRobotIntersections(shotLine);<commit_msg>Fixed bug with passing in Kick<commit_after>#include "Kick.hpp"

#include "../Window.hpp"

#include <boost/foreach.hpp>
#include <boost/format.hpp>

using namespace std;
using namespace Utils;
using namespace Geometry2d;

//#define DEBUG

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

Gameplay::Behaviors::Kick::Kick(GameplayModule *gameplay) :
	Behavior(gameplay, 1),
	_aimType(PIVOT),
	_kickType(KICK),
	_targetType(GOAL),
	_ballHandlingScale(1.0),
	_ballHandlingRange(0.5)
{
	automatic = true;
	_win = 0;
	_targetRobot = 0;
	_intercept = new Gameplay::Behaviors::Intercept(gameplay);
}

Gameplay::Behaviors::Kick::~Kick()
{
	if (_win)
	{
		delete _win;
	}
	if (_intercept)
	{
		delete _intercept;
	}
}

bool Gameplay::Behaviors::Kick::kickType(KickType mode) {
	if (mode == CHIP && robot()->hasChipper()) {
		_kickType = mode;
		return true;
	} else {
		return false;
	}
}

void Gameplay::Behaviors::Kick::setTarget() {
	_targetType = GOAL;
}

void Gameplay::Behaviors::Kick::setTarget(const Geometry2d::Segment& seg) {
	_targetType = SEGMENT;
	_target = seg;
}

void Gameplay::Behaviors::Kick::setTarget(Robot * r) {
	_targetType = ROBOT;
	_targetRobot = r;
}

bool Gameplay::Behaviors::Kick::assign(set<Robot *> &available)
{
	_robots.clear(); // clear existing robots
	if (!takeBest(available))
	{
	    return false;
	}

	if (!_win)
	{
		_win = new WindowEvaluator(_gameplay->state());
		_win->debug = false;
	}

	_state = Intercept;
	_intercept->assignOne(robot());
	_lastMargin = 0;

	return _robots.size() >= _minRobots;
}

bool Gameplay::Behaviors::Kick::run()
{
	if (!allVisible() || !ball().valid)
	{
		// No ball
		return false;
	}

	// Get ball information
	const Geometry2d::Point ballPos = ball().pos;
	const Geometry2d::Point ballVel = ball().vel;

	const Geometry2d::Point pos = robot()->pos();

	// find a target segment using window evaluators
	switch (_targetType) {
	case GOAL:
		_target = evaluateShot();
		break;
	case ROBOT:
		_target = evaluatePass();
		break;
	case SEGMENT:
		_target = evaluateSegment();
	}
	drawLine(_target, 255, 0, 0); // show the target segment

	Geometry2d::Point targetCenter = _target.center();

	//Determine how hard to kick given
	int kickStrength = calcKickStrength(targetCenter);

	// Always face the ball
	robot()->face(ballPos);

	// Vector that we would shoot along if we shot now
	// assume that the ball goes where we were facing
	//Geometry2d::Point shootDir = -(pos - ballPos);
	Point shootDir = Point::direction(robot()->angle() * DegreesToRadians);

	//shot segment is from us in direction of shootDir
	//it is sufficiently large to handle the entire field shot
	Segment shotLine (pos, pos + shootDir * 7.0);

	//the point of intersection of the shotLine and target
	Geometry2d::Point shootPoint;

	//see if the shot line intersects where we indent to shoot
	bool intersectedTarget = shotLine.intersects(_target, &shootPoint);

	// robot intersection tests
	bool intersectsRobot = checkRobotIntersections(shotLine);
{'fraction_non_alphanumeric': 0.13677761218744824, 'fraction_numerical': 0.007617155158138765, 'mean_word_length': 4.5616942909760585, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '1989676', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2100, 'n_words': 546}