Basic A* pathfinding algorithm question

  • Thread starter Thread starter K29
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary

Discussion Overview

The discussion revolves around implementing a basic A* pathfinding algorithm for a game involving agents represented as worms on a 2D grid. Participants explore the feasibility of the algorithm within a strict time constraint for making moves, as well as potential optimizations and challenges related to performance and data management.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses concern about the computational expense of the A* algorithm given the 50 ms time limit for responding with a move, especially on a 50x70 grid with multiple obstacles.
  • Another participant suggests that the A* algorithm may allow for tuning its running time through adjustable parameters, potentially improving performance.
  • A participant explains the mechanics of the A* algorithm, highlighting the need to compare costs of nodes repeatedly, which could be a bottleneck in performance.
  • There is a proposal to remember the current node with the smallest cost to avoid unnecessary comparisons, as well as to retain previous path solutions to enhance efficiency.
  • Concerns are raised about the speed of reading and writing data to a hard disk, with one participant advising against using disk access due to its slow and unpredictable nature.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the feasibility of the A* algorithm within the time constraints, and there are differing opinions on the best strategies for optimization and data management.

Contextual Notes

Participants discuss the potential impact of obstacles and the size of the grid on the algorithm's performance, as well as the implications of using disk access for storing data, which remains unresolved.

K29
Messages
103
Reaction score
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
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.
 
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:
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
7K
Replies
1
Views
2K
Replies
14
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K