What you want is a function that estimates the value of a board state. This value might represent the likelyhood of the computer winning from that state. Thus, the function might return 1 for a winning state, 0 for a losing state, and 0.5 for a draw state.

For other cases, this function either needs to make an estimate using some kind of heuristic (such as the least number of moves required to win) or by trying different moves and returning the value for the best move for whoever's turn it is. Thus, if it is the opponent's turn, the function would call itself recursively for different boards that result from different moves, then return the minimum of the values returned, since the opponent would choose the move with the worst result for the computer. For boards that represent the computer's turn, the function would return the maximum of the values that result from different turns the computer could take.

Because of the alternating minimum and maximum, this is sometimes called a minimax or min-max search. Try searching google for minimax or try this link for more info and code examples:

http://ai-depot.com/LogicGames/MiniMax.html

-Seth

For other cases, this function either needs to make an estimate using some kind of heuristic (such as the least number of moves required to win) or by trying different moves and returning the value for the best move for whoever's turn it is. Thus, if it is the opponent's turn, the function would call itself recursively for different boards that result from different moves, then return the minimum of the values returned, since the opponent would choose the move with the worst result for the computer. For boards that represent the computer's turn, the function would return the maximum of the values that result from different turns the computer could take.

Because of the alternating minimum and maximum, this is sometimes called a minimax or min-max search. Try searching google for minimax or try this link for more info and code examples:

http://ai-depot.com/LogicG

-Seth