This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Ok here is my robot (still some unfinished methods) but I was wondering if you could tell me if:
1) The logic behind the pathfinding is correct? (See code below)
2) Am I correctly using distance :S?
3) Waypoint is a class I created of type Waypoint(int,int), I have an array of these. How do I input the next Waypoint for the move method - I assume this is done through the main Class is this correct :S?
I am afraid the answer to all three questions is . . . it all depends.
We don't know the way your robot is supposed to move. What is the algorithm for moving? Write it down with pencil and paper, and keep breaking down each step until you get it to words of one syllable. Then you can see whether the logic is correct.
We don't know how you calculate distance moved; you appear only to move horizontally and vertically, like a rook in chess. But we can tell that method won't compile because of the extraneous [ and ]. Why are you stepping one at a time? Why not add the difference between your positions? Have you found the Math.abs() method?
What is a main Class? Do you mean a class with the main() method in? You would be better to create a method which instructs the Robot to move. You can pass the Waypoint array to it, and iterate through the array; for each element, pass that element to the move() method. The move() method now needs a Waypoint parameter.
You could, instead, pass a Waypoint to the move method, and iterate the array in the move method. But I think the first suggestion is better.