AMazeBot 2016 Workshop #1 Code

// AMazeBot 2016 Sample bot - WorkShop#1 - Distance calculations
// 
package bots.WorkShopBot_1;

import amazebot2016.*;
import amazebot2016.utils.Compass;
import java.awt.Point;

public class Brain extends BotBrain {
    
    @Override
    public String getName() {
        return "WorkShopBot_1";
    }

    @Override
    public void run() {

        Point goal = this.getGoalCorner();
        
        while (true) {
            // Calculate the distance from a Point to the goal for 
            // 4 different options
            Point pos = getPosition();
            
            Point eastPoint = new Point(pos.x + 1, pos.y);
            Point northPoint = new Point(pos.x, pos.y - 1);
            Point westPoint = new Point(pos.x - 1, pos.y);
            Point southPoint = new Point(pos.x, pos.y + 1);

            double distanceEast = goal.distance(eastPoint);
            double distanceNorth = goal.distance(northPoint);
            double distanceWest = goal.distance(westPoint);
            double distanceSouth = goal.distance(southPoint);

            boolean moved = false;
            if (distanceEast < distanceNorth
                    && distanceEast < distanceWest
                    && distanceEast < distanceSouth) {
                // East is best
                    moved = move(Compass.EAST);
            }
            if (!moved
                    && distanceNorth < distanceWest
                    && distanceNorth < distanceSouth) {
                    moved = move(Compass.NORTH);
            }
            if (!moved
                    && distanceWest < distanceSouth) {
                    moved = move(Compass.WEST);
                   
            } else if (!moved) {
                moved = move(Compass.SOUTH);
                
            }

        }
    }
}

                

Although we have planned topics for each workshop, we generally try to ensure some time is available for answering any student questions.