Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How to implement my next waypoint for pathfinding.  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • 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?

Posts: 62156
  • Mark post as helpful
  • send pies
  • 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.
Posts: 9547
  • Mark post as helpful
  • send pies
  • 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".
Skool. Stay in. Smartness. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!