After reading up a bunch on A* pathfinding (read some tuts, this one was good: http://www.policyalmanac.org/games/aStarTutorial.htm )
I am now trying to implement it into my basic RTS game. I understand how it works, but I am a bit confused as to how I should structure it in my code.
In my game I have the map (TMap) set up as an array of tiles (TTile, which I will use for the pathfinding), and I have a type for holding the unit objects (TUnit). Each TTile has the boolean field 'occupied' which is True if an object is on that tile.
My first thought on implementing the pathfinding looked like this:
I know that I need an OpenList and a ClosedList, but should I be using lists rather than arrays? The link I posted above has a download for a Blitz Basic example. In the code he appears to be using arrays for the OpenList and ClosedList, but I assume that's because of BB not allowing access to lists?
I am also confused as to which fields I need for TPathfind. Would I need f,g, and h, when I could just calculate them? Do I even need startx,starty, and goalx,goaly?
I am now trying to implement it into my basic RTS game. I understand how it works, but I am a bit confused as to how I should structure it in my code.
In my game I have the map (TMap) set up as an array of tiles (TTile, which I will use for the pathfinding), and I have a type for holding the unit objects (TUnit). Each TTile has the boolean field 'occupied' which is True if an object is on that tile.
My first thought on implementing the pathfinding looked like this:
Type TPathfind Field startx:Int,starty:Int,goalx:Int,goaly:Int,parentx:Int,parenty:Int,nodex:Int,nodey:Int Field f:Int,g:Int,h:Int 'f=g+h, g=sum of costs it took to get there, h=prediction to goal Global OpenList:TList=New TList Global ClosedList:TList=New TList Function SetCoords:TPathfind(unitx:Int,unity:Int,endx:Int,endy:Int) End Function Method EstimateGoal:Int(x:Int,y:Int) End Method Method ExpandNode() End Method End Type
I know that I need an OpenList and a ClosedList, but should I be using lists rather than arrays? The link I posted above has a download for a Blitz Basic example. In the code he appears to be using arrays for the OpenList and ClosedList, but I assume that's because of BB not allowing access to lists?
I am also confused as to which fields I need for TPathfind. Would I need f,g, and h, when I could just calculate them? Do I even need startx,starty, and goalx,goaly?