<commit_before>package dronerush;

import java.util.LinkedList;
import java.util.List;

import battlecode.common.CommanderSkillType;
import battlecode.common.GameActionException;
import battlecode.common.GameConstants;
import battlecode.common.MapLocation;
import battlecode.common.RobotController;

public class CommanderHandler extends BaseRobotHandler {

	private static int HEALTH_TO_RETREAT = 50;

	protected CommanderHandler(RobotController rc) {
		super(rc);
	}

	@Override
	public List<Action> chooseActions() throws GameActionException {
		LinkedList<Action> result = new LinkedList<Action>();
		// Leadership and Regenerate are passive skills, which is awesome
		// Flash and Heavy Hands are active though
		if (rc.getHealth() <= HEALTH_TO_RETREAT) {
			if (rc.hasLearnedSkill(CommanderSkillType.FLASH)) {
				result.add(retreatWithFlash);
			}
			result.add(retreat);
			return result;
		}
		if (rc.hasLearnedSkill(CommanderSkillType.HEAVY_HANDS)) {
			result.add(useHeavyHands);
		}
		result.add(attack);
		result.add(advance);
		result.add(scout);
		return result;
	}

	private final Action attack = new Attack();
	private final Action retreat = new Retreat();
	private final Action retreatWithFlash = new RetreatWithFlash();
	private final Action scout = new ScoutOutward();
	private final Action advance = new MoveTowardEnemyHq(/* avoidEnemies= */true);
	private final Action useHeavyHands = new HeavyHands();

	private class HeavyHands implements Action {
		@Override
		public boolean run() throws GameActionException {
			// TODO Auto-generated method stub
			// Heavy Hands is automatically cast on anyone we attack, so we should make sure to attack several different targets
			return false;
		}
	}

	public class RetreatWithFlash implements Action {

		@Override
		public boolean run() throws GameActionException {
			if (!rc.isCoreReady() || rc.getFlashCooldown() > 0) {
				return false;
			}

			MapLocation ourHq = rc.senseHQLocation();
			MapLocation enemyHq = rc.senseEnemyHQLocation();
			MapLocation[] enemyTowers = rc.senseEnemyTowerLocations();
			MapLocation[] potentialLocs = MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(),
					GameConstants.FLASH_RANGE_SQUARED);
			// should we use the pathfinding dist or the actual dist here?
			// it almost makes sense to use the actual dist, since we can flash over obstacles and we'd need to use this in a pinch
			int minDist = rc.getLocation().distanceSquaredTo(ourHq);
			MapLocation best = null;
			for (MapLocation loc : potentialLocs) {
				int locDist = loc.distanceSquaredTo(ourHq);
				if (locDist < minDist) {
					if (rc.senseRobotAtLocation(loc) == null) {
						if (!inHqOrTowerRange(loc, enemyTowers, enemyHq)) {
							minDist = locDist;
							best = loc;
						}
					}
				}
			}
			rc.castFlash(best);
			return true;
		}
	}

}<commit_msg>null check<commit_after>package dronerush;

import java.util.LinkedList;
import java.util.List;

import battlecode.common.CommanderSkillType;
import battlecode.common.GameActionException;
import battlecode.common.GameConstants;
import battlecode.common.MapLocation;
import battlecode.common.RobotController;

public class CommanderHandler extends BaseRobotHandler {

	private static int HEALTH_TO_RETREAT = 50;

	protected CommanderHandler(RobotController rc) {
		super(rc);
	}

	@Override
	public List<Action> chooseActions() throws GameActionException {
		LinkedList<Action> result = new LinkedList<Action>();
		// Leadership and Regenerate are passive skills, which is awesome
		// Flash and Heavy Hands are active though
		if (rc.getHealth() <= HEALTH_TO_RETREAT) {
			if (rc.hasLearnedSkill(CommanderSkillType.FLASH)) {
				result.add(retreatWithFlash);
			}
			result.add(retreat);
			return result;
		}
		if (rc.hasLearnedSkill(CommanderSkillType.HEAVY_HANDS)) {
			result.add(useHeavyHands);
		}
		result.add(attack);
		result.add(advance);
		result.add(scout);
		return result;
	}

	private final Action attack = new Attack();
	private final Action retreat = new Retreat();
	private final Action retreatWithFlash = new RetreatWithFlash();
	private final Action scout = new ScoutOutward();
	private final Action advance = new MoveTowardEnemyHq(/* avoidEnemies= */true);
	private final Action useHeavyHands = new HeavyHands();

	private class HeavyHands implements Action {
		@Override
		public boolean run() throws GameActionException {
			// TODO Auto-generated method stub
			// Heavy Hands is automatically cast on anyone we attack, so we should make sure to attack several different targets
			return false;
		}
	}

	public class RetreatWithFlash implements Action {

		@Override
		public boolean run() throws GameActionException {
			if (!rc.isCoreReady() || rc.getFlashCooldown() > 0) {
				return false;
			}

			MapLocation ourHq = rc.senseHQLocation();
			MapLocation enemyHq = rc.senseEnemyHQLocation();
			MapLocation[] enemyTowers = rc.senseEnemyTowerLocations();
			MapLocation[] potentialLocs = MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(),
					GameConstants.FLASH_RANGE_SQUARED);
			// should we use the pathfinding dist or the actual dist here?
			// it almost makes sense to use the actual dist, since we can flash over obstacles and we'd need to use this in a pinch
			int minDist = rc.getLocation().distanceSquaredTo(ourHq);
			MapLocation best = null;
			for (MapLocation loc : potentialLocs) {
				int locDist = loc.distanceSquaredTo(ourHq);
				if (locDist < minDist) {
					if (rc.senseRobotAtLocation(loc) == null) {
						if (!inHqOrTowerRange(loc, enemyTowers, enemyHq)) {
							minDist = locDist;
							best = loc;
						}
					}
				}
			}
			if (best != null) {
				rc.castFlash(best);
				return true;
			}
			return false;
		}
	}

}
{'fraction_non_alphanumeric': 0.0918438480306727, 'fraction_numerical': 0.0010456605088881143, 'mean_word_length': 4.174932371505861, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '6533287', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1735, 'n_words': 490}