CSC 209H: Assignment 3

Weight: 10% of course grade.

Due date: 10:00 p.m. Thursday November 17 Saturday November 19, 2005.


Introduction

In this assignment, you will be writing programs that will play the age-old game of Roshambo, otherwise known as rock, paper, scissors or by a number of other names. Typically the game is played between human beings as an easy way to determine who sits in the front seat, who gets the big piece of pie, or who plays with the toys first.

The game itself is very simple. Two players make a fist with one hand, and count together "Ro... Sham... Bo!" or "One... Two... Three!" while bouncing their fist. On "Three", they simultaneously change their fist into one of three shapes: a rock (a fist), a piece of paper (an open hand), or a pair of scissors (two fingers making a V). Paper beats rock, scissors beats paper, and rock beats scissors. If both players choose the same shape, it's a tie, and they repeat.

The optimal strategy is to choose a shape at random, which wins 33% of the time and ties 33%. But humans are bad at randomness, so the secret to winning is to try to guess what shape your opponent will throw, and yourself throw the shape that wins. Do this well, and you'll win much more often than using the optimal strategy.

Roshambo is probably bigger than you thought. Every year since 2002, Toronto has been host to the WRPS International World Championship, where the winner receives a large cash prize. This event is even broadcast internationally on television. There is also an annual computer Roshambo competition, where programs compete, trying exploit each other's weaknesses.

Our goal here will be to write some simple Roshambo-playing programs, and write a program that will run and judge a Roshambo tournament.


Part 1 - Rock-Paper-Scissors players

In this part you are asked to write at least two different C programs that will play a series of rock, paper, scissors games.

Your programs will be named rps1, rps2, and so on. You may write and submit as many programs as you wish. You will also submit a README text file briefly describing how each of your programs work. Be sure to point out any interesting strategies you might be using!

For the purposes of this assignment, we will use the following representations for the possible throws:

Your program will iteratively execute the following phases:

When EOF is encountered on stdin instead of "GO", your program should terminate normally.

Each program may assume it is playing a series of games against a single opponent. A particularly clever program may use past results to try to increase its odds of winning (for example, if its opponent always throws rock, your program might decide to always throw paper).

Warning: you will not be evaluated on how clever your program is, only that it follows the specification! Do not spend so much time on your players so that you do not complete the rest of the assignment!

Tip: To aid in debugging (particularly for part 2), you might want to send diagnostic or status information to standard error. Be sure to turn off this diagnostic output before handing in your assignment.

Examples

The following may be an execution of such a program.

stdin	stdout
GO	2
2		
GO	0
1		
GO	2
1		

When in debugging or diagnostic mode, your program might follow an execution like this.

stdin	stdout	stderr
GO	2
2		Tie
GO	0
1		Lose
GO	2
1		Win

Hints and Clarifications


Part 2 - Roshambo umpire

In this part you will write a C program named roshambo that will act as the umpire in a Roshambo tournament. The competitors will be executions of your rps* programs.

Your program should support being run in the following manner:

$ roshambo [-r rounds_per_match] list-of-competitors

Following the -r option (if it exists) is an integer N, the number of rounds to be played per match. If -r does not appear, default to N=10.

The list of competitors will be a list of program names of rps programs, possibly (and probably) with duplicates. For example, a list might be rps1 rps2 rps3 rps1 rps1 for a tournament with 5 players. There must be at least 2 competitors specified. Your program must support tournaments of at least 16 competitors.

Your program will do the following:

Important: Be sure to clean up any processes that may be left behind before logging out of your machine. The ps and top commands can help you find any lingering processes.

Examples

This is a tournament played between two competitors.

$ ./roshambo -r 10 rps1 rps2
Match 1: player 1 (rps1) versus player 2 (rps2)
Round 1: 1 and 1
Round 2: 2 and 2
Round 3: 2 and 0
Round 4: 2 and 2
Round 5: 2 and 0
Round 6: 1 and 0
Round 7: 2 and 0
Round 8: 1 and 0
Round 9: 1 and 1
Round 10: 1 and 0
Round 11: 1 and 1
Round 12: 2 and 1
Score: 4 to 3 with 5 ties, player 1 (rps1) wins
The tournament winner is player 1 (rps1)

Hints and Clarifications


Learning Objectives

What to hand in

You will commit to the a3 directory of your CSC209 repository the following files:

You are strongly encouraged to take advantage of the version control system and commit your work frequently so that you can keep track of your progress. Please note that perfectly fine (and even recommended) that you keep any additional files related to this assignment (such as files and scripts used for testing) under version control. The markers will simply ignore such files.