CS1101C Lab 3 (Even Week)

Sic Bo

The deadline for this lab question is Thursday 23 March 2006, 23:59:59 hours.

The name of your C program file must be called sicbo.c, files with any other name will not be marked.

If you have not yet downloaded and compiled / run / understood the programs from random.zip in the IVLE Workbin -> Lecture notes, do so first. Else you will not be able to proceed with this lab.

Background

We are finally going to get a casino. Putting aside the ethical arguments (this is a programming course; not an ethics course), we will do a very simple simulation of the dice gambling game called “Sic Bo”. Sic Bo is played by rolling three fair six-sided dice and looking at the outcome. Suppose the player starts off with $1000. We assume that the amount the player will bet for each round is always $1. At the end of each round, the player can either win (he can win $1, $2, or $3) or lose (he loses $1). There are many different types of bets in Sic Bo. We will concentrate on only two types of bet: the Small Bet, and the Specific Number Bet.

Small Bet

The player rolls the three dice. If the sum of the three dice is between 4 to 10 inclusive, and if a triplet does not occur, the player wins $1. If all three dice show the same number, it is called a triplet.

The player loses $1 if the sum of the three dice is between 11 to 18 inclusive, or if any triplet occurs.

Specific Number Bet

The player bets on a specific number from 1 to 6 inclusive, then rolls the three dice. If the specific number appears on all three dice, he wins $3. If the specific number appears on exactly two of the dice, he wins $2. If the specific number appears exactly once, he wins $1. If the specific number does not appear on any of the dice, he loses $1.

For example, if the player bets on the number 4, and if the three dice shows 4-1-4, he wins $2 because 4 appeared twice. If the three dice shows 2-1-1, he loses $1 because 4 did not appear at all.

Simulation

Given the two types of bets above, we would like to see whether always using the small bet strategy (we will call this strategy 1) or always using the specific number bet strategy (call it strategy 2) is better in the long run. Suppose the original or starting amount is $1000, we will simulate 1000 rounds with a fixed betting strategy. If the original amount is $n, we will always simulate n rounds. The number of rounds is always the same as the original amount of money. The bet amount is always $1. At the end of the n rounds, we will display the amount of money remaining, and the final amount of money as a percentage of the starting amount of money. Then you can intelligently decide whether to bet at all, and which betting strategy to use.

Implementation

You will be provided with an input file consisting of different simulation scenarios. Each line in the input file gives the parameters for a single simulation. Each simulation typically contains many rounds (1000, 5000, or possibly more). A typical line from the input file consist of three integers separated by blank spaces as shown below:
17791 1 1000
The explanation for each number is given as follows:

17791Random number seed
1Betting strategy. 1 indicates small bet strategy, 2 indicates specific number bet strategy.
1000Number of rounds / Original amount

This says that for this particular simulation, the random number seed is 17791, we will use the small bet strategy, and the number of rounds is 1000 (the starting amount of money is $1000). The random number seed should be initialized to the value shown (by using the srand function) at the beginning of each simulation.

Input File

Assume that the text input file is always called sicbo1.txt. This sample input file contains data for seven simulations:

17791 1 1000
17792 1 10000
17793 1 100000
17794 1 1000000
17795 2 1000
17796 2 10000
17797 2 100000
17798 2 1000000

We will test your program with other simulation data, so your program must work for the general case, and not just only for the sample input file given.

Sample Run

The following shows a sample run for the input file sicbo1.txt. Actual values for the simulation results have been replaced with x’s (the number of x’s does not signify the number of digits). Display the percentage to three decimal places. To print a % sign in a printf statement, use %%.

You are reminded to follow the sample outcome exactly, else marks will be deducted.

Seed: 17791, small bet strategy, starting amount: $1000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17792, small bet strategy, starting amount: $10000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17793, small bet strategy, starting amount: $100000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17794, small bet strategy, starting amount: $1000000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17795, specific number bet strategy, starting amount: $1000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17796, specific number bet strategy, starting amount: $10000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17797, specific number bet strategy, starting amount: $100000
    final amount: $xxxx, percentage: xxx.xxx%
Seed: 17798, specific number bet strategy, starting amount: $1000000
    final amount: $xxxx, percentage: xxx.xxx%

Take Note

Tips

Ponder

Which betting strategy is better? How much do you expect to gain / lose from each betting strategy?


This document, index.html, has been accessed 16 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 10 different hosts have accessed this document in the last 445 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 6 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.