Basic A* pathfinding algorithm question

  • Thread starter K29
  • Start date
  • Tags
    Algorithm
In summary, the speaker is seeking advice for a project where they must program an AI to beat other computer science students in a game. They have researched and are using a basic A* pathfinding algorithm with a manhattan heuristic, but they are concerned about the time constraints of the game engine. The game is a 2d grid with worms as agents and there are 4 "obstacles" (including the speaker's worm). The speaker is unsure if they are wasting their time with this algorithm and asks if they are allowed to save data from one call of their function to the next to potentially speed up the process. Another person suggests using an object to store results instead of accessing the slow and unpredictable disk.
  • #1
K29
108
0
Just looking for some advice here.(This is the first time I'm doing anything like this so please bare with me)

I have been given a project where we have a game and 4 agents (the other 3 agents are other computer science students) The idea is to program a good AI that can beat theirs.

I am going above and beyond what was required and researched a basic A* pathfinding algorithm with manhattan heuristic. I am currently coding this in java for the game. The game is a 2d grid with worms as agents. each worm takes up multiple squares.

I am worried that it will be problematic though. The game engine allows for 50 milliseconds to respond with a "move" for your agent, (if you don't respond in time it moves it in whatever direction you are facing which is NOT good) I am told that 50 microseconds is a long time in computer terminology. But A* looks expensive. The board is 50 by 70 for the game and there are 4 "obstacles" (my worm and my opponents worms). There are 3 degrees of movement for a move (straight, left, right, but not back on yourself because the agent is a worm)

Do you think I am wasting my time on this or will basic A* finish in time(50 ms)?(apparently the server which our agents will be tested on has a quad core i5 I think) The worst case on a 50X70 board of squares I'm scared may take too long, but as I said the only obstacles are yourself and other 3 worms which can each take up a maximum of 59 squares each in the worst case.
 
Last edited:
Physics news on Phys.org
  • #2
Given enough real-life time, you should try a lot of different AI's for your worm.

I've never actually looked at the algorithm, but I was under the impression that the A* algorithm allowed you to tune its running time -- that there was a parameter you could tweak that controls how much or how little effort you put into path-finding.


Are you allowed to save data from one call of your function to the next? Maybe you can speed things up even further by remembering the results of previous calculation.
 
  • #3
A* looks at different nodes adjacent to your agent or previous nodes the path you are constructing and associates a heuristic cost to each node by choosing a simple path to the target(ignoring obstacles) and a "past" cost based on the cost of nodes to get to the current node you are examining in your path. The costly part of the algorithm is comparing a nodes' final cost to a large amount of other nodes' costs on the board and this has to be repeated multiple times until you have a path to your destination.

Great idea! I could remember the current node with smallest cost and I won't have to cycle through all the nodes every time, just the new ones that are added will need to be checked. Remembering a solution path from the previous timestep of the game could also be handy, but then I need to read and write a line from a textfile. Is a harddisk read and write expensive? (Sorry, I'm just not sure about relatve speed of such things, especially since I'm not using the computer that it will be tested on in the end)
 
Last edited:
  • #4
Accessing disk is slow (and often unpredictable); you don't want to do that. You just want to put the results in some object that can be accessed by your function.
 
  • #5


As a scientist, my advice would be to first test the basic A* algorithm on a smaller scale, such as a 10x10 grid, to see how long it takes to find a path. This will give you an idea of the algorithm's efficiency and whether it can be completed within the 50 millisecond time limit.

If the algorithm does not finish in time, you can try optimizing it by implementing techniques such as pruning or using a different heuristic. You can also consider parallelizing the algorithm to take advantage of the quad core i5 processor.

It's important to also consider the complexity of the game and the behavior of the other agents. If the other agents are not using efficient pathfinding algorithms, then your basic A* algorithm may still have a chance to outperform them.

Overall, it's always good to go above and beyond in a project, but also be mindful of the constraints and limitations. Keep testing and optimizing your algorithm to find the best solution within the given time frame. Good luck!
 

Related to Basic A* pathfinding algorithm question

1. What is the A* pathfinding algorithm?

The A* (A-star) pathfinding algorithm is a popular method used in artificial intelligence and robotics to find the shortest path between two points on a graph or grid. It is a combination of the Dijkstra's algorithm and a heuristic function, which allows it to efficiently search through a large number of nodes and find the optimal path.

2. How does the A* algorithm work?

The A* algorithm works by evaluating each node in a graph or grid based on two factors - the cost of reaching that node from the starting point, and an estimated cost of reaching the end goal from that node. It then chooses the node with the lowest total cost and continues to evaluate its neighboring nodes until the end goal is reached.

3. What is a heuristic function in the A* algorithm?

A heuristic function is a method used to estimate the distance between a current node and the end goal in the A* algorithm. It helps guide the search towards the most promising nodes and improves the efficiency of the algorithm.

4. Can the A* algorithm be used in different types of graphs or grids?

Yes, the A* algorithm can be used in a variety of graphs and grids, as long as they have defined nodes and connections between them. It is commonly used in 2D and 3D grids, but can also be applied to other types of graphs such as road networks or game maps.

5. What are the advantages of using the A* algorithm?

The A* algorithm is known for its efficiency and optimality, meaning it will always find the shortest path between two points if one exists. It is also versatile and can be applied to different types of problems, making it a popular choice in many fields such as robotics, video games, and route planning.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
30
Views
4K
Replies
2
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top