1

I am currently working on a game and have come into a bit of a problem.

I am working on an algorithm that will create a path for the AI characters to follow in the game. It is a top down adventure game and the AI will choose a random location on a 50 by 50 map then take the shortest path, taking obstructions into account.

I originally had it so that the AI will use 0-3 to determine how to move. If it is 0, they move up, 1, right, etc. Now I am trying to use the A* algorithm to create a list of moves. Once they arrive, they will choose a new destination and the process will repeat.

The problem I am having is storing the squares. From what I understand, you need a closed list and an open list. I was planning on using linked lists for these, then ultimately using a third linked list that stores the path to be followed.

The issue is that I need to store both an x and a y coordinate. I thought I could just use two lists for each, but that seems inefficient.

By the way, I am using Java to program it.

ziggystar
  • 28,410
  • 9
  • 72
  • 124
Grimey
  • 91
  • 2
  • 12

1 Answers1

1

Instead of having lists for each coordinate just wrap your x and y into a class. You can use the Point class or make your own storing the x and y and implementing a comparison to help with your A* Search. You can also have a look at Implementation of A Star (A*) Algorithm in Java

Community
  • 1
  • 1
n00begon
  • 3,503
  • 3
  • 29
  • 42