// // // -- this method *should* be a lot faster, but I can't get it to hit spinbot, so until then.... /*double getGunOffset(Tracer enemyStart, DCRobotState rs){ double distance = lastScan.getDistance(); double deltaHeading = enemyStart.heading - lastRobotScan.getHeadingRadians(); double startAngle = rs.absBearing + deltaHeading; Point2D.Double myRelativeLocation = JKDCUtils.project(enemyStart.location, startAngle + Math.PI, distance); double bulletSpeed = 20 - 3*BULLET_POWER; double bulletDistance = 0; Tracer t = enemyStart; do{ t = t.next; if(t == null || t.round != enemyStart.round) return Double.POSITIVE_INFINITY; bulletDistance += bulletSpeed; }while(JKDCUtils.sqr(bulletDistance) < myRelativeLocation.distanceSq(t.location)); double fireAngle = JKDCUtils.absoluteBearing(myRelativeLocation,t.location); double offset = Utils.normalRelativeAngle(fireAngle - startAngle); if(!JKDCUtils.fieldContains(JKDCUtils.project(myLocation,rs.absBearing + offset,myRelativeLocation.distance(t.location)))) return Double.POSITIVE_INFINITY; return offset; }*/ //// The standard PlayItForward method that works perfectly, but uses a lot more Trig... double getGunOffset(Tracer enemyStart, DCRobotState rs){ double bulletSpeed = 20 -3*BULLET_POWER; double bulletDistance = 0; Tracer t = enemyStart; Point2D.Double predLocation = enemyLocation; double predHeading = lastScan.getHeadingRadians(); do{ t = t.next; bulletDistance += bulletSpeed; if(!JKDCUtils.fieldContains(predLocation) || t == null || t.round != enemyStart.round) return Double.POSITIVE_INFINITY; predLocation = JKDCUtils.project(predLocation, predHeading += t.deltaHeading, t.velocity); }while(JKDCUtils.sqr(bulletDistance) < myLocation.distanceSq(predLocation)); double fireAngle = JKDCUtils.absoluteBearing(myLocation,predLocation); return Utils.normalRelativeAngle(fireAngle - rs.absBearing); }
-- Skilgannon
I can't see anything wrong with that code, have you tried it against Walls? I'm not very good at looking at other peoples code, sorry. -- ABC