Runs beautifully 4 me
-
but for 1 single exception...
When it is searching for a solution, especially when there is NO solution, then it goes into an infinite loop, .
(which finally crashes my sys ( after about 1 minute)
It displays the grid, and the "X" & "O" char's correctly
I had the tree corners covered ( (1,1), (1,3), (3,1)
The program did not actually show my last move on the screen, but I could see that it was searching for the next available move
- reminded me of the 1985 film "War Games" where the computer began trying-out all possibilities.
This can be seen by adding this line as the first line of the computerMove() subrt'n:
|
getchar(); // #include <stdio.h>
|
Because you only have 11 possible positions in the grid, then I suggest that you store all 11 values in a 1-d array (vector)
1-9, + all , + none = 11.
You could also keep a counter ( i_cntr = 1, i_cntr <11, i_cntr++)
since only (about) 11 total moves are allowed, but an Array[11] would be cleaner.
1 2
|
else
computerMove(row,col);
|
Also, rather than calling recursively computerMove(), you might, rather, try placing this subrt'n into a WHILE loop. That way it can run for a longtime without overflowing the stack.
Lastly, when you have it De-Bugged, then PLEASE think about trying to consolidate your code - especially the checkComp, and the checkPlayer subrt'ns which can be condensed into about 2-3 lines.