fix logic: combine tiles on the right side

This commit is contained in:
Aaron Bulmahn 2014-04-17 21:46:34 +02:00
parent 2c472777f4
commit f25b57e018
2 changed files with 56 additions and 4 deletions

View File

@ -61,7 +61,7 @@ char *file;
/* Merges adjacent squares of the same value together in a certain direction */
void merge(int d)
{
if (d == DL || d == DR) {
if (d == DL) {
int i, j;
for (i = 0; i < SZ; i++) {
for (j = 0; j < SZ; j++) {
@ -74,7 +74,7 @@ void merge(int d)
}
}
}
else {
else if (d == DU) {
int i, j;
for (i = 0; i < SZ; i++) {
for (j = 0; j < SZ; j++) {
@ -87,6 +87,32 @@ void merge(int d)
}
}
}
else if (d == DR) {
int i, j;
for (i = SZ - 1; i >= 0; i--) {
for (j = SZ - 1; j >= 0; j--) {
if (j > 0 && g[i][j] && g[i][j] == g[i][j - 1]) {
g[i][j] <<= 1;
sl += g[i][j];
s += g[i][j];
g[i][j-- - 1] = 0;
}
}
}
}
else if (d == DD) {
int i, j;
for (i = SZ - 1; i >= 0; i--) {
for (j = SZ - 1; j >= 0; j--) {
if (j > 0 && g[j][i] && g[j][i] == g[j - 1][i]) {
g[j][i] <<= 1;
sl += g[j][i];
s += g[j][i];
g[j-- - 1][i] = 0;
}
}
}
}
}

View File

@ -61,7 +61,7 @@ char *file;
/* Merges adjacent squares of the same value together in a certain direction */
void merge(int d)
{
if (d == DL || d == DR) {
if (d == DL) {
int i, j;
for (i = 0; i < SZ; i++) {
for (j = 0; j < SZ; j++) {
@ -74,7 +74,7 @@ void merge(int d)
}
}
}
else {
else if (d == DU) {
int i, j;
for (i = 0; i < SZ; i++) {
for (j = 0; j < SZ; j++) {
@ -87,6 +87,32 @@ void merge(int d)
}
}
}
else if (d == DR) {
int i, j;
for (i = SZ - 1; i >= 0; i--) {
for (j = SZ - 1; j >= 0; j--) {
if (j > 0 && g[i][j] && g[i][j] == g[i][j - 1]) {
g[i][j] <<= 1;
sl += g[i][j];
s += g[i][j];
g[i][j-- - 1] = 0;
}
}
}
}
else if (d == DD) {
int i, j;
for (i = SZ - 1; i >= 0; i--) {
for (j = SZ - 1; j >= 0; j--) {
if (j > 0 && g[j][i] && g[j][i] == g[j - 1][i]) {
g[j][i] <<= 1;
sl += g[j][i];
s += g[j][i];
g[j-- - 1][i] = 0;
}
}
}
}
}