CS1101C Lab 3 (Even Week)

The Warlock of Firetop Mountain #2

The deadline for this lab question is Friday 28 March 2008, 23:59:59 hours.

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

Preliminary

This week's lab is based on last week's lab question. If you have not read it, please do so now.

The difference on this week's lab is in the rolling of the dice. In last week's lab, both the human and creature have an attack of 2d6; that means we throw two six-sided dice. For this week, the human and creature can have different attacks. The human can have an attack of 2d6, and the creature can have an attack of 1d12 (throwing one twelve-sided dice). In general, an attack consists of mdn, where we throw an n-sided die m times. Your task is to add in this flexibility for the simulation.

Text File

You will be provided with an input text file called firetop2.txt consisting of one or more lines. Each line contains the parameters for each experiment. Each line consists of a random number seed, the number of simulations, the human's skill, the human's stamina, the creature's skill, the creature's stamina, the human's attack parameters, and the creature's attack parameters. A typical line from the input file consist of ten integers separated by blank spaces as shown below:
6094 100 1 5 1 5 2 6 1 12
The explanation for each number as well as their valid ranges are given as follows:

6094Random number seed (1-32767)
100Number of simulations (1-100000)
1Human's skill (1-12)
5Human's stamina (1-24)
1Creature's skill (1-12)
5Creature's stamina (1-24)
2 6Human's attack is 2d6 (1-24 for each integer)
1 12Creature's attack is 1d12 (1-24 for each integer)

Everything else remains the same as last week's lab.

Here is the contents of a sample text file:

6094 100 1 5 1 5 2 6 1 12
6095 1000 1 5 1 5 2 6 1 12
6096 10000 1 5 1 5 2 6 1 12
6097 100000 1 5 1 5 2 6 1 12

7094 100 12 24 12 24 2 6 1 12
7095 1000 12 24 12 24 2 6 1 12
7096 10000 12 24 12 24 2 6 1 12
7097 100000 12 24 12 24 2 6 1 12

8094 100 12 24 12 24 2 6 1 13
8095 1000 12 24 12 24 2 6 1 13
8096 10000 12 24 12 24 2 6 1 13
8097 100000 12 24 12 24 2 6 1 13

9094 100 12 24 12 24 2 6 1 14
9095 1000 12 24 12 24 2 6 1 14
9096 10000 12 24 12 24 2 6 1 14
9097 100000 12 24 12 24 2 6 1 14
We will of course test your programs with different test data.

Sample Run

Assuming that the executable is firetop2, a sample run of the program is shown below. Follow the sample output precisely. User input is denoted in bold.

$ gcc -Wall firetop2.c -o firetop2

$ ./firetop2

Seed: 6094, human skill: 1, human stamina: 5
    creature skill: 1, creature stamina: 5
    human attack: 2d6, creature attack: 1d12
Number of simulations: 100, human victories: 59
    creature victories: 40, draws: 1
Percentage of human victories: 59.000%
Percentage of creature victories: 40.000%
Percentage of draws: 1.000%

Seed: 6095, human skill: 1, human stamina: 5
    creature skill: 1, creature stamina: 5
    human attack: 2d6, creature attack: 1d12
Number of simulations: 1000, human victories: 561
    creature victories: 415, draws: 24
Percentage of human victories: 56.100%
Percentage of creature victories: 41.500%
Percentage of draws: 2.400%

Seed: 6096, human skill: 1, human stamina: 5
    creature skill: 1, creature stamina: 5
    human attack: 2d6, creature attack: 1d12
Number of simulations: 10000, human victories: 5565
    creature victories: 4181, draws: 254
Percentage of human victories: 55.650%
Percentage of creature victories: 41.810%
Percentage of draws: 2.540%

Seed: 6097, human skill: 1, human stamina: 5
    creature skill: 1, creature stamina: 5
    human attack: 2d6, creature attack: 1d12
Number of simulations: 100000, human victories: 56640
    creature victories: 41138, draws: 2222
Percentage of human victories: 56.640%
Percentage of creature victories: 41.138%
Percentage of draws: 2.222%

Seed: 7094, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d12
Number of simulations: 100, human victories: 70
    creature victories: 30, draws: 0
Percentage of human victories: 70.000%
Percentage of creature victories: 30.000%
Percentage of draws: 0.000%

Seed: 7095, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d12
Number of simulations: 1000, human victories: 657
    creature victories: 337, draws: 6
Percentage of human victories: 65.700%
Percentage of creature victories: 33.700%
Percentage of draws: 0.600%

Seed: 7096, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d12
Number of simulations: 10000, human victories: 6738
    creature victories: 3207, draws: 55
Percentage of human victories: 67.380%
Percentage of creature victories: 32.070%
Percentage of draws: 0.550%

Seed: 7097, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d12
Number of simulations: 100000, human victories: 65976
    creature victories: 33366, draws: 658
Percentage of human victories: 65.976%
Percentage of creature victories: 33.366%
Percentage of draws: 0.658%

Seed: 8094, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d13
Number of simulations: 100, human victories: 56
    creature victories: 44, draws: 0
Percentage of human victories: 56.000%
Percentage of creature victories: 44.000%
Percentage of draws: 0.000%

Seed: 8095, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d13
Number of simulations: 1000, human victories: 493
    creature victories: 500, draws: 7
Percentage of human victories: 49.300%
Percentage of creature victories: 50.000%
Percentage of draws: 0.700%

Seed: 8096, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d13
Number of simulations: 10000, human victories: 4956
    creature victories: 4970, draws: 74
Percentage of human victories: 49.560%
Percentage of creature victories: 49.700%
Percentage of draws: 0.740%

Seed: 8097, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d13
Number of simulations: 100000, human victories: 49627
    creature victories: 49749, draws: 624
Percentage of human victories: 49.627%
Percentage of creature victories: 49.749%
Percentage of draws: 0.624%

Seed: 9094, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d14
Number of simulations: 100, human victories: 38
    creature victories: 62, draws: 0
Percentage of human victories: 38.000%
Percentage of creature victories: 62.000%
Percentage of draws: 0.000%

Seed: 9095, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d14
Number of simulations: 1000, human victories: 352
    creature victories: 640, draws: 8
Percentage of human victories: 35.200%
Percentage of creature victories: 64.000%
Percentage of draws: 0.800%

Seed: 9096, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d14
Number of simulations: 10000, human victories: 3479
    creature victories: 6462, draws: 59
Percentage of human victories: 34.790%
Percentage of creature victories: 64.620%
Percentage of draws: 0.590%

Seed: 9097, human skill: 12, human stamina: 24
    creature skill: 12, creature stamina: 24
    human attack: 2d6, creature attack: 1d14
Number of simulations: 100000, human victories: 35511
    creature victories: 63976, draws: 513
Percentage of human victories: 35.511%
Percentage of creature victories: 63.976%
Percentage of draws: 0.513%

$

Note and Ponder

  1. Assume that all user input is valid.

  2. To print the % sign, use %% in your printf format specifier.

  3. To edit the text file, you may use the vim editor by typing "vim firetop2.txt".

  4. If your program does not work as you expect (logical errors), use extra printf statements to print out all the values of your variables to aid in your debugging.

  5. How do you know if your program is working perfectly? Did you test your programs with your own test data? What constitutes as good test data?

  6. Most importantly, have lots of fun programming!


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

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

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