1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Basic A* pathfinding algorithm question

  1. Aug 8, 2011 #1

    K29

    User Avatar

    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: Aug 8, 2011
  2. jcsd
  3. Aug 8, 2011 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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.
     
  4. Aug 8, 2011 #3

    K29

    User Avatar

    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: Aug 8, 2011
  5. Aug 8, 2011 #4

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Basic A* pathfinding algorithm question
  1. Algorithm Help (Replies: 4)

Loading...