Hey, this program is a game where you try to beat CPU at a Tic Tac Toe game. Everything is compiling, but there seems to be a problem because the turn never goes to CPU, instead the program keeps outputting Player 1's turn. Any suggestions?
Sorry btw if the code is a little too long, I'm still in the process of simplifying it.
When CPUMove is run, it does the checks on the board and returns the value at an index position of box, in which case it would return the character code of either 1, 2, 3, 4, 5, 6, 7, 8, 9
For example, I took my move, set a breakpoint after the CPUMove call and this was the contents of your variables...
CPUmove returned 51 int
choice 51 int
mark 88 'X' char
player 2 int
Shouldn't you be returning the position number and not the contents at that position?
The program compiles but it bugs out after around 5 moves, I can't seem to figure out what the problem is. Could you guys do me a huge favor and give it a few runs to see what's going on?
If I were to put my first move in 2 (X), then computer puts in 1 (0) then I put my 2nd move in 3(X), the CPUMove() function will see 2 and 3 are the same and attempt to put O in position 1 regardless if its taken or not.
Just try making your first move on 2, then 3, computer will see 2 and 3 filled regardless of which player put them there and try to put X in position 1 which was filled by player 2 (CPU).
i would point out many flaws but the codes to ugly...
@TheGentlmen Was that even necessary? - everyone starts somewhere, and its all part of the learning process! - What is important is he knows this and is working on it...
fizanimtiaz93 wrote:
Sorry btw if the code is a little too long, I'm still in the process of simplifying it.