Assignment 1

Socks and Toes

(OK its: Sockets and Tic Tac Toe)

Due Date: Thursday, September 15, 2005, at 11:59 pm

For this assignment, you are to create a two player-two process tic-tac-toe game using sockets for communication between the two players. You are to write two programs, one for the server (with the executable file named ttts) and one for the client (with the executable file named tttc).

The server program is to take an optional command line argument, which is the post that is to be used. If no port value is specified, your program is to find some available port and use that port for the connection socket. Before the server program starts listening for a connection, it must display the machine name it is running on and the port it is using.

The client program is to be given the port number that it connect to the server and it is to take an optional command line argument of a machine name that specifies the machine the server is running on. This optional command line argument is to be specified by the flag of -m. If no machine name is give assume the server is running on the same machine as the client.

The input and output of the program may be text based. Since there are nine positions on the tic-tac-toe board, a move by a player is indicated by entering the value from 1 through 9 as follows:
 
 

1 2 3
4 5 6
7 8 9

The object of the game is to get three places in a row either horizontally, vertically or diagonally. Traditionally, the first player uses an X to mark their moves and the second player uses an O to mark their moves. For the first round, the server goes first. After each game, both players are asked if they want to play again. If both players respond "yes", another game is played. After the first game, which ever player lost the previous game goes first. If the previous game ended in a tie (sometimes called "cats"), the player that went second in the previous game goes first in the current game.

For a players turn, they enter in the values from 1-9 to indicate a move. If the position is already taken, give an error message and allow the player to make another choice. If the player's move gets three in a row, the program should announce the winner immediately. The ninth move of a game should be made automatically (since there is only one position where the move could go). During the player's turn, the player could enter in a "h" or "?" to get some help on the game. This help should list basics of the game and the table that shows the correspondence between the playing board positions and the values 1 through 9. During the player's turn, the player may concede the game (admit they have lost) by entering a "c". During the player's turn, the player may quit the game and the program by entering a "q". If this happens, your program is to prompt to see if the player really wants to quit.

While a player is waiting for the other player to take their turn, the program should print a message such as:

     Waiting for the other player's turn......

Where a new period gets printed at some regular interval (i.e. every 5 seconds). The use of a timeout will help with this.

For 10 points extra credit, you may create a GUI for this program. This GUI should allow for same functionallity as specified above.

Your program should "gracefully" exit after if the other end of the socket exits.

Your program is to be submitted electronically via the turnin command on the LINUX machines. The project name for this is mp1. All programs are expected to be written in good programming style using the java programming language.

How to turn in your work

Turnin your program electronically using the "turnin" command from your CS account as follows:

turnin -c cs441 -p mp1  [your project directory]
where the [your project directory] is the directory name under which you have all your files related to this programming problem. The turnin command will automatically compress the data under your directory, so there is no need to do the compression by yourself.

Notice you can only invoke turnin command on the Linux machines in the lab or after logging into the server machine oscar.cs.uic.edu.


If you want to verify that your project was turned in, look in the turnin directory for a file with your userid. For instance for this project, from your CS account you would type:
  

    turnin -c cs441 -p mp1 -v

Note that you can execute turnin as many times as you would like, up until the program deadline when turnin will be disabled for this project. Each time you execute turnin for a project, you overwrite all of what you had turned in previously for that project.It does not work in an incremental way.