<commit_before>package jra;

import java.awt.Color;
import java.util.Vector;
import robocode.*;

public class SeekAndDestroy extends AdvancedRobot {

	Vector<ScannedRobotEvent> scannedRobots = new Vector<>();
	ScannedRobotEvent nearestRobot;
	
	public void run() {
		setAdjustRadarForRobotTurn(true);//keep the radar still while we turn
		setColors(Color.BLACK, Color.LIGHT_GRAY, Color.DARK_GRAY);
		setBulletColor(Color.blue);
		//setAdjustGunForRobotTurn(true); // Keep the gun still when we turn
		turnRadarRightRadians(Double.POSITIVE_INFINITY);//keep turning radar right		
	}
	
	public void onScannedRobot(ScannedRobotEvent e) {
		
		//setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
		if (scannedRobots.size() < getOthers() && !haveScannedRobot(e)) {
			// Scan all robots first, keeping track of the closest one
			scannedRobots.add(e);
			if (nearestRobot == null) {
				nearestRobot = e;
			} else if (e.getDistance() < nearestRobot.getDistance()) {
				nearestRobot = e;
			}
			return;
		} else {
			// All robots scanned, move to the closest one
			
			if (nearestRobot.getName().equals(e.getName())) {				
				nearestRobot = e;			
				turnRight(nearestRobot.getBearing());			
				ahead(nearestRobot.getDistance() - 50);
				customFire(nearestRobot);			
			}
			
			if (shouldResetNearestRobot(e)) {
				scannedRobots = new Vector<>();
				nearestRobot = null;
			}
		}		
	}
	
	private boolean shouldResetNearestRobot(ScannedRobotEvent e) {
		boolean nearestChangedDistance = e.getName().equals(nearestRobot.getName()) 
				&& e.getBearing() != nearestRobot.getBearing();
		boolean someBotDied = scannedRobots.size() != getOthers();
		
		log("Distance changed %s - botDied %s - scanned %s - getOthers %s", nearestChangedDistance, someBotDied, scannedRobots.size(), getOthers());
		return nearestChangedDistance || someBotDied;
	}
	
			
	public void onHitRobot(HitRobotEvent e) {
		ahead(0); // Stop movement
	}
	
	public void onHitWall(HitWallEvent e) {
		turnRight(e.getBearing());
	}
	
	private boolean haveScannedRobot(ScannedRobotEvent e) {
		boolean haveScanned = false;
		for (int i = 0; i < scannedRobots.size(); i++) {
			if (e.getName() == scannedRobots.get(i).getName()) {
				haveScanned = true;
				break;
			}
		}
		
		log("Have Scanned %s - %s", e.getName(), haveScanned);
		return haveScanned;
	}
	
	private void customFire(ScannedRobotEvent e) {
		double height = getHeight();
		double distance = e.getDistance();
		double power = 0.5;
		
		double closeRange = height * 4;
		double mediumRange = height * 6;
		double longRange = height * 8;
		
		if (distance <= longRange && distance > mediumRange) {
			power = 1;
		} else if (distance <= mediumRange && distance > closeRange) {
			power = 2;
		} else if (distance <= closeRange) {
			power = 3;
		}
		
		log("Firing on %s for power %s", e.getName(), power);
		fire(power);
	}
	
	private void log(String message, Object... params){
		System.out.println(String.format(message,  params));
	}
}
<commit_msg>- Fixed gun Targeting bug, gun will now point in the general vicinity of the target, rather than at random locations. - Attacking first target that is detected within 150 pixels - Adding Victory dance (shimmy)<commit_after>package jra;

import java.awt.Color;
import java.util.Vector;
import robocode.*;
import robocode.util.Utils;

public class SeekAndDestroy extends AdvancedRobot {

	Vector<ScannedRobotEvent> scannedRobots = new Vector<>();
	ScannedRobotEvent nearestRobot;
	int hitTurnDirection = 1;
	boolean attack = false;
	
	public void run() {
		setAdjustRadarForRobotTurn(true);//keep the radar still while we turn
		setColors(Color.BLACK, Color.LIGHT_GRAY, Color.DARK_GRAY);
		setBulletColor(Color.blue);
		setAdjustGunForRobotTurn(true); // Keep the gun still when we turn
		turnRadarRightRadians(Double.POSITIVE_INFINITY); //keep turning radar right
	}
	
