Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I got stuck in my programming assignment. Please help. I will provide the assign

ID: 3621358 • Letter: I

Question

I got stuck in my programming assignment. Please help. I will provide the assignment description as well as my code. I do try, but it doesn't work out.

Assignment: The game of Nim has two players alternately taking marbles from a pile. In each move the player must take at least one marble, but at most half of the marbles in the pile. The player who takes the last marble loses. Write a program in which the computer plays against a human opponent. Generate a random integer between 10 and 100 (inclusively) to denote the initial size of the pile of marbles. Generate a random integer between 0 and 1 to decide whether or the computer or the human takes the first turn. Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid. In stupid mode, the computer simply takes a random legal value between 1 and n/2 from the pile whenever it has a turn. In smart mode, the computer takes off enough marbles to make the size of the pile a power of 2 - 1 ---that is, 3, 7, 15, 31, or 63. That is always a legal move, except if the size of the pile is one less than a power of 2. In that case the computer makes a random legal move. Note that the computer can not be beaten in smart mode when it has the first move, unless the pile size happens to be 15, 31, or 63.

This is my code:
int main()
{
cout << "Welcome to the game of Nim!" << endl;
srand(time(NULL));
int initial_size = rand() % 91 + 10;
cout << "The initial size of the pile is " << initial_size << endl;

int turn = rand() % 2 + 0;
cout << "The first turn belongs to ";
if(turn==0)
{
cout << "computer." << endl;
}
else
{
cout << "you. Goodluck!" << endl;
}

int computer_play = rand() % 2 + 0;
cout << "The computer plays ";
if(computer_play==0)
{
cout << "smart." << endl;
}
else
{
cout << "stupid." << endl;
}

int number;
int current_marbles = initial_size;
while(turn==1);
{
cout << " *** Computer moves." << endl;
cout << "Pile of marbles: " << current_marbles;
current_marbles -= number;
if(computer_play==0)
{
int n;
number = pow(2, 1) - 1;
}
else
{
number = rand() % (current_marbles / 2) + 1;
}
cout << endl;
cout << "Computer chooses to remove: " << number << " marbles. ";
cout << "***Removing " << number << " marbles from the pile. ";
cout << "Now pile of marbles is: " << current_marbles << endl;
for(int i=1;i<=30;++i)
{
cout << "+";
}
}
while(turn==0)
{
cout << endl;
cout << " *** Now you have to move. ";
cout << "Piles of marbles: " << current_marbles - number << endl;
cout << "Please enter number of marbles you want to take: "
<< "(at least one and at most half of the marbles) ";
cin >> number;
if(number<=0 || ((number > (current_marbles/2)) && (number !=1)))
{
cout << "***Bad move for you. You lose. ";
}
else
{
current_marbles -= number;
cout << "*** Removing "<< number <<" marbles from the pile. ";
cout << " Now pile of marbles is " << current_marbles << endl;
}
for(int i=1;i<=30;++i)
{
cout << "+";
}
}
cout << endl;
return 0;
Please help

Explanation / Answer

hey contact me at cuttup665@gmail.com