EarthQuake
9.5 on the Richter!

Posts: 2745
Registered: 05-03 |
Okay, before I get started, let me explain my situation...
I have a grid of sectors, each being a room that is connected to all adjacent rooms via a doorway. It might look something like this:
code: ########### ########### ###########
# # # # # #
# 1 # G # 2 # J # 3 #
# # # # # #
########### ########### ###########
A B C
########### ########### ###########
# # # # # #
# 4 # H # 5 # K # 6 #
# # # # # #
########### ########### ###########
D E F
########### ########### ###########
# # # # # #
# 7 # I # 8 # L # 9 #
# # # # # #
########### ########### ###########
Where 1-9 is the room (or "cell" as I will call it), and A-L is a doorway between two cells (I will call these "connections"). The ordering is just arbitrarily chosen, and doesn't necessarily make any sense in the algorithm I'm trying to figure out.
What I'm trying to do (this is related to ACS) is trace a path from a randomly chosen cell to another cell, to create a randomized layout of sorts. All connections not part of this path are made inaccessible. What I am having trouble implementing though, is an algorithm that can take a known cell index (or even the coordinates of that cell) and determine the tag of any of it's connections (which actually varies depending on if that cell is on the corner or edge of the grid).
Basically, I'm trying to come up with a function that looks something like this:
code: Tag = GetConnectionTag(Cell, Direction);
Where "Tag" is literally a unique tag assigned to each doorway sector, "Cell" is the unique index of the room I'm currently working from (1-9 in the above example), and "Direction" is some constant used for specifying which connection I want to examine. If a given cell does not actually have a connection in the specified direction, the function would probably return a tag of zero, from which I could abort operation. The tags used for the connections will obviously depend on the algorithm itself, each being unique.
I have the following known information: the maximum size of the grid, the unique cell index, the cell X/Y coordinates, and the direction of the connection to check.
Again, the order I've used in my illustration is arbitrarily chosen. Ideally, connections A-L would have values that coincide with their actual sector tags, but I do not know what values these would be. I've busted my balls trying to wrap my head around all the math, and even dragged a friend of mine into this who is much brighter than I am, but still, no solutions come to mind. So as a last resort, I'm asking the Doom collective mind for help!
I don't know if there is a simple solution to this, but I would really appreciate some help, as I have a project that depends on a clean implemention of this. Thanks much.
|