Computer Science homework help
Computer Science homework help. 1 Overview In this project,
we are going to build “Dice War”.
Dice War is a simple dice game with one dealer, 4 players, and two dice. The 4 players (let’s call them A, B, C and D) work in teams where A and C are on the same team and B and D are on the other team. The goal of the game is to have both players on the same team get the same sum. The winning team is the one in which of a player scores the same sum as their partner’s last toss. The Dealer gives the dice to an initial player selected at random and players take turns throwing the dice in the order A, B, C and D. The dealer then waits until one player scores the same sum as their partner’s last toss and declares the winning team. Initially, the dealer waits for the players to be ready, hands the dice to the initial player and the game proceed from that player going around.
2 Implementation
This project is to implemented in C using POSIX threads. You can check: https://computing.llnl.gov/tutorials/pthreads for a tutorial on the POSIX thread library.
The main function should create a thread for the dealer and 4 threads for the players (total of 5 threads). You would need to use pthreads semaphores and conditions variables (e.g., to make the dealer wait on the condition that a player scored the same sum). Notice that we want to keep the threads synchronized and to protect any shared objects. The main program takes a seed as an argument for the random number generation which will be used to randomize the dice throwing process).
3 The Output
The dealer and the players will write into a log file each action they talk. The log file should be able to describe exactly what is happening at each step. The log file should look something like this:
PLAYER A: gets 5 and 4 with a sum 9
PLAYER B: gets 2 and 3 with a sum 5
PLAYER C: gets 2 and 4 with a sum 6
PLAYER D: gets 1 and 3 with a sum 4
The final messages for the game should look something like:
PLAYER A: gets 5 and 4 with a sum 9
PLAYER B: gets 2 and 3 with a sum 5
PLAYER C: gets 6 and 3 with a sum 9
DEALER: The winning team is A and C
The output of the program to the screen (not in the log file) should show the dice values received by each player and the winning team declared by the dealer.
PLAYER B: 5 4
PLAYER C: 2 4
PLAYER D: 1 4
4 Submission
Submission will be done through TRACS. Submissions will include the code, a report containing a brief overview of the design and implementation, the results of 5 independent runs of the program with different seeds, and instructions on to how to compile and run the simulator. Please upload a single zip file including all your files.