0

Hello, I'm making a program that can play Bejeweled 2.

Everything is working smooth except for a glitch in the movement algorithm.

If anyone is really good at making these type of algorithms can you look at this code and/or give me some hints ?

This is the core algorithm for 3 pieces of the same color. This is also the base for 4,5 pieces and also for the sparkle piece.

I added the i and j rules recently i don't know if they are really necessary.

```
for(j=0;j<8;j++)
for(i=0;i<8;i++)
if(t==0){
if((i>=1&&j>=0&&ara[i][j].color==ara[i-1][j-1].color&&ara[i][j].color==ara[i-2][j-1].color)||
(j>=2&&ara[i][j].color==ara[i][j-2].color&&ara[i][j].color==ara[i][j-3].color)||
(i<=5&&j>=1&&ara[i][j].color==ara[i+1][j-1].color&&ara[i][j].color==ara[i+2][j-1].color)||
(i>=0&&i<=6&&j>=0&&ara[i][j].color==ara[i-1][j-1].color&&ara[i][j].color==ara[i+1][j-1].color)){
p.x1=ara[i][j].width;
p.y1=800-ara[i][j].height;
p.x2=ara[i][j-1].width;
p.y2=800-ara[i][j-1].height;
t=1;
}else
if((i>=0&&j>=1&&ara[i][j].color==ara[i-1][j-1].color&&ara[i][j].color==ara[i-1][j-2].color)||
(i>=2&&ara[i][j].color==ara[i-2][j].color&&ara[i][j].color==ara[i-3][j].color)||
(i>=0&&j<=5&&ara[i][j].color==ara[i-1][j+1].color&&ara[i][j].color==ara[i-1][j+2].color)||
(i&&j&&ara[i][j].color==ara[i-1][j-1].color&&ara[i][j].color==ara[i-1][j+1].color)){
p.x1=ara[i][j].width;
p.y1=800-ara[i][j].height;
p.x2=ara[i-1][j].width;
p.y2=800-ara[i-1][j].height;
t=1;
}else
if((i>=0&&j>=1&&i<=6&&ara[i][j].color==ara[i+1][j-1].color&&ara[i][j].color==ara[i+1][j-2].color)||
(i<=4&&ara[i][j].color==ara[i+2][j].color&&ara[i][j].color==ara[i+3][j].color)||
(i<=6&&j<=5&&ara[i][j].color==ara[i+1][j+1].color&&ara[i][j].color==ara[i+1][j+2].color)||
(i<=6&&j<=6&&j>=0&&ara[i][j].color==ara[i+1][j-1].color&&ara[i][j].color==ara[i+1][j+1].color)){
p.x1=ara[i][j].width;
p.y1=800-ara[i][j].height;
p.x2=ara[i+1][j].width;
p.y2=800-ara[i+1][j].height;
t=1;
}else
if((i>=1&&j<=6&&ara[i][j].color==ara[i-1][j+1].color&&ara[i][j].color==ara[i-2][j+1].color)||
(j<=4&&ara[i][j].color==ara[i][j+2].color&&ara[i][j].color==ara[i][j+3].color)||
(i<=5&&j<=6&&ara[i][j].color==ara[i+1][j+1].color&&ara[i][j].color==ara[i+2][j+1].color)||
(i>=0&&i<=6&&j<=6&&ara[i][j].color==ara[i-1][j+1].color&&ara[i][j].color==ara[i+1][j+1].color)){
p.x1=ara[i][j].width;
p.y1=800-ara[i][j].height;
p.x2=ara[i][j+1].width;
p.y2=800-ara[i][j+1].height;
t=1;
}
}
```

*Edited 6 Years Ago by Nick Evan*: Un-indented code