Lab 2. Rock Paper Scissor

This lab is to simulate the game if Rock Paper Scissor with 2 players and multiple players. Read more about this game at http://en.wikipedia.org/wiki/Rock-paper-scissors.


Task 1 – Ping-Pong Communication with 2 players.

-          Get Organised for this problem:

o   Create a folder week2/pingpong.

o   Start from the files pingpong.c and bring the files Makefile and machines in the folder.

-          Make the changes to solve the problem.

o   Declare an array of chars for the moves e.g. char * moves = “RPS”;

o   Write a function int test (char move1, char move2) to return0, 1 or 2 depending on winner.

o   Each player should do:

§  Init + rank + size

§  Generate a random number between 0,1,2 representing the move.

§  Ping pong the move (use the code as it is)

§  Test winner based on the chars outmsg and inmsg

§  Write the results


Task 2 – Ring Communication with Multiple Players. 

-          Start from the program ring.c.

-          Put in place the following sequence of computation:

o   Declare an array of chars for the moves e.g. char * moves = “RPS”;

o   Declare an array of chars for the round moves e.g. char round [100];

o   Write a function int test (char move1, char move2) to return 1 or 2 depending on winner.

o   Each player should do:

§  Init + rank + size

§  Generate a random number between 0,1,2.

§  Send using a ring the moves of each player and store them in the array round.

§  Test the array round to find the winner.

For this task you should derive a RPS multiplayer strategy.


Note:  Solutions for Task1 and Task2.

 

Note: You can generate a random number using the code below.

 

unsigned int iseed = (unsigned int)time(NULL);

srand(iseed*rank);       // seed the generator with a different seed.

move_id=rand()%3;    // generate a random number between 0-2.