I have a Connect 4 game almost complete.. but i'm having trouble coding the winning conditions. I know I could do it with like 50 if statements but that seems highly unreasonable.
Can any of you experienced coders help me? This is what I have so far; its extremly ugly..
Does that seem reasonable?Code:USHORT row = 0; for (USHORT i = 0; i<4; i++) { for (USHORT ii = 1; ii<5; ii++) { for (USHORT iii = 2; iii<6; iii++) { for (USHORT iiii = 3; iiii<7; iiii++) { if ((board[row][i] == board[row][ii]) && (board[row][ii] == board[row][iii]) && (board[row][iii] == board[row][iiii])) { if (player == player1) { //horizontal win; return 1; } else { //horizontal win; return 2; } } if (iiii == 6) { if (row < 6) { row++; } i = 0; ii = i++; iii = ii++; iiii = iii++; } } } } }