What type of wave surfing is this?

Jump to navigation Jump to search
Revision as of 12 June 2017 at 11:34.
The subject of this thread was changed from "What type of wave surfing is this" to "What type of wave surfing is this?".

What type of wave surfing is this?

I made this for a micro bot. It is wave surfing but it is not Goto or True wave surfing. It is something more like gravity surfing.Is there a name for this? Sorry for pasting the all code.

    public static double[][] m = new double[3][5];
    double enemyEnergy = 100;
    ArrayList<Wave> waves = new ArrayList<>();

    public void run() {
        setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
    }

    public void onScannedRobot(robocode.ScannedRobotEvent e) {
        double bulletPower;
        double absoluteBearing = e.getBearingRadians() + getHeadingRadians();
        double lateralVelocity = getVelocity() * Math.sin(getHeadingRadians() - absoluteBearing + Math.PI);
        if ((bulletPower = (enemyEnergy - (enemyEnergy = e.getEnergy()))) <= 3 && bulletPower >= 0.09) {
            waves.add(new Wave(bulletPower, getHeadingRadians() + e.getBearingRadians() + Math.PI, e.getDistance(), (int)Math.round(lateralVelocity / 8)));
        }
        double max = 0;
        double dir = 0;
        for (int i = 0; i < waves.size(); i++) {
            Wave w = waves.get(i);
            w.move += getVelocity();
            w.time--;
            if (w.time <= 0) {
                waves.remove(w);
                i--;
            } else {
                dir -= w.dir / w.time;
                max += 1 / w.time;
            }
        }
        dir /= max;
        setAhead(Math.max(-1, Math.min(dir, 1)) * 36);
        setTurnRightRadians(normalRelativeAngle(wallSmoothing(getX(), getY(), getHeadingRadians() + e.getBearingRadians() + Math.PI / 2, (int)Math.signum(dir)) - getHeadingRadians())); //Staying perpendicular to the enemy to have a large escape angle
        setTurnRadarLeftRadians(getRadarTurnRemaining());
        System.out.println(Arrays.deepToString(m));
    }

    public void onHitByBullet(robocode.HitByBulletEvent e) {
        if (!waves.isEmpty()) {
            Wave w = waves.get(0);
            m[w.segment][w.segment2] += Math.signum(w.move);
        }
    }

    public void onHitWall(robocode.HitWallEvent e) {
        onHitByBullet(null);
    }

    public double wallSmoothing(double x, double y, double currentAngle, int dir) {
        if (dir != 0) {
            currentAngle += Math.PI / 20 * dir;//This is optional. I use it to get away from the enemy
            Rectangle2D battleField = new Rectangle(25, 25, 775, 575);
            while (!battleField.contains(x + Math.sin(currentAngle) * 160 * dir, y + Math.cos(currentAngle) * 160 * dir)) {
                currentAngle -= Math.PI / 45 * dir;
            }
        }
        return currentAngle;
    }

    public class Wave {

        double speed;
        double mea;
        double time;
        int segment;
        int segment2;
        double dir;
        double move = 0;

        public Wave(double power, double angle, double distance, int segment) {
            time = distance / (speed = (20 - 3 * power));
            mea = 8 / speed;
            this.segment = segment + 1;
            dir = (int)Math.signum(m[segment + 1][segment2 = (int)Math.round(time / 91 * 5)]);
            if(dir == 0) {
                dir = Math.random() < 0.5 ? -1: 1;
            }
        }
    }
    Dsekercioglu (talk)13:34, 12 June 2017