YCP Logo Assignment 1 - Tic Tac Toe

Due: Friday, September 10th, by 11:59 PM

Getting Started

Download CS201_Assign1.zip and import it into your Eclipse workspace (File->Import->General->Existing projects into workspace->Archive file.)

You should see a project called CS201_Assign1 in the Package Explorer.

Your Task

In this assignment, you will write a program to allow two players to play a game of Tic Tac Toe.

Example Session

Here is an example session (user input in bold):

Player X's turn
   |   |
-----------
   |   |
-----------
   |   |
Row? [0-2] 1
Col? [0-2] 1

Player O's turn
   |   |
-----------
   | X |
-----------
   |   |
Row? [0-2] 0
Col? [0-2] 0

Player X's turn
 O |   |
-----------
   | X |
-----------
   |   |
Row? [0-2] 0
Col? [0-2] 1

Player O's turn
 O | X |
-----------
   | X |
-----------
   |   |
Row? [0-2] 1
Col? [0-2] 2

Player X's turn
 O | X |
-----------
   | X | O
-----------
   |   |
Row? [0-2] 2
Col? [0-2] 1

 O | X |
-----------
   | X | O
-----------
   | X |
Player X wins!

Requirements

At the beginning of each turn, the program should print out a representation of the game board using text characters.

The program should check each row and column value entered to make sure that they are within bounds. It should also reject attempts to place a piece on a square where there is already a piece. If the user enters an invalid move, the program should prompt them to enter a different move.

The program should detect when the game is over. If one of the players has won by placing three pieces in a row, the program should print a message indicating which player won. If the game ended in a draw, the program should indicate that.

Hints

Use a Scanner object to get input from the user. You can use the nextInt() method to read an integer value.

You should consider using an array to represent the board. Here is how you can declare a one-dimensional array:

int[] board = new int[9];

Here is how you can declare a two-dimensional array:

int[][] board = new int[3][3];

Arrays in Java can be passed to methods by reference. This is similar to C.

Grading

The grading criteria are as follows:

  • For a grade of up to 75, implement the above features, but without any validation of user input
  • For a grade of up to 80, implement the above features with input validation
  • For a grade of up to 90, use static methods to perform operations such as checking to see if a move is legal, checking to see if the game has been won, etc.
  • For a grade of up to 100, allow the user to play against a computer opponent

There is one insane extra credit option (for a grade of up to 150) if you're feeling ambitious: implement a graphical user interface. It should display the board graphically, and allow pieces to be placed using the mouse, and support the other features as described above.

Submitting

Export your finished program to a zip file (right-click on the project, then Export...->Archive File). Upload the zip file to the marmoset server as project assign1. The server URL is

https://camel.ycp.edu:8443/

IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.