xterm wroteHi Nader,
There's a much simpler way (which reduces your code alot) to check whether someone won.
You have a 3x3 grid with 8 possible ways of winning. We mark each cell in the grid with 2^[index] and thus we will have:
1 2 4
8 16 32
64 128 256
The winning combination are:
1 + 2 + 4 = 7
8 + 16 + 32 = 56
1 + 8 + 64 = 73
4 + 16 + 64 = 84
2 + 16 + 128 = 146
1 + 16 + 256 = 273
4 + 32 + 256 = 292
64 + 128 + 256 = 448
Thus the winning array is: int win[8] = {7,56,73,84,146,273,292,448}
Everytime X makes a move, add the value in the grid to an xcounter
Everytime Y makes a move, add the value in the grid to an ocounter
Everytime a move takes place check for every entry in the win array, whether xcounter & entry == entry
If so, X won.
Hey Xterm
well infact that is a more complicated way with calculations( 0.001% delay =P ) , since i just used a Player Enum that is either a Human or Bot , so i just check those in a row/column of any size , and that is more creative to check the winning entity, human or bot, well but @ the end i believe that each or every bunch of coders have their own style ;)
Note: Updated score bug and a repaint bug when PC wins it paints out the cross -line for sure.