However, when I play first I always win when I start at position 0. An example play is below based on me playing first and my marker being O.
O X 2
X X O
O O 8
So, it has blocked me up until this point and tried to win itself. Now it is the computers choice but rather than play position 8 to stop me winning it goes with position 2 allowing me to play position 8 and steal a sweet victory. Up until the final two places left on the board it behaves as it should, blocking me and trying to win. So it is working to a degree just not when this situation occurs.
I've tried debugging and stepping through but if I'm honest it's kinda hard to follow exactly what is going on with it all.
Just wondering if anyone can spot a silly error or suggest how I can solve this bug. Like I said when the computer plays first it works correctly with no bugs.
int evaluateAI(GameBoard &TicTacToe, int Player, int &bestMove ){ int bestScore; int score; #define WIN 1; #define LOSS -1; #define DRAW 0; if(!TicTacToe.gameOver()) { return DRAW; } else if(TicTacToe.checkWinningLine(players[Player].getMarker())) { return WIN; } else if(TicTacToe.checkWinningLine(players[1 - Player].getMarker())) { return LOSS; } else { bestScore = LOSS; int notUsed; for(int row = 0; row < 3; row++) { for(int col = 0; col < 3; col++) { if(TicTacToe.getBoard(row, col) == '\0') { TicTacToe.setBoard(row, col, players[Player].getMarker()); score = -evaluateAI(TicTacToe, 1 - Player, notUsed); if(score > bestScore) { bestMove = TicTacToe.convertIndex(row, col); bestScore = score; } TicTacToe.unsetBoard(row, col); } } } } return bestScore;}