Sunday, November 13, 2011

How would I wirte a code for a TIc Tac Toe game in Java using Minimax algorithm?

As it says in the Wikipedia entry, this is a recursive algorithm, so we will probably be using a recursive function. We will need some sort of data structure to represent the game board, a 3x3 array is the most intuitive. First thing you'll do in your recursive function is to test the board to see if it is in a terminal state (i.e. player wins, computer wins, or a tie game) and return the appropriate value (e.g. computer wins = 1, player wins = -1, tie = 0). If the board is not in a terminal state then you would return the sum of the values of all possible moves, that is, you would call the function within itself and sum its return values.

No comments:

Post a Comment