A7: Tic-Tac-Toe

On This Page


Overview

During this assignment, you will:

  • Program the game tic-tac-toe
  • Pass arrays as arguments to functions

Specifications

Write a program that allows two users to play tic-tac-toe that operates like this:

  1. The program first displays a board as follows and prompts user X for a move.
  2. 1 2 3
    4 5 6
    7 8 9
    Please enter your move using
    the number of the square or -1 to exit
    
    Player X's move: 1
    
  3. Players enter their move by entering the position number they wish to mark.
  4. After each move, the program displays the changed board and prompts the next player to move.
  5. X 2 3
    4 5 6
    7 8 9
    Please enter your move using
    the number of the square or -1 to exit
    
    Player O's move: 2
    
  6. Play continues alternating between the two players until one of them wins.
  7. X O 3
    X O 6
    X 8 9
    Player X wins!
    

Required Functions

You must code the following functions exactly as specified, though you may add more.

/**
 * Displays the current board.
 *
 * @param board The game board.
 * @param length The number of elements in the game board.
 */
void displayBoard(char board[], const int length);

/**
 * Prompts for a move and makes the move if valid.
 * Otherwise, posts an error message and asks the
 * user to enter a correct move.
 *
 * @param board The game board.
 * @param prompt Message to display to the user.
 * @param player Name of the player.
 */
void makeMove(char board[], string prompt, string player);

/**
 * Checks to see if the game has a winner.
 *
 * @param board The game board.
 * @return true if a winner was found, otherwise false.
 */
bool checkWinner(char board[]);

Hints:

  1. To convert the string player to a char, use player.at(0).
  2. To exit your program , you can call: exit(0)

Additional Specifications

  1. The name of the program source code file must be tictactoe.cpp.
  2. Whenever the user enters -1, the program exits.
  3. Player X's move: -1
    You entered a negative number.
    Good bye!
    
  4. Your program must catch and handle invlaid moves.
  5. Player X's move: 10
    Invalid move!
    Please enter your move using
    the number of the square or -1 to exit
    
    Player X's move:
    
  6. You may use magic numbers for array indexes for this assignment.
  7. Do not forget to document your code.

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming. (1 point)
  2. Add an option that allows either player to enter a zero ('0') and have the computer generate the next move automatically. (1 point)
  3. Add an option that allows either player to enter a "c", instead of a number, and have the computer generate the next move automatically. (2 points)

Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course Syllabus.

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 2: Source code compiles with warnings
  • 0: Does not compile or wrong file turned in

Functionality

  • 10: Demonstrates mastery of the assignment
    • Has extra features or demonstrates techniques beyond the assignment
    • Applies concepts from the lesson(s) appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • No errors encountered during operation
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Meets all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
  • 2: Serious functional problems but shows some effort and understanding
    • Meets less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 0: Does not execute or no specifications met

Code Documentation

  • 4: Code is well-documented
  • 3: Code has minor documentation errors
    • Has 1 documentation error
  • 2: Code has some documentation errors
    • Has 2-3 documentation errors
  • 1: Code has many documentation errors
    • Has more than 3 documentation errors
  • 0: No apparent attempt to document code

REAME.txt File

  • 2: README.txt file submitted with specified information included
  • 1: README.txt submitted but some information was not included
  • 0: No README.txt submitted

Maximum Score: 20, plus extra credit

What to Turn In

Submit your assignment following the instructions for homework. Include the following items for grading:

  1. README.txt file
  2. tictactoe.cpp

You must submit all the files needed to make your assignment function properly. Do not assume that the instructors has any files unless explicitly stated by the instructor. Your assignment must work as submitted.

Home | WebCT | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links

Last Updated: November 11 2004 @16:16:45