
-----------------------------------
RedRogueXIII
Sat Nov 12, 2005 2:21 pm

Quick Question about Saving Grid Positions.
-----------------------------------
I'm trying to do A* pathfinding for a grid but I'm completely blank on how to save the x and y positions to a 2dimensional array.  I'll post my code on request but I really haven't started on the pathfinding yet. im stuck :(

-----------------------------------
Cervantes
Sat Nov 12, 2005 3:16 pm


-----------------------------------
Think of the 2D array as a cartesian coordinate system.  Each point on a cartesian grid is defined by two values: a value in each of the axes.  Similarly, you can plot a maze or such onto a 2D array.

For some source code, check out [url=http://www.compsci.ca/v2/viewtopic.php?t=9878]a grid system basis in [Turing Source Code].

-----------------------------------
do_pete
Mon Nov 14, 2005 11:22 am


-----------------------------------
you could go:
coordinates(x,y):=1

-----------------------------------
RedRogueXIII
Tue Nov 15, 2005 7:06 pm


-----------------------------------
took the easy way and just made two seperate arrays.

var setx, sety:array 1..* of int

so much easier if you think about it.

-----------------------------------
GlobeTrotter
Tue Nov 15, 2005 8:10 pm


-----------------------------------
took the easy way and just made two seperate arrays.

var setx, sety:array 1..* of int

so much easier if you think about it.

Doesn't make sense.  Two arrays, one for x, one for y, cannot replace a 2-D array.  For example, if you have a 10x12 space, stored in a 2-D array, that's 120 elements.  If you had two arrays, one 10 and one 12 that's only 22 elements.  You would need 12 arrays each of 10 instead of a 2-D.

-----------------------------------
Cervantes
Tue Nov 15, 2005 8:14 pm


-----------------------------------
I must not understand what you're trying to do, because that definately wouldn't work for what I'm thinking of.

You said "pathfinding for a grid".  That implies that you have a grid.  The grid is not composed of an x axis and a y axis, as you seem to have set up here.  No, it is a 2 dimensional plane.  

Say your grid was 10 units wide and 10 units high.  The system you've got set up there would allow you to store 20 (= 10 + 10) pieces of data on the grid spaces.  But there's a problem: there are 100 (=10*10) spots on this grid.

Regardless, you shouldn't do setx and sety, you should make a set record:

var set : array 1 .. * of
    record
         x, y : int
    end record


There's a tutorial in [Turing Tutorials] on records and types.  Check the Turing Walkthrough for a link.

-----------------------------------
GlobeTrotter
Tue Nov 15, 2005 8:40 pm


-----------------------------------
Cervantes, I don't think he would need records.  From what I understand of A*, it requires a 2-D array of boolean depicting what areas are traversable.

-----------------------------------
MysticVegeta
Wed Nov 16, 2005 7:29 pm


-----------------------------------
Isnt Pathfinding more got to do with Recursions than 2D arrays? Or am I wrong about what I think hes doing?

-----------------------------------
Cervantes
Wed Nov 16, 2005 7:45 pm


-----------------------------------
Cervantes, I don't think he would need records. From what I understand of A*, it requires a 2-D array of boolean depicting what areas are traversable.
I'm aware.  I was referring to the snippet of code he posted, and nothing else. :)

Isnt Pathfinding more got to do with Recursions than 2D arrays? Or am I wrong about what I think hes doing?
It would use both, though recursion is the more complex concept of the two.

-----------------------------------
MysticVegeta
Wed Nov 16, 2005 7:49 pm


-----------------------------------
I dont see how assigning the grid elements to a 2D array is a complex part..?

-----------------------------------
Cervantes
Wed Nov 16, 2005 8:32 pm


-----------------------------------
Hence why I said recursion was the harder of the two.

But MysticVegeta: You can't define, in absolute terms, the difficulty of a task.  The universe is perceived differently by different observers.  This fact extends from Einstein to basic social situations such as this.

-----------------------------------
MysticVegeta
Wed Nov 16, 2005 10:38 pm


-----------------------------------
yeah it was dumb of me to say that lol  :oops: 
PathFinding can sometimes really be a pain, except for zylum that is. Those recursion trees are so confusing....
