adamwiggins (owner)

Revisions

gist: 26390 Download_button fork
public
Public Clone URL: git://gist.github.com/26390.git
Embed All Files: show embed
tictactoe.m #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- (bool)someoneWon {
   // horizontal
   for (int x = 0; x < 3; x++)
   {
      if (spots[x][0] != ' ' && spots[x][0] == spots[x][1] && spots[x][1] == spots[x][2])
         return spots[x][0];
   }
 
   // vertical
   for (int y = 0; y < 3; y++)
   {
      if (spots[0][y] != ' ' && spots[0][y] == spots[1][y] && spots[1][y] == spots[2][y])
         return spots[0][y];
   }
 
   // diagonal
   if (spots[0][0] != ' ' && spots[0][0] == spots[1][1] && spots[1][1] == spots[2][2])
      return spots[0][0];
   if (spots[0][2] != ' ' && spots[0][2] == spots[1][1] && spots[1][1] == spots[2][0])
      return spots[0][2];
 
   return ' ';
}