Question
Can someone please help me out with this? CIS2542 - Homework Gorg vs Boov Battle Part 2 Bring on the Gorg! NOTE: Remember that you
Can someone please help me out with this? CIS2542 - Homework Gorg vs Boov Battle Part 2 Bring on the Gorg!
NOTE: Remember that you are adding on to your previous Boov project. See the previous documentation for Boov specific information.
The Gorg can no longer be reasoned with! Negotiations cannot go well if you have no idea what the other side wants! They are so strong and vicious that ignoring them only means Earth is indirectly conquered somehow? Its not my movie plot, but my retelling is totally butchering it for sure.
The Boov are friends of all peoples across the galaxy. Or so we are told. These beloved creatures want nothing more than peace and harmony, as long as it is their version of peace and harmony. It turns out okay for everyone in the end I suppose.
Maybe you can tell from the descriptions, but the Boov are quite the underdogs here! Captain Smek will need to simulate a Gorg battle many times over to see what their odds of victory would be.
For the next part of this simulation, lets create the Gorg class. Here are their specifications.
Gorg
- Every one of them is named George
- Every one of them has 10 health points
- When a Gorg gets attacked:
- 1/4 of the time randomly, the attack will miss and do no damage
- 1/4 of the time the Gorg will actually regain 1 health point! Just make sure the new health value doesnt get above the starting value of 10
- 1/2 of the time randomly, the attack will hit them and do [2-4] random damage
Requirements
1) Create a Gorg class type
- Private string member variable for name
- Private int member variable for health
- Public constructor which initializes both member variables
- Public get function for the name
- Public get function for the health value
- Public boolean function called IsDefeated()
- A Gorg is defeated when health <= 0
- Public void function called Print() to print out the valuable object details
- Public void function called GetsAttacked()
- The above section describes the results of when a Gorg gets attacked
2) Create a main() function which creates a Boov versus Gorg battle using these classes
- Create a Boov object (We will be sending one named Oh off to do all the battling)
- Create a Gorg object (Hes always named George, remember?)
- What percentage of the time will the Boov win the battle?
- Boov always attack first, and then the attacks go back and forth
- Create a loop that uses the GetsAttacked() functions until either the Boov or Gorg is defeated
- Keep track of each kind of victory
- Test every one of your functions thoroughly
- After 100000 simulations, how bad are the Boovs chances?
Submit your solution folder in ZIP format. //GorgvsBoov.h:
#pragma once
#include
class GorgvsBoov { public: GorgvsBoov(const std::string & NAME); GorgvsBoov(const GorgvsBoov & rhs);
~GorgvsBoov();
std::string GetName(); int GetHealth(); static int GetCount();
bool IsDefeated(); void Print(); void GetAttacked();
GorgvsBoov & operator =(const GorgvsBoov &rhs);
private:
std::string name; int health; static int count; }; //GorgvsBoov.cpp:
#include "GorgvsBoov.h"
#include
int GorgvsBoov::count = 0;
GorgvsBoov::GorgvsBoov(const std::string & NAME) :name(NAME), health(10 + (rand() % 6)) { ++count; }
GorgvsBoov::GorgvsBoov(const GorgvsBoov & rhs) : name(rhs.name), health(rhs.health) { count++; }
GorgvsBoov::~GorgvsBoov() { --count; }
std::string GorgvsBoov::GetName() { return name;
}
int GorgvsBoov::GetHealth() { return health; }
int GorgvsBoov::GetCount() { return count; }
bool GorgvsBoov::IsDefeated() { return health <= 0; }
void GorgvsBoov::Print() { std::cout << name << ": " << health; }
void GorgvsBoov::GetAttacked() { int result = rand() % 4;
if (result == 1) { health -= 1; }
else if (result >= 2) { health -= (2 + rand() % 4); }
}
GorgvsBoov & GorgvsBoov::operator=(const GorgvsBoov & rhs) { health = rhs.health; name = rhs.name; return *this; } //Main.cpp
#include "GorgvsBoov.h" #include #include
int main() {
srand(static_cast(time(NULL)));
int rounds = 0; int battles = 1000000;
for (int i = 1; i <= battles; i++) { GorgvsBoov b("OhNo!");
while (b.IsDefeated() == false) { rounds++; b.GetAttacked(); } }
double average = rounds / static_cast(battles);
std::cout << "Average: " << average << std::endl;
system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started