	public void onScannedRobot(ScannedRobotEvent e) {
		log("Scanned %s - scannedSize: %s - haveScanned %s", e.getName(), scannedRobots.size(), haveScannedRobot(e));
		
		if (scannedRobots.size() < getOthers() && !haveScannedRobot(e) && !attack) {
			// Scan all robots first, keeping track of the closest one
			scannedRobots.add(e);
			if (nearestRobot == null) {
				nearestRobot = e;
			} else if (e.getDistance() < nearestRobot.getDistance() && !e.isSentryRobot()) {
				nearestRobot = e;
			}
			
			if (nearestRobot.getDistance() <= 150) { attack = true; }
			return;
		} else {
			// All robots scanned, move to the closest one
			
			if (nearestRobot.getName().equals(e.getName())) {				
				nearestRobot = e;
												
				setTurnGunRightRadians(getGunTurnRadians(nearestRobot));
				customFire(nearestRobot);
				
				setTurnRightRadians(getTurnRadians(nearestRobot));
				setAhead(nearestRobot.getDistance() - 50);
			}			
		}	
		
		if (shouldResetNearestRobot(e)) {
			clearNearestTarget();
		}
	}
	
	private double getTurnRadians(ScannedRobotEvent targetRobot) {
		double absBearing = targetRobot.getBearingRadians() + getHeadingRadians();
		double lateralVelocity = targetRobot.getVelocity() * Math.sin(targetRobot.getHeadingRadians() - absBearing);
		double turnAmountRadians = Utils.normalRelativeAngle(absBearing - getHeadingRadians() + lateralVelocity / getVelocity());
		
		return turnAmountRadians;
	}

	private double getGunTurnRadians(ScannedRobotEvent targetRobot) {
		double absBearing = targetRobot.getBearingRadians() + getHeadingRadians();
		double lateralVelocity = targetRobot.getVelocity() * Math.sin(targetRobot.getHeadingRadians() - absBearing);
		double gunTurnAmountRadians = Utils.normalRelativeAngle(absBearing - getGunHeadingRadians() + lateralVelocity / 22);
		
		return gunTurnAmountRadians;
	}

	private boolean shouldResetNearestRobot(ScannedRobotEvent e) {
		boolean nearestChangedDistance = e.getName().equals(nearestRobot.getName()) 
				&& e.getBearing() != nearestRobot.getBearing();
		boolean someBotDied = scannedRobots.size() != getOthers();
		
		return nearestChangedDistance || someBotDied;
	}
	
			
	public void onHitRobot(HitRobotEvent e) {
		ahead(0); // Stop movement
	}
	
	public void onHitWall(HitWallEvent e) {
		turnRight(-e.getBearing());
	}
	
	public void onWin(WinEvent e) {
		for (int i = 0; i < 50; i++) {
			turnRight(30);
			turnLeft(30);
		}
	}
	
	private boolean haveScannedRobot(ScannedRobotEvent e) {
		boolean haveScanned = false;
		for (int i = 0; i < scannedRobots.size(); i++) {
			if (e.getName() == scannedRobots.get(i).getName()) {
				haveScanned = true;
				break;
			}
		}
		
		return haveScanned;
	}
	
	
	public void onHitByBullet(HitByBulletEvent e) {
		log("\tHit, bearing %s", e.getBearing());
		setTurnRight(90 * hitTurnDirection);
		setAhead(500);
		
		hitTurnDirection *= -1;
	}
	
	private void clearNearestTarget() {
		scannedRobots = new Vector<>();
		nearestRobot = null;
		attack = false;
	}
	
	private void customFire(ScannedRobotEvent e) {
		if (e == null) { return; }
		double height = getHeight();
		double distance = e.getDistance();
		double power = 0.5;
		
		double closeRange = height * 4;
		double mediumRange = height * 6;
		double longRange = height * 8;
		
		if (distance <= longRange && distance > mediumRange) {
			power = 1;
		} else if (distance <= mediumRange && distance > closeRange) {
			power = 2;
		} else if (distance <= closeRange) {
			power = 3;
		}
		
		setFire(power);
	}
	
	private void log(String message, Object... params){
		System.out.println(String.format(message,  params));
	}
}

{'fraction_non_alphanumeric': 0.12053033346725593, 'fraction_numerical': 0.006160439266104192, 'mean_word_length': 3.9489728296885356, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 13, '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': '7291520', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2429, 'n_words': 575}