-1

For a school project, my friends and I are learning what is pathfinding and how to exploit it via a simple exercise:

For a group of ants going from A to B, they need to travel through multiple nodes, one at a time.

I've read some explanation about Dijsktra's algoritm, and I wanted to know if I could use it in a graph where every distance between every node is 1 unit. Is it optimal ? Or is A* more appropriated to my case ?

EDIT:

Since I had knowledge on the graph, BFS was prefered because distance between node was pre-computed, where Djisktra is prefered when you have absolutely nothing about the graph itself. See this post for reference

Quentin Laillé
  • 125
  • 1
  • 12
  • 1
    *"Is it optimal?"* That is relative. We cannot answer that. But if you are learning, then Dijsktra is something that is easy to start with. – user694733 Apr 06 '17 at 11:53
  • easy was the word, thanks for having my back. – Quentin Laillé Apr 06 '17 at 12:21
  • 1
    Dijkstra is a special case of AStar. You can find an explanation on SO: http://stackoverflow.com/a/16268762/5847906 – Ayak973 Apr 06 '17 at 12:29
  • 1
    This question might be better suited for http://ai.stackexchange.com/ or http://gamedev.stackexchange.com/. Also there are plenty of similar questions already asked and there are plenty of online resources discussing these algorithms. Take a look at [ask] and [mcve] before you post a question a Stack Overflow, it's important to do some research yourself first. – PJvG Apr 06 '17 at 12:33

1 Answers1

2

If every edge has the same cost, then Dijkstra's algorithm is the same as a breadth-first search. In this case you might as well just implement BFS. It's easier.

If you have a way to estimate how far a point is from the target, then you could use A* instead. This will find the best path faster in most cases.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87