Basically I'm currently trying to make a reversi game for Android and my if statements are causing me a bit of a headache, it seems if conditions are right for more than one it's only going through the motions on one of the statements and just leaving the other one. My code looks like:
if (check[position] == 0
&& (check[position - 8] == 2
|| check[position + 8] == 2
|| check[position + 1] == 2
|| check[position - 1] == 2
|| check[position - 9] == 2
|| check[position + 9] == 2
|| check[position - 7] == 2 || check[position + 7] == 2)) {
if (check[position + 8] == 2) {
for (int i = position; i < 56; i += 8) {
if (check[i] == 1) {
for (int j = position; j < i; j += 8) {
check[j] = 1;
}
playerno = 2;
break;
} else
break;
}
} else if (check[position - 8] == 2) {
for (int i = position; i > 8; i -= 8) {
if (check[i] == 1) {
for (int j = position; j > i; j -= 8) {
check[j] = 1;
}
playerno = 2;
break;
} else
break;
}
} else if (check[position + 1] == 2) {
for (int i = position; i < board.length; i++) {
if (check[i] == 1) {
for (int j = position; j < i; j++) {
check[j] = 1;
}
playerno = 2;
break;
}
if (i == 7 || i == 15 || i == 23 || i == 31
|| i == 39 || i == 47 || i == 55
|| i == 63) {
break;
}
}
} else if (check[position - 1] == 2) {
for (int i = position; i > 0; i--) {
if (check[i] == 1) {
for (int j = position; j > i; j--) {
check[j] = 1;
}
playerno = 2;
break;
}
if (i == 0 || i == 8 || i == 16 || i == 24
|| i == 32 || i == 40 || i == 48
|| i == 56) {
break;
}
}
}
Check is just an int array that notes what player holds that particular piece on the board Now for some reason if I have a position that satisfies two of these conditions it only goes through one of the if statements and more often than not this yields the game treating it as an invalid move, I was wondering how I can get around that?