rendered paste bodyclass GuessFactorC { TeamRobot bot; UT unit; ArrayList waves = new ArrayList(); Rectangle2D fieldRectangle; //private int uniqueSegments = 31; //private int fieldSegments = 5; //private int distanceSegments = 6; //private int velocitySegments = 5; //private int xForceSegments = 22; //private int yForceSegments = 22; private int[][][][][] stats = new int[5][6][5][22][31]; //private int headingSegments = 20; //private int[][][][][] stats = new int[fieldSegments][distanceSegments][velocitySegments][headingSegments][uniqueSegments]; private int[] currentStats; private int direction = 1; //private double maxDistance; public GuessFactorC(TeamRobot b, UT u) { fieldRectangle = new Rectangle2D.Double(0, 0, b.getBattleFieldWidth(), b.getBattleFieldHeight()); bot = b; unit = u; //maxDistance = new Point2D.Double(0,0).distance(bot.getBattleFieldWidth(), bot.getBattleFieldHeight()); } public void run() { UI info = unit.lastInfo(); Point2D.Double enemyPos = new Point2D.Double(info.x, info.y); //let's process the waves now: for (int i=0; i<waves.size(); i++) { WaveBullet currentWave = (WaveBullet)waves.get(i); if (currentWave.check(enemyPos, bot.getTime())) { waves.remove(currentWave); i--; } } return; } public void update() { UI info = unit.lastInfo(); double absBearing = info.bearing + bot.getHeadingRadians(); //find our enemy's location: Point2D.Double enemyPos = new Point2D.Double(info.x, info.y); double power = 3; double orientation = (info.velocity*Math.sin(info.heading - absBearing) >= 0) ? 1 : -1; //int distanceIndex = (int)info.distance/((int)maxDistance/distanceSegments); int distanceIndex = (int)info.distance/((int)1132/6); int velocityIndex = (int)info.velocity/2; int yForceIndex = (int)((Math.cos(info.heading)*10)+10); int fieldIndex = getOutIndex(); //bot.out.println(headingIndex); //currentStats = stats[fieldIndex][distanceIndex][velocityIndex][yForceIndex]; currentStats = stats[getOutIndex()][(int)info.distance/((int)1132/6)][(int)info.velocity/2][(int)((Math.cos(info.heading)*10)+10)]; //currentStats = stats[fieldIndex][distanceIndex][velocityIndex][headingIndex]; WaveBullet newWave = new WaveBullet(new Point2D.Double(bot.getX(), bot.getY()), info.heading, info.velocity, orientation, bot.getTime(), currentStats); waves.add(newWave); } public double getBearing() { UI info = unit.lastInfo(); int bestindex = 15; //initialize it to be in the middle, guessfactor 0. //for (int i=0; i<uniqueSegments; i++) for (int i=0; i<31; i++) if (currentStats[bestindex] < currentStats[i]) bestindex = i; //this should do the opposite of the math in the WaveBullet: WaveBullet w = getNewestWave(); double guessfactor = (double)(bestindex-(stats.length-1)/2)/((stats.length-1)/2); double angleOffset = direction*guessfactor*info.velocity; double angle = robocode.util.Utils.normalRelativeAngle(info.bearing+angleOffset); return angle; } public WaveBullet getNewestWave() { return (WaveBullet)waves.get(waves.size()-1); } private int getOutIndex() { UI info = unit.lastInfo(); int i = 0; do { } while (++i < 5-1 && fieldRectangle.contains((info.x + (Math.sin(info.heading)* (45.0 * i))), (info.y + (Math.cos(info.heading)) * (45.0 * i)))); //} while (++i < fieldSegments-1 && fieldRectangle.contains((info.x + (Math.sin(info.heading)* (45.0 * i))), (info.y + (Math.cos(info.heading)) * (45.0 * i)))); return (i); } }class WaveBullet{ public Point2D.Double startPosition; private long fireTime; private double orientation, heading, velocity; private int[] returnSegment; public WaveBullet(Point2D.Double position, double h, double v, double o, long time, int[] segment) { startPosition = position; heading = h; velocity = 20-v*3; orientation = o; fireTime = time; returnSegment = segment; } public boolean check(Point2D.Double enemyPosition, long currentTime) { //if the distance from the wave origin to our enemy has passed the distance the bullet would have traveled... if (startPosition.distance(enemyPosition) <= (currentTime-fireTime)*velocity) { double newBearing = (Double)Math.atan2(startPosition.getX()-enemyPosition.getX(),startPosition.getY()-enemyPosition.getX()); double angleOffset = Utils.normalRelativeAngle(newBearing-heading); double guessFactor = Math.max(-1, Math.min(1, angleOffset/Math.asin(8/velocity)))*orientation; int index = (int)Math.round((returnSegment.length-1)/2*(guessFactor+1)); returnSegment[index]++; return true; } return false; }}