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:
17791 | Random number seed
|
1 | Betting strategy. 1 indicates small
bet strategy, 2 indicates specific number bet strategy.
|
1000 | Number 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
- Assume that the text input file always exists and contains only
valid integers.
- Assume that all the numbers in the input file will never be greater
than 1,000,000 or smaller than 1.
- Do not use any arrays in your program.
Tips
- To print a % sign in a printf statement, use %%.
- This may be the most complicated program you have ever designed. Go
to the drawing board and plan your program. Think about the individual
modules you want using the divide-and-conquer strategy. Write and test
each module / function individually. Do not ever write the complete
program, and then start compiling / running / testing it. You will end
up with numerous compilation and logic errors which will take a long
time to fix. Remember how I (Raymond) showed in lecture that you should
practice incremental coding by incrementally coding parts of the
program, then testing each part out before moving on to other parts of
the program.
- You should probably not use the input file given when testing
your program for the first time; you should create your own input file
(by using the Unix command “vim sicbo1.txt”) with
manageable values and small number of simulations. When you are
confident that your program is working for small number of simulations,
increase it.
- You should use many printf statements to give more
information of what your program is doing exactly. For example, you
should probably show the result of each dice throw, the result from each
round, the amount of money you have after each round, etc. In summary,
you should print out as much debugging information as you need; then
before submission, comment out the debugging information.
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.