Hello, I've been working on basic A.I. algorithms in C++ over the last week and I've hit a wall. I've written a basic hard-coded logic FSM TicTacToe game and I then attempted to implimented a Minimax algorithm using the information provided in the following post:

http://www.gamedev.net/topic/562118-minimax-for-tic-tac-toe/

I've created an implimentation based upon what I believe to be correct and I'm getting odd results. The algorithm seems to select the correct move after two incorrect moves. Can anyone see where I've gone wrong? Any help would be greatly appreciated.

Note: The grid is an array[3][3], with 0,0 being top left.

http://pastebin.com/PV8eM1rz

I could not work out the correct way to format code so I've put it in a pastebin link. I hope this is okay.

Thanks again