CS 202 - Computer Science II - Spring 2008
Project 4


Loyola College > Department of Computer Science > Dr. James Glenn > CS 202 > Projects > Project 4

Due

Monday, April 28th at 11:59pm.

Projects submitted after the due date will be assessed a 20% penalty per day. Projects will not be accepted more than four days late.

Objectives

Introduction


Pig is a two-player game played with a single six-sided die. On each turn, the current player rolls the die and, if the result is not 1, adds the result to the turn score. After each roll, the player has the option of ending the turn, adding the turn score to the total score, and passing control to the next player, or rolling again. If a player rolls a 1 then the turn is over and nothing is added to the total score. The game is over when one player reaches 100 or more points. After each roll, players must strategically determine whether so much progress has been made that it is not worth risking another roll.

Assignment

Create a GUI version of Pig that allows human vs. computer play. The human should go first. You can create a simple computer player that rolls until it has won or until the turn total is at least some fixed amount (20 in the applet given above). Your program should follow the model/view/controller architecture.

In addition, at the end of a game, you should connect to the server at port 4502 on gunpowder.cs.loyola.edu and send a play-by-play account of the game. Each line in the account should be in the form human-score:computer-score:current-player:turn-total:action where current-player is 0 or 1 (for human and computer respectively) and action is ROLL:result or END. For example, the following describes a game

0:0:0:0:ROLL:3
0:0:0:3:ROLL:6
0:0:0:9:ROLL:2
0:0:0:11:END
11:0:1:0:ROLL:1
11:0:0:0:ROLL:6
11:0:0:6:ROLL:6
11:0:0:12:END
At the end of the account you must send a single line containing the string "DONE". You must not send the account until the end of the game.

Files

You needn't write the server. For testing, you can use the following server that displays every message that is sent to it and keeps track of human wins and computer wins. To test on your own computer, run PigServer and PigWindow at the same time (this requires a trick in jGRASP). If the server is running on your computer, have the client connect to host "127.0.0.1" on port 4502.

Advice

Grading

Submissions

Submit through e-mail the source code (.java files) for any class you created. JAR or ZIP archives are preferred (but not required).