Spring2006.CSCI221Homework3 History

Hide minor edits - Show changes to markup

Deleted line 0:

(:note Note: |Extended due date:)

Changed lines 132-135 from:

Here are some sample unit tests (jUnit classes) for the above design. You should read them to understand how they work.

to:

Here are sample unit tests (jUnit classes) for the above design. You should read them to understand how they work.

Changed lines 128-129 from:

Submission

to:

Unit Tests

(:note Note: |Unit tests have been posted.:)

Here are some sample unit tests (jUnit classes) for the above design. You should read them to understand how they work.

Download them and import them into your BlueJ project.

Submission

Changed lines 154-157 from:
  • A doc subdirectory with the Javadoc API documentation generated by BlueJ, for each of the classes above.
    • Unit test classes for each class above.
to:
  • A doc subdirectory with the Javadoc API documentation generated by BlueJ, for each of the classes above.
  • Unit test classes for each class above. If your program has known bugs, this would be the best way to document them (and get partial credit for the erroneous code).
Added line 1:

(:note Note: |Extended due date:)

Changed line 3 from:

Due Date: Tuesday, Feb. 21, 2006 \\

to:

Due Date: Thursday, Feb. 23, 2006 \\

Changed lines 108-110 from:

To implement the Computer player, you may use Attach:AIPlayer.class. This file encapsulates the Artificial Intelligence MinMax algorithm, for determining the computer move. For example,

to:

(:note Note: |AIPlayer.class has been updated.:)

To implement the Computer player, you may use AIPlayer.class. This file encapsulates the Artificial Intelligence MinMax algorithm, for determining the computer move. For example,

Changed lines 109-110 from:

To implement the Computer player, you may use AIPlayer.class. This file encapsulates the Artificial Intelligence MinMax algorithm, for determining the computer move. For example,

to:

To implement the Computer player, you may use Attach:AIPlayer.class. This file encapsulates the Artificial Intelligence MinMax algorithm, for determining the computer move. For example,

Changed lines 100-101 from:
 *  Input: {Provide a simple, yet complete description of the input required 
* by this class, if any.} \\
to:
 *  Input: {Provide a simple, yet complete description of the input 
* required by this class, if any.} \\
Changed lines 103-104 from:
 *  Output: {Provide a simple, yet complete description of the output generated 
* by this class, if any.} \\
to:
 *  Output: {Provide a simple, yet complete description of the output 
* generated by this class, if any.} \\
Changed lines 111-116 from:
      AIPlayer player = new AIPlayer();      // creates a computer player of perfect ability

      AIPlayer player = new AIPlayer(1.0);   // creates a computer player of perfect ability

The constructor’s ability parameter may range from 0.0 (novice) to 1.0 (expert). (Note: Actually, values outside this range are OK, however anything less than 0.0 is treated as 0.0 (how novice can you be?) and anything greater than 1.0 is treated as 1.0 (you cannot improve perfection!)).

to:
  AIPlayer player = new AIPlayer();      // creates an expert computer player

  AIPlayer player = new AIPlayer(1.0);   // creates an expert computer player

The constructor’s expertise parameter may range from 0.0 (novice) to 1.0 (expert). (Note: Actually, values outside this range are OK, however anything less than 0.0 is treated as 0.0 (how novice can you be?) and anything greater than 1.0 is treated as 1.0 (you cannot improve perfection!)).

Changed lines 119-120 from:
      player.getMove(board);  // get computer move
to:
  player.getMove(board);  // get computer move
Added lines 125-148:

Submission

  1. Open your BlueJ project.
  2. Open (edit) each source file and generate the class interface (javadoc). This can be done within the editor window either by pressing CTRL/J , or selecting the Interface drop-down menu item (on the right). (Note: This is necessary to generate your documentation for grading.)
  3. Under the Project menu, click Create Jar File... . In the dialog box that opens, select Include Source, and press Continue.
  4. Verify that the .jar file is correct, by using the 'jar xvf file.jar' command, where file.jar is your archive. Your .jar file should contain:
    • Readme.txt (see Widget for a sample).
    • Any files generated automatically by BlueJ (e.g., bluej.pkg, bluej.pkh, etc.).
    • Rules.java, HumanPlayer.java, ComputerPlayer.java, Board.java, Square.java, TicTacToe.java.
  • A doc subdirectory with the Javadoc API documentation generated by BlueJ, for each of the classes above.
    • Unit test classes for each class above.

In other words, I should be able to unzip your submission and run it without modifications or additions.

Email the generated .jar file to manaris@cs.cofc.edu, by the due date and time.

Changed line 57 from:
  • public Board() - builds a board of nine squares
to:
  • public Board() - builds a board of nine squares (numbered 0..8)
Added lines 107-124:

Computer Player

