Homework 13: Rock, Paper, Scissors
This continues the parallel theme. Your job is to write a rock-paper-scissors simulator.
- The program will spawn (N-1) threads (command-line argument) so there are a total of N threads running (including the main thread).
- Each thread (including the main thread) will pick a strategy and play a match of 1000 rounds of rock-paper-scissors against all other threads simultaneously. The strategy may be random or, for bonus points, some threads may pick specific strategies (always rock, majority thrown last turn, etc).
- Each thread will throw one gesture (rock, paper, or scissors) and then look at what every other thread threw. The score for a thread is the count of how many other threads this thread beat. Rock beats scissors, scissors beats paper, and paper beats rock.
- After 1000 rounds, each thread will report its total score to the main thread and exit. The main thread, after 1000 rounds, will receive and display the scores reported by all the other threads, and it will then exit as well.
- Note that there is no “manager thread” - all threads in the program should be playing the game at the same time.
For example, if 3 threads are running and thread “A” throws rock, thread “B” throws paper, and thread “C” throws paper, then thread “B” scores one for itself (for beating “A”) and thread “C” scores one for itself (for beating “A”). Thread “A” scores nothing (for beating no one).
Bring your solution to our April meeting.
Feel free to discuss the problem or any other topics you are interested in on our mailing list (accessible via our Meetup Group).