• Create Account

## [Help] c++ Allegro, PuyoPuyo colors comparative?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1javiside  Members

104
Like
0Likes
Like

Posted 21 July 2014 - 10:23 PM

Hi all, im making a game in c++ and i have a problem.. well its not a problem but i want to know the best way to compare the colors with te row and the columns, the way im thinking is .. something like this.. :

char board[7][7];

int row , col = 1;
int srch=1;
for(row=6;row>1;row--)
{
if (map[row][col]== map [row][col+srch] && map[row][col]== map [row][col+srch+1] && .....                   map[row][col+srch+3]== map [row][col+srch+4])
{
map[row][col]=' ';
...
map[row][col+srch+4]=' ';
}
else
else
else....etc
{
srch++;
}
} ....

well something like that ....establishing all the possible IF opcions :S... but there is a easier way to detect the collisions?? like in c# bounds.intersect? ... as you can see, in the board, 1 is for RED, 2 is BLUE, 3 YELLOW, 4 Green .. when there are 4 or more of the same kind intersecting they're all destroyed.. so is a better way or function ? im using c++ and allegro.. thank you all for your help.

Edited by javiside, 22 July 2014 - 11:01 AM.

### #2plainoldcj  Members

1068
Like
0Likes
Like

Posted 22 July 2014 - 05:46 AM

from your code above i assume you're only interested in finding adjacent columns of the same color
in an array. it's not really an intersection problem i think.
so

231111134
121122344

would become

23_____34
121122344

you could look for the start and end of sequences of the same color. something like this would work:

int sequenceColor;
int startIndex;

for each row:
for(int col = 0; col < numColumns; ++col) {
int color = map[row, col];
if(color != sequenceColor) {
// new sequence begins, check if last sequence is long enough to clear
int endIndex = col;
if(endIndex - startIndex >= 4) {
set map[row, i] = ' ', for i in [startIndex, ..., endIndex - 1]
}

startIndex = col; // start new sequence
sequenceColor = color;
}
}


Edited by plainoldcj, 22 July 2014 - 05:48 AM.

### #3javiside  Members

104
Like
0Likes
Like

Posted 22 July 2014 - 10:54 AM

from your code above i assume you're only interested in finding adjacent columns of the same color
in an array. it's not really an intersection problem i think.
so

231111134
121122344

would become

23_____34
121122344

you could look for the start and end of sequences of the same color. something like this would work:

int sequenceColor;
int startIndex;

for each row:
for(int col = 0; col < numColumns; ++col) {
int color = map[row, col];
if(color != sequenceColor) {
// new sequence begins, check if last sequence is long enough to clear
int endIndex = col;
if(endIndex - startIndex >= 4) {
set map[row, i] = ' ', for i in [startIndex, ..., endIndex - 1]
}

startIndex = col; // start new sequence
sequenceColor = color;
}
}


Hi, thank you for your answer but im also looking for adjacent in the upper rows and then start again on the cols, but maybe saving the positions? in a new array? like in your example :

231111134 ---> 23_____34 saving (3,4,5,6,7) then compare in the upper row and if there is 1 delete too..

For instance:

if i have:

224133

123144

221124

2311134

would become

__4_33

1_3___

____2_

_3___3_

or maybe in the first loop will erase all the 2 then the 1 ,then all the 4 until there is no more equal adjacent

then those numbers will drop to look for combos or chains and would become:

______

______

____3_

1334233

and look again focoincidence but i dont think that would be a problem just running again the code.

Thanks again.

### #4fastcall22  Moderators

9754
Like
1Likes
Like

Posted 22 July 2014 - 11:29 AM

well something like that ....establishing all the possible IF opcions :S... but there is a easier way to detect the collisions??

This is important step in your growth as a programmer: When you realize what you have learned is infeasible here and that there must be an easier way. While it is certainly possible to code the logic entirely of IF-statements, it quickly becomes unmanageable and buggy. So, as a programmer, you must solve the problem in a generic way. For instance, the procedure could look something like this, in pseudo code:

1. For every unvisited tile on the board:
2.	For each unvisited neighbor of this tile:
3.		Visit each neighbor of the same color:
4.			Count and mark this neighbor tile
5.			Move to this tile and repeat step 2 for this neighbor tile
6.	If there are no more neighbors, and we have moved to this tile:
7.		Move back, and continue on step 5
8.	If we found four or more tiles of the same color neighboring this tile:
9.		Score and remove these tiles

Notice steps 2, 5, and 7: Recursion might be helpful here.
zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

### #5javiside  Members

104
Like
0Likes
Like

Posted 22 July 2014 - 12:24 PM

This is important step in your growth as a programmer: When you realize what you have learned is infeasible here and that there must be an easier way. While it is certainly possible to code the logic entirely of IF-statements, it quickly becomes unmanageable and buggy. So, as a programmer, you must solve the problem in a generic way. For instance, the procedure could look something like this, in pseudo code:

1. For every unvisited tile on the board:2.	For each unvisited neighbor of this tile:3.		Visit each neighbor of the same color:4.			Count and mark this neighbor tile5.			Move to this tile and repeat step 2 for this neighbor tile6.	If there are no more neighbors, and we have moved to this tile:7.		Move back, and continue on step 58.	If we found four or more tiles of the same color neighboring this tile:9.		Score and remove these tiles
Notice steps 2, 5, and 7: Recursion might be helpful here.
Hi, thanks for the logic help I'll try that thank you again for the help

Edited by javiside, 22 July 2014 - 12:55 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.