Assignment |
A3: Tic Tac Toe Game |
---|---|
Due Date | Tuesday, July 19, 2005 @ 4:00pm (CSL time) |
Last Mod Date |
|
Links |
Objectives | Description | Class Specification | Testing | Generating Documentation | Javadocs | Requirements | Questions | Hints | Handin |
In this assignment, you are going to design, code, and test a program that implements the Tic Tac Toe Game. Tic Tac Toe is a game that requires two players who alternately place X's and O's upon a 3x3 playing board as shown in Figure 1 below. Players alternate roles in placing their marks in any unoccupied box (cell) on the board. The first player to complete three of its marks in (1) a horizontal row, (2) a vertical column, or (3) in either of the two cross diagonals wins the game.
Your assignment is to write a program that allows (1) a human to play against the computer, or (2) a human to play against another human. The program MUST allow users to choose between these two options. The following describes the requirements of each option.
Option (1) (human vs. computer):
Option (2) (human vs. human):
The board boxes will be numbered from 1 to 9 as shown in Figure 2 below. Each players MUST select its unoccupied box by entering the number that corresponds to that box.
The game MUST end when (1) all the boxes are marked, or (2) one of the players wins. When the game ends, the program MUST print out the outcome of the game. After every move the program MUST print the board with all the marks up to that point. Your program MUST also prevent players from choosing wrong boxes. That is, if a human player selects a box that is already marked, the program MUST re-prompt the human player to renter a valid box number. Similarly, your program MUST prevent human players from choosing wrong options and wrong marks. The program MUST continue prompting the human player to enter a valid entry so long as the entry is wrong.
The program outcome MUST look like the following:
The program MUST have two classes: TicTacToeMain.java and Board.java. The TicTacToeMain.java class will contain the main method of the program. It is in this class where all user input and interaction with the program is handled. The Board class is an instantiated class which maintains the state of the board, keeps track of the marks used by players, allows marks to be placed on the board, allows the computer to select its smart move, and checks for end of game. In the following, we provide detailed description of both classes.
sy1 and sy2 are the marks chosen from (X or O) to be used by computer and player 1 (option 1), or player 1 and player 2 (option 2) respectively.
This method places the mark sy into the box number boxNum in the board and then displays the board. Refer to sample of the outcome above for output formatting. The method must return False without doing anything if the box numbered boxNum is already occupied. Otherwise it returns True.
This method selects a unoccupied box using the Selection Algorithm given below and then returns the number of the selected box.
Selection Algorithm Given the board with its marked boxes, the algorithm selects a box for the computer to place its mark as follows.
|
This method checks whether the game ends. The game ends when the board is all marked, or one player wins. This method will be called by the main method of the TicTacToeMain class after each move to check for the end of game. The method MUST return an integer which indicates the status of the game when it ends. This returned value will be used by the main method to display information accordingly.
This class contains the main method. It prompts the user for entering the number of players (option 1 or 2), the symbols to be used by the players, creates a Board object. The Board object will be used through its methods to maintain the board, make the moves, and check of end of games. The main method also should contain code that allows players to alternately enter their selected boxes.
In this assignment you will be generating documentation for the Board class from the Javadoc comments that you
wrote. The following are instructions for using Eclipse to generate
the Javadoc web pages.
Make sure you write comments in proper Javadoc format for all of
your methods before doing this step.
Select the "Project" menu item in the Menu bar. From the "Project" menu select "Generate Javadoc..". A dialog window should appear. If it doesn't, try the "File" menu to the "Export" menu item and select the javadoc icon.
Enter S:\java\bin\javadoc.exe in the field labeled "Javadoc command".
Make sure the "Public" radio button is selected. Make sure the files you are generating documentation for are selected. You may have to click on the + box next to your project name to expand the listing and see all the files so that you can make sure they are all selected. Note the location in which the documentation will be generated; it's the field labeled "Destination" in the dialog window. Press the "Finish" button and the documentation should be generated.
You can use any web browser to view the documentation you create. Most web browsers have an "Open File" menu item. Select this item and navigate to the location you noted in the "Destination" field of the "Generate Javadoc" dialog window. There will be many files at this location; select the file index.html. You will see a page much like the Java API pages, but the classes listed will be the ones you have written. You can click on the links and look at the documentation for your individual classes. If you select one of the files named after one of your classes, say Board.html, you will see only the documentation for that class.
Documentation for Java source code is almost always provided in a special javadoc format. This documentation is automatically generated from the source code comments, which MUST follow a special format.
We will be using classes from the Java API in every assignment. The documentation for every class in the Java API can be found at http://java.sun.com/j2se/1.5.0/docs/api.
This section outlines the major requirements of the assignment. Your solution to the assignment MUST meet each of these requirements. Be sure to read the announcements frequently and ask questions if you need clarification.
This section lists several questions that should deepen your understanding of the assignment. Create a text-only file named questions.txt and answer these questions.
Be sure to include the descriptive information listed below as well as the answers to each question.
Assignment Number:
Assignment Name:
Date Completed:
Partner 1 Name:
Partner 1 Login:
Partner 1 TA:
Partner 2 Name:
Partner 2 Login:
Partner 2 TA:
Use the Handin
program to hand in your work.
Students working in pairs will only submit one copy of all program
files, except the README file described below.
All students working in pairs MUST read the Pair Programming Document and submit a README file. Each student working in a pair, MUST handin this file to their own handin directory. Copy, complete and handin the file that is linked here.
Feedback,
questions or accessibility issues.
Copyright: Bechir Hamdaoui and Suresh Sridharan @copy;2005 All
rights reserved.
Based on Programming Project 7.2 in "Java Concepts (4th edition)" by
Cay Horstmann, John Wiley & Sons, Inc. 2005.
Latest update: