hi! i have made my very first game just last night. ^___^ it is a simple tic tac toe game that can be played by either 2 players or one against the computer. It worked fine on well... my opinion. but i really need comments and suggestions on how to improve it. tnx.
PS. in ai(), I set the value of x and y to rand() thus making the computer opponent less challenging. can this be improve? how?
It is a random position ai.
It doesn't know the best move.
You could brute force a spanning tree of the best possible move the AI can make.
(Takes a while)
But then the ai will be unbeatable if it goes first.
e.g.
if first, go to a random corner.
based on where your moves are, and enemy move is, go somewhere else.
Write out all possible locations.
Or you could make a semi-smart AI.
If x[0] && x[1] == "X", put X in x[2] (or 0) depending on his piece.
DO that or all rows/colums/diagonals, should be 20 different possibilities just for 2 in a row and blocking/finishing the 3rd.