Homework 7

You are to write a c-program that plays Rock-Paper-Scissors. This is an exciting project (homework). Please keep up with developments.

The Game

It is a two person game where each player secretly selects a choice from the three positions: Rock, Paper or Scissors. After both have chosen, the choices are compared and the game scored. If both players pick the same, it is a tie. Else one player is the winner, the other the loser, according to the sceme: scissors cut paper, paper covers rock, rock breaks scisssors.

Each player choses as name, say X and Y. Each player makes a choice, say CX and CY. Player X then runs the program like this:

    rps X Y CX
Player Y runs the program like this:
   rps Y X CY
The program terminates stateing whether the player has won, lost or tied the game.

General Description

The programs will communicate using the file system, in particular by creating a file named Rock, Paper or Scissors. To prevent cheating, we will use the file system protection mechanisms, placing the named files in directories and then controling the readabililty of the directories.

After each program has committed the user's choice by creating a file inside of an unreadability directory, the two programs will rendez-vous. This is a tricky little bit of programming: to get two programs to synchronize. The programs will memorize the time of the rendez-vous. They will then make the directories readable, revealing the choices. They will check the change-time of the opponents' files to ascertain they have not cheated. The change-time must be less than the time of rendez-vous.

We can go on and do clean up, and repeated games with score keeping, and so on. But for now I will just give a more detailed description of the simple version of the program.

Details

See the rendez vous code at /rps.

The two players pick distinct names, we will call them X and Y. It is important to note which name is lexicographically smaller, since tasks are divided up depending on this. We will assume X is smaller than Y in lexicographic order.

  1. The program of player X creates a world-writable directory name X-Y in the directory /var/tmp. If the directory already exists, continue (we hope that it is owned by X, else we will crash).
  2. The program of player X creates a non-readable directory X.d inside directory X-Y, and inside this directory, creates one file, named either Rock, Paper, or Scissors.
  3. The program of player Y does likewise, with a directroy Y.d.
  4. The two programs then rendez-vous using files X.l and Y.l, inside the directory X-Y.
  5. The program for X then change the mode of X.d to world readable. The program for Y does the same for Y.d
  6. The programs read the file names, check for cheating, and print their conclusions.
  7. In the simple verion, now the programs exit.
In a more complicated version, the programs can clean up, as follows:
  1. Continuing the above protocol: the programs rendez-vous on X.l and Y.l a second time.
  2. Program X then deletes X.d.
  3. Seeing this, program Y then delete Y.d and Y.l and exits.
  4. Seeing this, program X then deletes X.l and X-Y and exits.
As designed, the programs should work even without this cleanup, that is, they should be robust to the initial state of the file system cuased by players quiting the protocol early.