• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement my next waypoint for pathfinding.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess your question boils down to: "How do I find the shortest path to my destination?"

Personally I always use something called A* search. It's relatively fast at finding a good path to the destination.
It's hard to explain in a simple way without knowing the details of your project.

Also you should move to your next way point directly. If you first move horizontally and then vertically, you may end up "stuck behind a wall".
 
reply
    Bookmark Topic Watch Topic
  • New Topic