Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --------------------------------------------------
- // THIS CODE FILE IS NOT TO BE MODIFIED IN ANY WAY!!!
- // --------------------------------------------------
- // YOU ARE TO REFACTOR YOUR CODE FROM PREVIOUS HOMEWORKS
- // SO THAT THIS CODE WORKS PROPERLY WITH YOURS
- // Include files
- #include <iostream>
- #include "Boov.h"
- #include "Gorg.h"
- int main()
- {
- // Maintain counters for each competitor
- long long boov_wins = 0;
- long long gorg_wins = 0;
- // Keep the battling to a minimum
- const long long NUMBER_OF_SIMULATIONS = 1000;
- // Lots of battling
- for (long long i = 1; i <= NUMBER_OF_SIMULATIONS; ++i)
- {
- // Set up each object dynamically so virtual functions will work
- Competitor * oh = new Boov("Oh!");
- Competitor * george = new Gorg();
- // Gorg gets attacked first
- // Boov only gets attacked if Gorg is still standing
- // See if we need to continue
- while ((oh->IsDefeated() == false) && (george->IsDefeated() == false))
- {
- george->GetsAttacked();
- if (george->IsDefeated() == false)
- {
- oh->GetsAttacked();
- }
- }
- // Only one of the two is defeated... So let's figure out who it is
- // You'll need this link for programmming the print statements correctly
- // https://www.learncpp.com/cpp-tutorial/12-10-printing-inherited-classes-using-operator/
- if (george->IsDefeated())
- {
- ++boov_wins;
- std::cout << *oh << " defeats " << *george << std::endl;
- }
- else
- {
- ++gorg_wins;
- std::cout << *george << " defeats " << *oh << std::endl;
- }
- // This particular simulation is over so give back the memory
- // Maybe if we continued development we would add a Refresh() function or something
- delete oh;
- delete george;
- }
- // Print out the overall results
- double gorg = gorg_wins / static_cast<double>(NUMBER_OF_SIMULATIONS) * 100.0;
- double boov = boov_wins / static_cast<double>(NUMBER_OF_SIMULATIONS) * 100.0;
- // I personally get about 98.7% for George
- std::cout << "George wins " << gorg << "% of the time" << std::endl;
- // I personally get about 1.3% for Oh
- std::cout << "Oh wins " << boov << "% of the time" << std::endl;
- // Pause program before closing down
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement