Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
Help checking a grid
Reply
Posted 2006-02-09, 02:29 PM
I have a grid that I need to check to see if a path of like colors exists from left to right or top to bottom. The buttons will be changed from white to blue or red.

The path does not have to be straight. i.e. the following path is fine.

XXXXXX
XXXXXX
XXXXXX
XXXXXX
XXXXXX
XXXXXX

Also, please note that, since the grid is actually composed of hexagons, more paths exist than simply the linear ones like in the previous example.

For example:

If you had a path that ran almost all the way from left to right on the bottom row
grid(0,5), grid(1,5), grid(2,5), grid(3,5), grid(4,5)
then having either grid(5,5) or grid(5,4) would result in a complete path. That's because grid(4,5) touches both grid(5,5) and grid(4,4).

The "color" of each button is stored into a 2-dimensional array grid(0,0) through grid(5,5) as red=1 and blue=2.

I tried hard-coding it, but the number of paths is just way too large.

Any ideas how how to go about this check?

I'm using VB05, but I can adapt any functionality that works.
Attached Images
File Type: jpg hexagon.JPG (64.6 KB, 2 views)
D3V said:
This message is hidden because D3V is on your ignore list.
What is it they say about silence being golden?

Last edited by Medieval Bob; 2006-02-09 at 02:37 PM.
Old
Profile PM WWW Search
Medieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzMedieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Medieval Bob
 



 
Reply
Posted 2006-02-09, 03:52 PM in reply to Medieval Bob's post "Help checking a grid"
I'm not sure I understand the problem completely, but I think you could use two recursive functions to solve this, one for top to bottom and one for left to right. Have a global variable that store true or false, initialize it to false, and if you find a like path, set it to true. For checking top to bottom, have it start the recurive function from every...hexagon in the top row, and for checking left to right have the recursive function start from every hexagon in the left-most column.

I don't know, that seems like it would work to me. You got some sample data I could try out?
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2006-02-10, 07:50 AM in reply to Demosthenes's post starting "I'm not sure I understand the problem..."
So you're saying like

check(i,j){
if grid(i,j) = grid(i+1,j) { check(i+1,j); }
if grid(i,j) = grid(i+1, j+1) { check(i+1, j+1); }
}

Ya I think that'll work. I'll code it up later on when I get some free time. Thx for the suggestion.
D3V said:
This message is hidden because D3V is on your ignore list.
What is it they say about silence being golden?
Old
Profile PM WWW Search
Medieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzMedieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Medieval Bob
 



 
Reply
Posted 2006-02-10, 04:42 PM in reply to Medieval Bob's post starting "So you're saying like check(i,j){..."
I did a hexagon problem like this earlier . . . it helped me to make the matrix 12x6 as well, but when checking fromt op to bottom sometimes you have to say:

check(r+2, c);
check(r+1, c+1);
check(r+1, c-1);

and I can't remember, but I also thing I ended up trying:

check(r-1, c-1); and check(r-1, c+1); as well . . ., making sure it didn't go backwards to the spot it just came from, but I'm not sure about those.

That got somewhat confusing at times, but it worked for me. Good luck man, those hexagon problems are a beast...lol.

Last edited by Demosthenes; 2006-02-10 at 04:46 PM.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2006-02-11, 09:36 AM in reply to Demosthenes's post starting "I did a hexagon problem like this..."
When the function calls itself, how do you make sure it's not going back to the same place? What if you had a circle of them? That would infinite loop...

*thinks* I guess I could get an array of grid locations and use it like a stack.

Start at 0,1: Store 0,1 in 'stack'
Find next at 1,1: Store 1,1 in 'stack'
Find next at 1,2: Store 1,2 in 'stack'
Find next at 2,2: Store 2,2 in 'stack'
Find next at 2,1: Store 2,1 in 'stack'
Find next at 1,1: 1,1 already exists in 'stack' do not take.

And then when I fall out of an iteration, I can set the most recent location in the 'stack' back to -1,-1. That may be hard to code correctly...

I suppose if I sat down and worked on it, I might find out... but meh. I'll do it later.
D3V said:
This message is hidden because D3V is on your ignore list.
What is it they say about silence being golden?
Old
Profile PM WWW Search
Medieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzMedieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Medieval Bob
 



 
Reply
Posted 2006-02-11, 10:15 AM in reply to Medieval Bob's post starting "When the function calls itself, how do..."
Medieval Bob said:
When the function calls itself, how do you make sure it's not going back to the same place? What if you had a circle of them? That would infinite loop...

*thinks* I guess I could get an array of grid locations and use it like a stack.

Start at 0,1: Store 0,1 in 'stack'
Find next at 1,1: Store 1,1 in 'stack'
Find next at 1,2: Store 1,2 in 'stack'
Find next at 2,2: Store 2,2 in 'stack'
Find next at 2,1: Store 2,1 in 'stack'
Find next at 1,1: 1,1 already exists in 'stack' do not take.

And then when I fall out of an iteration, I can set the most recent location in the 'stack' back to -1,-1. That may be hard to code correctly...

I suppose if I sat down and worked on it, I might find out... but meh. I'll do it later.
Yea, I ran across a problem with it bouncing between two spots. It wasn't a very elegant method to solve it, but I passed two more arguments to the function: the old r and the old c values, and made sure it didn't go back to that location. That made it work for me.

I guess you could have a parallell boolean grid and mark true false for spots you've been also . . . I haven't tried that though.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2006-02-11, 10:52 AM in reply to Demosthenes's post starting "Yea, I ran across a problem with it..."
Ya, that would work even better I think.

That way, I'd just have to set the current (i,j) location to false when the iteration fell back a step.
D3V said:
This message is hidden because D3V is on your ignore list.
What is it they say about silence being golden?
Old
Profile PM WWW Search
Medieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzMedieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Medieval Bob
 
 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 02:15 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.