// --------------------------------------------------------------
// CSI 201 Fall 2016
// Homework assignment: Boss Fight
//
// Turn-In Instructions:
//   Copy this code into a new C++ project. Edit the code until
//   your project works. Then upload the modified .cpp code file
//   to canvas.
//
//   Also, there is a final question at the end of these directions.
//   You also must upload your answer to that question (as a .txt,
//   .doc, .docx, or .pdf) to canvas.
//
// Objectives:
//   - practice with defining functions
//   - practice reading code that someone else wrote
//   - experience working with larger projects than we've seen
//     so far
//
// Where to get help:
//   - Wednesday's lab (risk_rolls) is very similar to this.
//     Additionally, we gave an example solution to another very
//     similar problem: canvas_files -> risk_rolls ->
//     more_dice_examples.cpp
//   - The usual: office hours, appointments, QSC. Please ask for
//     help!
//
// Overview:
// In this assignment, we are simulating how a very nerdy dice game
// will work out. Our heroine is fighting a dragon. Each round, they
// attack each other. The game will keep going until one (of both)
// of them run out of hit points. (Both the heroine and the dragon
// can die on the same turn.) At the beginning of the game, the
// heroine starts with 20 hit points, and the dragon starts with 50.
//
// Here is how attacking works:
//   The heroine first rolls a 20-sided die (1d20) to see if her attack
//   hits. If the result is greater than 12, she hits the dragon, but
//   if it is <= 12, her attack misses. If she hits, she rolls two six-
//   sided dice (2d6). The sum of those two dice is how much damage
//   she does (the dragon's hit points will go down by this amount).
//
//   The dragon attacks in the same way, except it needs to roll a
//   d20 that is > 15 to hit, and when it hits, it rolls one 8-sided
//   die to determine how much damage it does.
//
// Your tasks:
//   Many of the functions below are incomplete. Fill in all of the
//   missing code by reading the comments above each function, and
//   then writing code so that each function does what it says it
//   should.
//
//   Once your code works, it should tell you the percentage of the
//   time that the heroine survives the fight with the dragon.
//
//   Finally, once your code works, answer the following question
//   (in a separate word, text, or pdf file):
//
// Final Question:
//   Suppose you are designing this game, and can make choices to
//   improve it. Past experience has shown that players tend to
//   dislike games where they don't have at least a 60% change of
//   winning. Propose one or more changes that will meet this goal,
//   and describe how you used your code to prove that the changes
//   work.
// --------------------------------------------------------------

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

//functions we'll use
int roll1d20(); //make a random # between 1 and 20
int roll1d8(); //make a random # between 1 and 8
int roll1d6(); //make a random # between 1 and 6
int heroineSurvives(int, int); //does the heroine survive after killing the dragon
void computeOutcomeProbabilities(
    int numberOfTrials, int dragonHP, int heroineHP);



//where all code begins
int main() {

    // see the random number generator, so that we get different
    // random numbers each time we play.
    srand(time(0));

    int numberOfTrials = 100000;
    int dragonHP = 50;
    int heroineHP = 20;
    computeOutcomeProbabilities(numberOfTrials, dragonHP, heroineHP);
} //end of main is here


//make a dice roll from 1-20, called a 1d20
int roll1d20() {
    return -1; //This line is just a placeholder. Replace it!
}

//make a dice roll from 1-8, called a 1d8
int roll1d8() {
    return -1; //This line is just a placeholder. Replace it!
}

//make a dice roll from 1-6, called a 1d6
int roll1d6() {
    return -1; //This line is just a placeholder. Replace it!
}

// The meat of the program goes in this next function.
// All other functions should only be 1 or 2 lines long.

// This function plays through the dragon game once.
// Inputs:
//   dragonHP : how many hit points the dragon starts with
//   heroineHP : how many hit points the heroine starts with
// Output:
//   0 : if the heroine dies (has hit points <= 0 at the end of the fight)
//   1 : if the heroine lives (has hit points > 0 at the end of the fight)
// Specification:
//   The introduction at the top of this file describes how a game works.
//   Here are some more specific hints.
//   - The fight continues while both the dragon and the heroine have
//     hit points left
//   - In every round, the dragon and the heroine both have a chance
//     to hit each other. These hits don't have an order. That is, you
//     don't need to have logic for "the dragon attacks first", or
//     anything like that. They both get to attack each round. This means
//     that they can die simultaneously.
//   - Both the heroine and the dragon first roll a d20 die to see if they
//     even hit at all. If they do hit, then they roll more dice to see
//     how much damage they do. See the comments at the top of this file
//     for more details.
//   - If the dragon's attack does 4 damage, that means
//         heroineHP -= 4
int heroineSurvives(int dragonHP, int heroineHP) {

    return -1; //This line is just a placeholder. Replace it!
}

// You don't need to change any of this code
// this will simulate many probability trials
// and output the survival percentage to the console
// notice how tidy our main has become!
void computeOutcomeProbabilities(int num_trials, int dragonHP, int heroineHP) {
    int heroineSurvivesTotal = 0;
    int counter = 0;

    // Play the game num_trials times
    while (counter < num_trials) {
        // Run one game and log any successes
        if (heroineSurvives(dragonHP, heroineHP) == 1)
            heroineSurvivesTotal++;
        counter++;
    }
    cout << "Heroine Survives " << heroineSurvivesTotal * 100.0 / num_trials << " percent of the time. " << endl;
}
