Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Return value of TRUE indicates winning move.
- bool checkWin(const unsigned int x, const unsigned int y, const TYPE table[3][3]) {
- if (table[0][y] == table[1][y] == table[2][y] || table[x][0] == table[x][1] == table[x][2])
- return TRUE; // Row or column win.
- if (x == y || abs(x - y) == 2) { // Is this move able to make a diagonal win?
- if (x != 1 && table[x][y] == table[1][1] == (x != y ? table[y][x] : table[abs(x - 2)][abs(y - 2)]))
- return TRUE; // Not center box, but completed a diagonal.
- else if (x == 1 && (table[x][y] == table[0][0] == table[2][2] || table[x][y] == table[2][0] == table[0][2]))
- return TRUE; // Center box, completed a diagonal.
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement