Hi. I'm a C++ noob. One of the first programs that I made is a tic-tac-toe game complete with an AI and 2-player modes. I am curious if there is a better way to do this. would like to hear your comments, thoughts and suggestions.
There are several large switch and if statements here, but they are actually quite simple. The ones in two player mode just check if the move is valid or not. The statements related to the CPU are described below:
First, the CPU checks if the first move was in the middle. If it was, then it chooses a random place to go, discluding the middle. If the first move was not the middle, then the computer goes to the middle. In any other case, the CPU checks if there is a winning move on the players behalf, and tries to block it. After the CPU checks for that, it checks if it has a winning case, and then goes to the position that would make it win. The last case is if there are no winning or losing moves and it's not the first move, the CPU just keeps guessing random positions until it gets a valid one.
Thanks for your help.
-Static
http://www.mediafire.com/?2odmznykbom
Sorry, It's too large to post, so you'll have to download it from mediafire. That's one reason I would like to know if there is a better way to do it (1115 lines of code).