A7: Tic-Tac-Toe

On This Page


Overview

During this assignment, you will:

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

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. Program start

  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. Another move

  6. Play continues alternating between the two players until one of them wins.
  7. The winner

Required Methods

You must code the following methods, though you may add more.

/**
 * Returns a String that will display the current board.
 *
 * @param board The game board.
 * @return A display of the current board
 */
public static String getDisplay(char[] board)

/**
 * 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.
 */
public static 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.
 */
public static boolean checkWinner(char[] board)

Hint: to convert the String player to a char, use player.chatAt(0).

Additional Specifications

  1. The name of the program source code file must be TicTacToeApp.java.
  2. Whenever the user presses the Cancel button, the program exits.
  3. Cancel message

  4. Your program must catch and handle all error conditions including incorrect or invalid moves.
  5. Error checking message

  6. You may use magic numbers for array indexes for this assignment.
  7. Do not use packages statements

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 "0" and have the computer generate the next move automatically. (1 point)
  3. Improve the display of the tic-tac-toe board using HTML tags. For example: (1 point)
  4. Extra credit HTML formatting

    Hint: A JOptionPane understands some HTML tags. For example, to display the text red dog using the color red you would use a String like:

    String s = "<html><font color=\"red\">red dog</font></html>\n";

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. All of your source code (.java files)
  3. Any other source code needed to make your program function.

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 | Schedule | Expectations | Course info
Help | FAQ's | HowTo's | Links

Last Updated: November 11 2004 @15:17:57