private Double shouldWeBreak(double desiredSpeed, World world) { TrackModel track = world.getTrackModel(); double distance = track.getLaneDistanceBetweenPieces( track.getCurrent(), track.getNextCurve(), world.getMyLane()); double inPieceDistance = world.myPhysics.getPreviousPosition().inPieceDistance; double distanceToCurve = distance - inPieceDistance; double endSpeed; double newThrottle = 0; endSpeed = world.getMySpeed(); int ticksTillCurve = ticksToRunDistance(distanceToCurve, world, newThrottle); if (ticksTillCurve == -1) return null; for (int i = 0; i < ticksTillCurve; i++) { endSpeed = world.myPhysics.getAccelerationEstimator().getSpeedOnNextTick(endSpeed, newThrottle); } // Now we have reached the point that if (endSpeed > desiredSpeed) { return 0d; } else { return null; } }
@Override public Double getThrottle(World world) { TrackModel track = world.getTrackModel(); if (world.getMySpeed() == 0) { return 1.0d; } if (track.getCurrent().equals(nextCurve)) { // System.out.println(String.format( // "Wanted speed to curve %s but was %s", speedForNextCurve, // world.getMySpeed())); nextCurve = null; } double curveSpeed = determineMaxCurveSpeed(track.getNextCurve()) * ERROR_CORRECTION; if (curveSpeed > 10) curveSpeed = 10 * ERROR_CORRECTION; this.nextCurve = track.getNextCurve(); this.speedForNextCurve = curveSpeed; Double shouldWeBreak = shouldWeBreak(curveSpeed, world); if (shouldWeBreak != null) { return shouldWeBreak; } return null; }