<commit_before>
var JET = JET || {};

JET.Math = {
	v1: new THREE.Vector2(),
	angleBetween: function(obj1, obj2) {
		JET.Math.v1.copy(obj2.position).sub(obj1.position);
		return Math.atan2(JET.Math.v1.y, JET.Math.v1.x);
	},
	angleDiff: function(a, b) {
		var ang = (b - a) % (2*Math.PI);
		if (ang > Math.PI) return ang - 2*Math.PI;
		else if (ang < -Math.PI) return ang + 2*Math.PI;
		else return ang;
	},
	distSq: function(obj1, obj2) {
		return obj1.position.distanceToSquared(obj2.position);
	}
};

JET.updateAI = function(bot, dt) {
	// Select target
	if (!bot.target) {
		bot.cycleTargets();
		if (!bot.target) return;
	}

	var targetDistSq = JET.Math.distSq(bot, bot.target);

	// Control angle
	var desiredAngle = JET.Math.angleBetween(bot, bot.target);
	var angleError = JET.Math.angleDiff(bot.rotation.z, desiredAngle);
	var angleCorr = angleError * 10; // Apply gain
	angleCorr = THREE.Math.clamp(angleCorr, -bot.turnRate, bot.turnRate);
	bot.rotation.z += angleCorr * dt;

	// Figure out speed goal
	var desiredSpeed = bot.maxSpeed;
	if (Math.abs(angleError) > Math.PI / 4)
		desiredSpeed = bot.minSpeed;
	else if (targetDistSq < 50*50)
		desiredSpeed = bot.target.speed;
	else if (targetDistSq < 200*200)
		desiredSpeed = bot.target.speed * 1.1;
	// Control the speed
	var speedError = desiredSpeed - bot.speed;
	var speedCorr = speedError * 10; // Apply gain
	speedCorr = THREE.Math.clamp(speedCorr, -bot.acceleration, bot.acceleration);
	bot.speed += speedCorr * dt;
};<commit_msg>Bots can shoot with cannon.<commit_after>
var JET = JET || {};

JET.Math = {
	v1: new THREE.Vector2(),
	angleBetween: function(obj1, obj2) {
		JET.Math.v1.copy(obj2.position).sub(obj1.position);
		return Math.atan2(JET.Math.v1.y, JET.Math.v1.x);
	},
	angleDiff: function(a, b) {
		var ang = (b - a) % (2*Math.PI);
		if (ang > Math.PI) return ang - 2*Math.PI;
		else if (ang < -Math.PI) return ang + 2*Math.PI;
		else return ang;
	},
	distSq: function(obj1, obj2) {
		return obj1.position.distanceToSquared(obj2.position);
	}
};

JET.updateAI = function(bot, dt) {
	// Select target
	if (!bot.target) {
		bot.cycleTargets();
		if (!bot.target) return;
	}

	var targetDistSq = JET.Math.distSq(bot, bot.target);

	// Control angle
	var desiredAngle = JET.Math.angleBetween(bot, bot.target);
	var angleError = JET.Math.angleDiff(bot.rotation.z, desiredAngle);
	var angleCorr = angleError * 10; // Apply gain
	angleCorr = THREE.Math.clamp(angleCorr, -bot.turnRate, bot.turnRate);
	bot.rotation.z += angleCorr * dt;

	// Figure out speed goal
	var desiredSpeed = bot.maxSpeed;
	if (Math.abs(angleError) > Math.PI / 4)
		desiredSpeed = bot.minSpeed;
	else if (targetDistSq < 50*50)
		desiredSpeed = bot.target.speed;
	else if (targetDistSq < 200*200)
		desiredSpeed = bot.target.speed * 1.1;

	// Control the speed
	var speedError = desiredSpeed - bot.speed;
	var speedCorr = speedError * 10; // Apply gain
	speedCorr = THREE.Math.clamp(speedCorr, -bot.acceleration, bot.acceleration);
	bot.speed += speedCorr * dt;

	// Weapons
	if (targetDistSq < 100*100 && angleError < Math.PI / 16) {
		bot.curWeapon = 0;
		bot.shoot();
	}
};
{'fraction_non_alphanumeric': 0.15421609490221225, 'fraction_numerical': 0.024687399807630652, 'mean_word_length': 3.6776611694152925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '2577045', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1210, 'n_words': 270}