Purpose: This document specifies the design of a tic-tac-toe playing program. It is written as an example of how to write a design document. Assumptions: 1. The program will be played by a single user, playing against the computer. 2. The input will be via the keyboard, and the output will be on the console. Rules of tic-tac-toe: Tic-tac-toe is played on a 3x3 grid consisting of 9 cells. The cells are initially empty. Players take turns placing Xs (one player) and Os (the other player) until either the board is full, in which case the game is a draw, or until one player has placed three Xs or Os in a row, either horizontally, vertically, or diagonally. Data: 1. board - The tic-tac-toe board - represented as a 3x3 array of integers - 0 represents an empty cell, 1 represents the users move, and -1 represents the computer's move. 2. move - A tic-tac-toe move - represented as an (x,y, w) triple - x and y represent the location of the move in the array, and w is either 1 for the user or -1 for the computer, depending on whose move this is. 3. turn - Whose turn it is to play - represented as an integer - either 1 or -1 depending upon whether it is the user's turn or the computer's turn Operations: 1. clear_board(board) - Description: a function that sets the board to the initial state, all 0s. - Input: a board - Output: nothing - result: the board is cleared to 0s 2. display_board(board) - Description: A function that displays the board on the console - Input: the board - Output: nothing - result: the board is displayed on the console 3. move get_user_move() - Description: a function that gets a move from the user - Input: nothing - Output: a move - result: one move has been gotten from the user 4. move get_computer_move(board) - Description: a function that computes the computer's move - Input: the board - Output: a move - result: the computer has made one move 5. void do_move(board, move) - Description: a function that updates the board to reflect the move that it is passed - Input: the board, a move - Output: nothing - Result: The board has been changed to reflect the move 6. integer check_winner(board) - Description: Checks to see if anyone won the game - Input: the board - Output: 1, 0, or -1 depending on whether the user, nobody, or the computer won the game - Result: a winner (if present) is determined 7. boolean check_full(board) - Description: Checks to see if the board is full - Input: The board - Output: true or false depending on whether or not the board is full - Result: the fullness of the board has been checked Algorithms: Tic-Tac-Toe Game algorithm: 1. Clear the board. 2. Print out the rules of the game and instructions for playing the game. 3. Ask the user who should go first, the user or the computer 4. Input the response and set turn to the appropriate value 5. While check_full(board) = false and check_winner(board) = 0 6. display_board(board) 7. If turn = 1 8. move := get_user_move(board) 9. Otherwise 10. move := get_computer_move(board) 11. do_move(board, move) 12. Swap turn 13. End while 14. Print out the value of check_winner, either user, computer, or draw, depending on whether check_winner(board) returns 1, -1, or 0. Algorithm for get_computer_move(): 1. If there is a move that would give the computer three in a row, return that move. 2. Otherwise, if the user has two in a row, return the move that the user would play to get three in a row. 3. Otherwise, if there is a move that would give the user two sets of two in a row, return that move. 4. Otherwise, if the center cell is open, return that move. 5. Otherwise, if there is a move that would give the computer two in a row, return that move. 6. Otherwise, if a corner cell is open, return that move. 7. Otherwise, play in any other cell. Algorithm for check_winner(): 1. For each possible three in a row 2. Add the three values 3. If the sum is 3 // the user has won 4. return 1 5 If the sum is -3 // the computer has won 6. return -1 7. End for 8. return 0 // nobody has won Algorithm for do_move(board, move) 1. board[move.x][move.y] := move.w I think you get the idea. clear_board, display_board, get_user_move, check_full and print_board are trivially obvious and are not described in this document. However, a good design document would describe them.