Fall Semester 2005


Due date
Friday September 23, 11:59pm

You need to turn in two distinct implementations:

  1. one that uses CGI.pm (documentation from lecture notes nine)
  2. another one that doesn't use CGI.pm

We'll talk about this in class on Thu, Sep 23.

Late policy
Try to turn everything on time, although late solutions will be accepted.

Work policy
Working in groups is encouraged but please turn in your own version of the assignment.

Also, please make sure you

the Computer Science Department's Statement on Academic Integrity before turning in your assignment.

If you are an Informatics student the following also applies: Informatics academic honesty policy.

Task
Write a program that allows you to play (The Rock, Paper, Scissors Game). The game is described below:

You and the computer play a game.

Here's a standalone program that implements the game:
import java.io.*;
import java.util.*; 

class Two {
    public static void main(String[] args) throws IOException {
        BufferedReader b = 
            new BufferedReader(new InputStreamReader(System.in));
        String line; 
        int user, computer, pointsUser = 0, pointsComputer = 0; 
        String[] choices = { "rock", "scissors", "paper" }; 
        Hashtable h = new Hashtable(); 
        h.put("rock"   , new Integer(0)); 
        h.put("scissors", new Integer(1)); 
        h.put("paper"   , new Integer(2)); 
        Object choice; 
        System.out.println("Hello and welcome to the game.");           
        do {
            computer = (int)(Math.random() * choices.length); 
            System.out.println("*** The computer has chosen: (" + choices[computer]  + ")"); 
            System.out.println("Now it's your turn.");
            System.out.println("Paper, scissors, or rock...");
            System.out.print("Which will it be? Type here: ");
            line = b.readLine(); 
            choice = h.get(line); 
            String message = "*** The computer's choice was: " + choices[computer];
            if (choice == null) {
                System.out.println("Sorry, this is not a valid choice."); 
                System.out.println("The computer has just scored one on you.");
                System.out.println("Its choice was: " + choices[computer]);
                pointsComputer += 1;                 
            } else {
                user = ((Integer)choice).intValue();               
                if ((user + 1) % 3 == computer) {
                    System.out.println("Very good.\n" + message);
                    System.out.println("***(So, you win.)***"); 
                    pointsUser += 1; 
                } else if ((computer + 1) % 3 == user) {
                    System.out.println("Too bad.\n" + message);
                    System.out.println("***(So, you lose.)***"); 
                    pointsComputer += 1; 
                } else {
                    System.out.println(message + "\n***(This game's a draw.)***"); 
                }
                System.out.println("The score is now: "); 
                System.out.println("  Computer: " + pointsComputer); 
                System.out.println("  You     : " + pointsUser); 
            }            
        } while (true);   
    }
}
Your program should be a CGI script that behaves just like this one, above.

Here's a session with the program above:

frilled.cs.indiana.edu%javac Two.java
frilled.cs.indiana.edu%java Two
Hello and welcome to the game.
*** The computer has chosen: (rock)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: scissors
Too bad.
*** The computer's choice was: rock
***(So, you lose.)***
The score is now: 
  Computer: 1
  You     : 0
*** The computer has chosen: (scissors)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: paper
Too bad.
*** The computer's choice was: scissors
***(So, you lose.)***
The score is now: 
  Computer: 2
  You     : 0
*** The computer has chosen: (paper)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: rock
Too bad.
*** The computer's choice was: paper
***(So, you lose.)***
The score is now: 
  Computer: 3
  You     : 0
*** The computer has chosen: (paper)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: scissors
Very good.
*** The computer's choice was: paper
***(So, you win.)***
The score is now: 
  Computer: 3
  You     : 1
*** The computer has chosen: (rock)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: rock
*** The computer's choice was: rock
***(This game's a draw.)***
The score is now: 
  Computer: 3
  You     : 1
*** The computer has chosen: (rock)
Now it's your turn.
Paper, scissors, or rock...
Which will it be? Type here: ^Cfrilled.cs.indiana.edu%
Here's a prototype for your web script (we'll discuss it in class).

Prototypes:

Grading
Feedback will be provided within a week, grades will be posted on-line.