1 write a parameterized function that plays the game you must determine the function 5346996

1. Write a parameterized function that plays the game. You must determine the function’s parameters.

I need to modify

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

typedef unsigned (*COMPUTESTICKSTOPICKUP)(unsigned, unsigned);

string trim(string& original);
string toupper(string& original);
//void evaluate_parameters(unsigned& total_sticks, unsigned& max_pick_up);
int randomInt(int lower, int upper);
void playPickupSticks(const string& player_name,
unsigned& initial_sticks,
unsigned& max_sticks);
bool answer_convert(string& original);
unsigned humanComputeSticksToPickup(unsigned sticks_on_pile,
unsigned max_sticks_to_pickup);
unsigned computerComputeSticksToPickup
(unsigned sticks_on_pile,
unsigned max_sticks_to_pickup);
int main()
{
//read configuration file name
const string config_file_name_prompt = “Please enter your configuration file name: “;
string config_file_name;
cout
getline(cin, config_file_name, 'n');
config_file_name = trim(config_file_name);
assert(config_file_name.length() > 0);

//open configuration file
ifstream config_file;
config_file.open(config_file_name.c_str());
assert(config_file.good());

//read initial number of sticks on pile
unsigned initial_sticks_on_pile;
config_file >> initial_sticks_on_pile;
assert(config_file.good() && initial_sticks_on_pile > 0);

//read maximum number of sticks to pick up
unsigned max_sticks_to_pickup;
config_file >> max_sticks_to_pickup;
assert(config_file.good() && 1

//void evaluate_parameters(initial_sticks_on_pile, max_sticks_to_pickup);

//read human player's name
string human_player_name;
config_file >> human_player_name;
human_player_name = trim(human_player_name);
assert(human_player_name.length());

config_file.close();

srand(unsigned(time(NULL)));
const string play_prompt = “Do you want to play pickup sticks?”;
const string play_again_prompt = “Do you want to play pickup sticks again?”;
string answer;
cout
cin >> answer;
;

bool choose_play_game = answer_convert(answer);
//answer = toupper(answer);
//answer = trim(answer);
while(choose_play_game == true)
{
playPickupSticks(human_player_name,
initial_sticks_on_pile,
max_sticks_to_pickup);
cout
cin >> answer;
answer = toupper(answer);
}
system(“pause”);
return 0;
}
string toupper(string& original)
{
unsigned length = original.length();
string edited = “”;
for(unsigned pos = 0; pos
{
char c = original[pos];
c = toupper(c);
edited = edited + c;
}
return edited;
}

string trim(string& original)
{
int left = 0;
int right = original.length() – 1;
while(left
left++;
while(left
right–;
string edited = original.substr(left, right – left + 1);
return edited;
}
bool answer_convert(string& original)
{
bool true_or_false;
original = trim(original);
original = toupper(original);
if(original == “Y”)
true_or_false = true;
else if(original == “YE”)
true_or_false = true;
else if(original == “YES”)
true_or_false = true;
else
true_or_false = false;
return true_or_false;
}
int randomInt(int lower, int upper)
{
if(upper
{
int t = upper;
upper = lower;
lower = t;
}
int range = upper – lower + 1;
int number = rand() % range + lower;
return number;
}
/*void evaluate_parameters(unsigned& total_sticks, unsigned& max_pick_up)
{
if(total_sticks % (max_pick_up + 1))
max_pick_up = max_pick_up + 1;

cout

}
*/

void playPickupSticks(const string& human_player_name,
unsigned initial_sticks_on_pile,
unsigned max_sticks_to_pickup)
{
string computer_player_name = “The Computer”;

unsigned sticks_on_pile = initial_sticks_on_pile;
vector computeSticksToPickup;
vector player_names;
computeSticksToPickup.push_back(humanComputeSticksToPickup);
computeSticksToPickup.push_back(computerComputeSticksToPickup);
player_names.push_back(human_player_name);
player_names.push_back(computer_player_name);

cout
unsigned player_id = randomInt(0,1);
do
{
//select next player
player_id = (player_id + 1) % 2;

unsigned sticks_to_pickup;

cout
sticks_to_pickup = computeSticksToPickup[player_id](sticks_on_pile, max_sticks_to_pickup);
cout
sticks_on_pile = sticks_on_pile – sticks_to_pickup;
cout
}
while(sticks_on_pile > 0);
cout
}
unsigned humanComputeSticksToPickup(unsigned sticks_on_pile, unsigned max_sticks_to_pickup)
{
unsigned local_max_sticks_to_pickup = min(sticks_on_pile, max_sticks_to_pickup);
unsigned sticks_to_pickup;
cout
cin >> sticks_to_pickup;
while(!cin.good() || sticks_to_pickup == 0 || sticks_to_pickup > local_max_sticks_to_pickup)
{
if(!cin.good())
{
cin.clear();
cin.ignore(numeric_limits::max(), 'n');
cout
}
else
{
cout
}
cout

cin >> sticks_to_pickup;
}
return sticks_to_pickup;
}
unsigned computerComputeSticksToPickup(unsigned sticks_on_pile, unsigned max_sticks_to_pickup)
{
unsigned sticks_to_pickup;
unsigned local_max_sticks_to_pickup = min(sticks_on_pile, max_sticks_to_pickup);
if(sticks_on_pile % (max_sticks_to_pickup + 1) == 1)
{
sticks_to_pickup = rand() % local_max_sticks_to_pickup + 1;
}
else
{
sticks_to_pickup = local_max_sticks_to_pickup + 1;
do
{
sticks_to_pickup = sticks_to_pickup – 1;
}
while((sticks_on_pile – sticks_to_pickup) % (max_sticks_to_pickup + 1) != 1);
}
return sticks_to_pickup;
}

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now