Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Quick Question about Saving Grid Positions.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RedRogueXIII




PostPosted: Sat Nov 12, 2005 2:21 pm   Post subject: 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 Sad
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Nov 12, 2005 3:16 pm   Post subject: (No subject)

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 a grid system basis in [Turing Source Code].
do_pete




PostPosted: Mon Nov 14, 2005 11:22 am   Post subject: (No subject)

you could go:
code:
coordinates(x,y):=1
RedRogueXIII




PostPosted: Tue Nov 15, 2005 7:06 pm   Post subject: (No subject)

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




PostPosted: Tue Nov 15, 2005 8:10 pm   Post subject: (No subject)

RedRogueXIII wrote:
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




PostPosted: Tue Nov 15, 2005 8:14 pm   Post subject: (No subject)

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:
code:

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




PostPosted: Tue Nov 15, 2005 8:40 pm   Post subject: (No subject)

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




PostPosted: Wed Nov 16, 2005 7:29 pm   Post subject: (No subject)

Isnt Pathfinding more got to do with Recursions than 2D arrays? Or am I wrong about what I think hes doing?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Nov 16, 2005 7:45 pm   Post subject: (No subject)

GlobeTrotter wrote:
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. Smile

MysticVegeta wrote:
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




PostPosted: Wed Nov 16, 2005 7:49 pm   Post subject: (No subject)

I dont see how assigning the grid elements to a 2D array is a complex part..?
Cervantes




PostPosted: Wed Nov 16, 2005 8:32 pm   Post subject: (No subject)

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




PostPosted: Wed Nov 16, 2005 10:38 pm   Post subject: (No subject)

yeah it was dumb of me to say that lol Embarassed
PathFinding can sometimes really be a pain, except for zylum that is. Those recursion trees are so confusing....
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: