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.

AppGameKit Classic Chat / Need a little help with something

Author
Message
Trisect Development
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Denmark
Posted: 29th Mar 2012 08:34
I'm making a match-5 game and I ran into a little problem.

When I detect for 5 in a row I end up with some thing like this:

00xxxxx0xx

They are values in an array
ex.


Now to my question.
How do I isolate the 5 x's in this?

I need the positions in the array of the 5 x's

iOS Apps from Trisect Development.
Click here.
Trisect Development
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Denmark
Posted: 30th Mar 2012 00:09
Okay I found out how to find 5 in a row horizontal and vertical.

Now I'm stuck when trying to find 5 in the diagonal.
I need to find 5 and find the position of the first en the line of 5's.

I could really use some help guys!

iOS Apps from Trisect Development.
Click here.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 30th Mar 2012 02:10
This is one of those problems that seems more complex than it actually is.

For a start, you only need to look in four directions for the whole thing, Up/Right, right, Down/Right and Down. All other directions are just duplicates of those four.

The first step is to find the first cell of the five and for this you don't need to check the entire grid.

Suppose your grid is 10 x 10;

5 in a row horizontally or diagonally must have room for four more to the right of it, so MUST start in the left most six columns.

Similarly 5 in a row vertically or diagonally down and right MUST start in the top six rows.

Diagonally up and right MUST start in the bottom six rows and the left six columns

For each X in these locations you do a loop counting from 1 to 4 and check the cells offset by that amount, if any do not contain an X, move onto the next start point.

If all four match you have the five.

So for example, if you have an X at position 2,3, firstly set a flag to assume a match, then if one fails, clear that flag;

Here's some sample code to check for diagonal down and right, assuming you have found an "x" at x=2, y=3

If you get to the end of the loop and "matchDownRight" is still 1, then you have your five.

Do a similar loop for other directions.

Login to post a reply

Server time is: 2024-11-23 07:18:30
Your offset time is: 2024-11-23 07:18:30