To implement the Computer player, you may use AIPlayer.class. This file encapsulates the Artificial Intelligence MinMax algorithm, for determining the computer move. For example,

      AIPlayer player = new AIPlayer();      // creates a computer player of perfect ability

      AIPlayer player = new AIPlayer(1.0);   // creates a computer player of perfect ability

The constructor’s ability parameter may range from 0.0 (novice) to 1.0 (expert). (Note: Actually, values outside this range are OK, however anything less than 0.0 is treated as 0.0 (how novice can you be?) and anything greater than 1.0 is treated as 1.0 (you cannot improve perfection!)).

To get player to calculate a move for you, do:

      player.getMove(board);  // get computer move

This is a void method, which updates its Board argument with the player’s move (player always plays ‘O’). It outputs informational messages to System.err.

Note: AIPlayer is not in the public domain. It is made available under a Creative Commons License.

Changed line 127 from:
  1. Cooper, D. and Clancy, M. (1985) “Oh! Pascal”, 2nd ed., W.W. Norton & Company, New York, p. 42.
to:
  1. Cooper, D. and Clancy, M. (1985) “Oh! Pascal”, 2nd ed., W.W. Norton & Company, New York, p. 42.
Added lines 1-74:

Assigned Date: Tuesday, Feb. 7, 2006
Due Date: Tuesday, Feb. 21, 2006
Due Time: 11:55pm

Last modified on April 03, 2015, at 11:59 AM (see updates)

Purpose

This assignment focuses on Object-Oriented programming. You are expected to work in isolation (without access to any resources other than the class textbook, class notes, and the instructor).

Assignment

Implement a game of Tic-Tac-Toe. In our version of the game, two players, human and computer, play in turns, placing X's and O's, respectively, on the 3x3 square board. The human player always goes first. The game goes on until either there is a winner (3 X's or 3 O's in a vertical, horizontal, or diagonal line), or the game is a draw (all squares are occupied and no one has won).

The program should display the current board configuration after each move, e.g.,

        |   |
      X |   |
     ---+---+---
      O |   |
     ---+---+---
      X | O |
        |   |

and prompt the user to enter a move (a number from 1 to 9). The human player always goes first. Squares are numbered consecutively, from 1 to 9, where 2 is the middle square in the top row. The program should be as robust as possible. When the game is over it should output a message describing the outcome.

Design

You should implement the following design. Do NOT make any modifications without checking with the instructor. Create a project called, TicTacToe. In that project implement the following classes:

  • Rules – encapsulates all rules of the game
    • public Rules()
    • public boolean isGameOver(Board board) - checks if the game is over
    • public boolean isWin(Board board) - checks if we have a winner
    • public boolean isDraw(Board board) - checks if we have a draw
    • public boolean isValid(int move, Board board) - checks if the proposed move is valid (it does not make the move)
  • Player – abstract class modeling a generic player
    • public Player()
    • abstract public void makeMove(Board board, Rules rules)
  • HumanPlayer extends Player -- encapsulates the human player
    • public HumanPlayer()
    • public void makeMove(Board board, Rules rules) - asks the end-user for a move and, if valid, puts it on the board
  • ComputerPlayer extends Player – encapsulates the computer player
    • public ComputerPlayer()
    • public void makeMove(Board board, Rules rules) - uses artificial intelligence techniques to make a valid move (this functionality will be provided)
  • Board – encapsulates the game board
    • public Board() - builds a board of nine squares
    • public Board(int numOfSquares) - builds a board of numOfSquares squares
    • public void clear() – initializes the board to empty squares
    • public char getSquare(int position)
    • public void setSquare(int position, char value)
    • public String toString() - returns a printable representation of the board
  • Square
    • public Square()
    • public char getValue()
    • public void setValue(char value)
    • public String toString() -- returns a printable representation of the square
  • TicTacToe – the system driver
    • public static void main(String[] args) - declares instances of above classes and uses their methods to implement the game.
Changed lines 79-82 from:

Your comments should be in the javadoc style. Also see the departmental style standard.

You should always include opening comments that state the author of the file, the date, documentation of resources used to write the code, and comments related to the code and its functionality. This semester your opening comment section for every source file you submit should have the following format.

to:

Obviously, you should comment any variable, obscure statement, block of code, method, and class you create. Your comments should express what is being done and/or why something is being done, as opposed to how – the how is shown by the code. (Also see the departmental style standard).

Every source file should always include opening comments that state the author of the file, the date, documentation of resources used to write the code, and comments related to the code and its functionality. This semester your opening comment section for every source file you submit should have the following format.

Added lines 107-109:

Reference

  1. Cooper, D. and Clancy, M. (1985) “Oh! Pascal”, 2nd ed., W.W. Norton & Company, New York, p. 42.
Added lines 1-32: