Rock, paper, scissors
Rock, paper, scissors
Extra Credit Points 8 - Added to your final score
Due on 9/30/98
Write a suite of programs that run in parallel and interact to play the
``paper, Scissors, Rock'' game. In this game, two players secretly
choose either paper, scissors or rock. They then reveal their choice. A referee
decides who wins as follows:
- Paper beats rock (by covering it)
- Rock beats scissors (by blunting it)
- Scissors beat paper (by cutting it)
- Matching choics draw.
The winning player gets a point. In a draw, no points are awarded. Your
program should simulate such a game, allowing a user to choose how many
iterations are performed, observe the game, and see the final score. Here is
an example of the session.
play 2 ... play 2 games
Paper, Scissor, rock: 2 iterations
Player 1: ready
Player 2: ready
Go players [1]
Player 1: Scissors
Player 2: Rock
Player 2 wins
Go players [2]
Player 1: Paper
Player 2: Paper
Players draw
Final Score:
Player 1: 0
Player 2: 1
Player 2 wins the tournament.
You should write three programs, which operate as follows:
- One program is the main program, which fork/execs one referee process
and two player processes. It then waits until all three terminate. It should check
that the command line parameter specifies the number of games is legal and pass
it to the referee process as a parameter to exec().
- One program is a referee program, which playes the role of a server.
This program should prepare a socket and then listen to both players to send
the string ``READY'', which means that they're ready to make a choice. It
should then tell each player to make a choice by sending them both the string ``GO''.
Their responses are then read, and their scores are calculated and updated.
This process should be repeated until all of the turns have been taken, at
which point the referee should send both players the string ``STOP'', which
causes them to terminate.
- One program is a aplayer program, which playes the role of the client.
This program is executed twice by the main program, and should start by
connecting to the referee's socket. It should then send the ``READY'' message.
When it receives the ``GO'' message back from the referee, it should make
a choice anbd send it as a stringto the referee. When it receives the string
``STOP'', it should kill itself.
These programs will share some functions. To do a good job, create
a makefile that separately compiles these common functions and links
them into the executables taht use them. Please don't avoid sending the
strings by encoding them as one byte numbers - that is part of the problem.