Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / 2x9 grid... 6 shapes (3 each)... matching 3 of the same kind...

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 8th Sep 2010 16:52
Hi all...

Ok, I've been trying to get my head around this for ages and let me begin that I want this game to be 3D, not 2D.

Here is the situation:

I have a 2x9 grid:

[1] [2] [3] [4] [5] [6] [7] [8] [9]
[10] [11] [12] [13] [14] [15] [16] [17] [18]

In these 18 spaces are 6 different types of objects... 3 Squares, 3 Triangles, 3 Circles etc., all randomly placed on the 18 spaces.

Now... I'm able to move them around and make something happen if the player has 3 identical objects touching together horizontally.

BUT! That same thing happens if the 3 identical shapes are on spaces 8, 9 and 10 or 9, 10, and 11. As you can see, these spaces are in numerical order but visually, they are not touching each other horizontally.

How do I go about preventing this? I can't change the spaces to be like this by the way:

[1] [2] [3] [4] [5] [6] [7] [8] [9]
[18] [17] [16] [15] [14] [13] [12] [11] [10]

Does anyone know the logical way as to solve my problem? Currently, the code that makes something happen when 3 identical objects are in line horizontally relies on their position on the spaces of the grid. I.E. if the 3 Squares are in spaces 5, 6 and 7 then do something.

I hope I'm able to explain my problem. If not, just ask and I will do my best to further explain.

Thanks
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Sep 2010 17:32
How about a quick bit of code? It might make it easier to impliment for you. I just spent 5 mins thinking about 10 different ways this might be done...

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Sep 2010 18:09
Any time I do something like this, I tend to use an extra typed variable flag, or an flag array the same as your 'board' layout - then step through each location, wipe out the flags, flag the current location, then step through the 'board' checking neighboring tiles to see if they are next to a flagged tile that is the same type. I'd total the number of flags, and if its >2 then remove the tiles that are flagged. It's not the quickest method, but it's quite reliable.

I think you could also keep a record of which tiles are touching eachother - so for tile 1, it would be touching 2 and 10 - tile 5 would be touching 4, 6 and 14. Then you know which tiles to check, maybe use 0 to signify a blank - and use a set array, like neighbors(18,3) which you'd fill with the neighboring tile numbers. When checking, you could count the matches in the neighboring tiles...

dim neighbor(18,3)
neighbor(1,0)=2 : neighbor(1,1)=10 : neighbor(1,2)=0

Probably the easiest method to impliment I think.

Health, Ammo, and bacon and eggs!
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 8th Sep 2010 18:12
Here is something I threw together. Perhaps it will help you.



So many games to code.......so little time.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Sep 2010 19:08
Quote: "BUT! That same thing happens if the 3 identical shapes are on spaces 8, 9 and 10 or 9, 10, and 11. As you can see, these spaces are in numerical order but visually, they are not touching each other horizontally."


Can't you prevent this by checking numbers 2-8 and 11-17 instead of all?

I might not understand the question completely though...

Cheers!
Sven

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 9th Sep 2010 07:12 Edited at: 9th Sep 2010 12:22
@baxslash

Umm... the reason why I didn't post my code in the first place is that I'm not really a programmer so my code tend to be very long and considered "messy". I don't take shortcuts when I first code because spreading it out helps me think more clearly.

But I will post it anyway. Warning though, the code is about 900 lines long. This is for a mechanic for a game I'm working on:

EDIT: I took down code temporarily because I'm going to work on it using my new idea.

@Van B
Uh... I'm not entirely sure how your method works...

@LBFN
I understood your code up until your function. I don't get how your function works.

@Sven B
With my current code, I'm not sure how.

By the way, I want to keep this 3D because I'll be adding in 3D assets to replace the coloured cubes.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 9th Sep 2010 12:19 Edited at: 9th Sep 2010 12:39
I think I may have found the solution to fix my problem.

Considering the way each cube is positioned and moved around, I can simply just expand my board. Rather than make it 5x5, I'll make it 7x7 so that the main gameboard has a "boarder" around the main 5x5 board.

Therefore, anything neighbouring cubes of the same colour that are in the board's boarders won't be counted!

It's hard to explain but I'm going to work on it now.

EDIT: Quick update... IT WORKS! I didn't have to change a lot as well. Because the way I coded this thing was that each object in the grid are given position numbers or space numbers. Before, using the 2x9 grid example above, the position of an object in row 2 and column 1 would be 10 (i.e. in space 10).

So what I done was "expand" my board so that instead of a 2x9 it's now a 4x11 but the game board is still the 2x9 located in the centre. There, the next row wouldn't start at 10, it would start at 12 and since there is at least 2 gaps in difference between 9 and 12, my current code didn't have to stay since getting 9, 10 and 11 is impossible now (since spaces 10 and 11 are the boarders).

Instead of:

1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18

It's:

1 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31 32 33
34 35 36 37 38 39 40 41 42 43 44

With numbers 13 - 21 and 24 - 32 being the 2x9 grid. Hope that was clear.

BUT!!! Of course I can't foresee the future but for now, it solved my problem ^_^

Will keep this thread up to date in case something goes wrong.

Login to post a reply

Server time is: 2026-07-22 12:41:14
Your offset time is: 2026-07-22 12:41:14