Problem 1 Modify the PickupSticks class so that the last player to pickup some s
ID: 3636028 • Letter: P
Question
Problem 1Modify the PickupSticks class so that the last player to pickup some sticks wins.#include "PickUpSticks.h"
PickUpSticks::PickUpSticks(void)
: randomizer()
{
initial_sticks_on_pile = 16;
Player::MaxSticksToPickup(3);
}
PickUpSticks::PickUpSticks(int new_initial_sticks_on_pile, int new_max_sticks_to_pickup)
: randomizer()
{
if(new_initial_sticks_on_pile < new_max_sticks_to_pickup || new_max_sticks_to_pickup < 2)
{
new_max_sticks_to_pickup = 3;
new_initial_sticks_on_pile = 16;
}
else if(initial_sticks_on_pile % new_max_sticks_to_pickup != 1)
{
new_max_sticks_to_pickup = 3;
new_initial_sticks_on_pile = 16;
}
initial_sticks_on_pile = new_initial_sticks_on_pile;
Player::MaxSticksToPickup(new_max_sticks_to_pickup);
}
PickUpSticks::~PickUpSticks(void)
{
cout << "PickUpSticks says goodbye" << endl;
}
void PickUpSticks::playPickUpSaticks(void)
{
int sticks_on_pile = initial_sticks_on_pile;
Player **player = new Player*[2];
player[0] = &human;
player[1] = &robot;
int player_id = randomizer.nextInt(0, 1);
cout << "There are " << sticks_on_pile << " sticks on the pile" << endl;
do
{
player_id = (player_id + 1) % 2;
cout << "It is " << player[player_id]->Name() << "'s turn" << endl;
int sticks_to_pickup = player[player_id]->pickupSticks(sticks_on_pile);
cout << player[player_id]->Name() << " picks up " << sticks_to_pickup << " sticks" << endl;
sticks_on_pile = sticks_on_pile - sticks_to_pickup;
cout << "There are " << sticks_on_pile << " sticks on the file" << endl;
}
while(sticks_on_pile > 0);
cout << player[(player_id + 1) % 2]->Name() << " wins" << endl;
delete [] player;
}
#include "Player.h"
int Player::max_sticks_to_pickup;
int Player::MaxSticksToPickup(void)
{
return max_sticks_to_pickup;
}
void Player::MaxSticksToPickup(int new_max_sticks_to_pickup)
{
if(new_max_sticks_to_pickup < 2)
max_sticks_to_pickup = 3;
else
max_sticks_to_pickup = new_max_sticks_to_pickup;
}
Player::Player(void)
{
Name("Lucy");
}
Player::Player(const string& new_name)
{
Name(new_name);
}
Player::~Player(void)
{
cout << Name() << " says good bye!" << endl;
}
string Player::Name(void) const
{
return name;
}
void Player::Name(const string& new_name)
{
if(new_name.length() == 0)
name = "Lucy";
else
name = new_name;
}
Explanation / Answer
Hi I have done the solution for this in my notebook. But the solution is too big , I cannot type it here because very less time is remaining.. So please rate me Lifesaver and I'll share the answer with you through email or cramster inbox. I don't do this generally, but I have no other option here because there's very less time left... you need not worry as I have the solution ready
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.