There are two classes and one interface used in each of the fully developed versions of tic tac toe. Essentially the only difference between these versions of the game is how the computer selects its move. |
Method Name | Description |
---|---|
init | Initializes variables and references used by applet. Precondition: Browser calls applet Postcondition: variables and references initialized. |
mouse_Released | Called whenever mouse released in applet area.
Precondition: Click of mouse. Postcondition: plotMove(MouseEvent) called |
plot_Move | Determines game condition and where mouse clicked and
calls various methods.
Precondition: Call from mouseReleased. Postcondition: t.computer_move() or t.human_move() called and then applet repainted. |
init_game | Initializes main variables used in game.
Precondition: Call from init() or plotMove() of t8. Postcondition: Empty board and other variables set for start of game. |
human_move | Stores human move in array.
Precondition: Call from plotMove in applet. Postcondition: Human move stored and flag set for computer to make move. |
computer_move | Calls miniMax to decide on best move and then stores move in
position array. Also displays information regarding algorithm
efficiency and calls function to check for winning state.
Precondition: Call from plotMove in applet. Postcondition: Computer's move made and flag set for human to make move. |
minimax | Searches for best move for computer.
Precondition: Call from computer_move method. Postcondition: Stores best move in bestc and bestr. |
evaluate | Returns value of possible moves.
Precondition: Call from miniMax method. Postcondition: Returns a value which indicates affect of possible move: human win, computer win, cat's game, or game not finished. |
win | Detects if a win exists and identifies its direction
Precondition: Call from computer_move() or human_move(). Postcondition: Identifies direction of win, if one exists. |
paint | Calls drawBoard and plotWin to display current game state.
Precondition: Called after init method and by plotMove() method through use of repaint() method. Postcondition: Display of game state updated. |
drawBorad | Draws grid and players in their positions.
Precondition: Call from paint(Graphics g) Postcondition: Current state of game displayed |
plotWin | Draws a line highlighting path of win.
Precondition: Called by paint(Graphics g). Only actually does anything if a winning pattern exists. Postcondition: A winning pattern is highlighted if one exists. |