Advertisement
Guest User

Untitled

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