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

Write a program for playing the game of Nim. The game of Nim starts with three h

ID: 3626429 • Letter: W

Question

Write a program for playing the game of Nim. The game of Nim starts with three
heaps and a fixed number of objects in each heap. Two players take turns removing
objects from the heaps. On a players turn, she chooses a heap and removes one or
more objects from that heap. She can remove all the objects from the heap. In our
version of the game of Nim, the player who takes the last object from the heaps (so
that all heaps are empty) wins. (See www.wikipedia.org for further discussion of the
game.)
The algorithm for the game of Nim is provided below. Most steps in the algorithm should be implemented as function calls. You need to implement the algorithm and
the function calls as described below. You need to implement each function. You may
and should also implement additional functions to help you in writing For instance, to
implement the function which draws the heaps you should implement a function
which draws a row representing a single heap and call that function three times, once
for each heap.
Implement the following algorithm for the game of Nim. Each line of the algorithm
should be implemented as a call to a single function. Implement the algorithm one
function at a time, writing the function, checking that it compiles and runs properly
and then implementing the next function.
(1) Prompt and read number of elements in each heap;
(2) Draw the heaps;
(3) while (some heap is NOT empty) do
(4) Prompt and read the next player move. (Prompt and read the heap to modify and
the number of elements to remove from the heap.);
(5) Remove the specified number of elements from the specified heap;
(6) if (all heaps are empty) then
(7) Print a message congratulating the winning player.
(8) Else
(9) Redraw the heaps;
(10)Change to the other player;
(11)end
(12)end

Here is my program...

#include<iostream>
#include<string>
#include <iomanip>
#include<cmath>
using namespace std;


void SetParamters(int&, bool&); //prompts user for paramters
void FillBoard(int, char[]);
void PrintBoard(char [], int);
void ComputerTurn(char [], int&, int);
void HumanTurn(char[], int&, int);




int main ()
{
int pieces,size, piecesSlection=0;
char GamePieces[20];
bool COMPUTER_TURN=false;


SetParamters(pieces, COMPUTER_TURN);
size=pieces-1;
FillBoard(pieces, GamePieces);
//PrintBoard(GamePieces, pieces);
do
{
if (COMPUTER_TURN==true)
{
ComputerTurn(GamePieces, piecesSlection, pieces);
PrintBoard(GamePieces,pieces);
COMPUTER_TURN=false;
}
else
{
HumanTurn(GamePieces, piecesSlection, size);
PrintBoard(GamePieces,pieces);
COMPUTER_TURN=true;
}
}while (GamePieces[0]!='_');//needs adjustment


return 0;
}

void SetParamters(int& pieces, bool& COMPUTER_TURN)
{
char answer;
cout<<"Welcome To NIM"<<endl<<endl;
do
{

cout<<"How many pieces would you like to start with?"<<endl;
cin>>pieces;
if (pieces<5||20<pieces)

cout<<"You can only choose a number between 5 and 20 try again."<<endl<<endl;

}while(pieces<5||20<pieces);

cout<<"Would you like to go first? (Y/N)";
cin>>answer;
if (answer=='y'||answer=='Y')
{
cout<<"OK, you can go first."<<endl;
COMPUTER_TURN=false;
}


else
{
COMPUTER_TURN=true;
cout<<"OK, I will go first."<<endl;
}


}
void FillBoard(int pieces, char GamePieces[])
{
for (int i=0; i<pieces;i++)

GamePieces[i]='o';

}
void PrintBoard(char GamePieces[], int pieces)
{
cout<<endl<<endl<<"HERE IS OUR CURRENT BOARD"<<endl<<endl;

for (int i=0; i<pieces; i++)
cout<<left<<setw(3)<<i;
cout<<endl;
for (int i=0; i<pieces; i++)
cout<<setw(2)<<GamePieces[i]<<' ';
cout<<endl;


}
void ComputerTurn(char GamePieces[], int& piecesChoice, int pieces)
{
int computerMove= piecesChoice+1;
cout<<endl<<endl<<"OK, ITS MY TURN!"<<endl;
if (computerMove<=pieces&&GamePieces[computerMove]!='_')
GamePieces[computerMove]='_';
}
void HumanTurn(char GamePieces[],int& piecesSlection, int size)
{
char answer, count=0;

cout<<"It's Your turn! Which Pieces Would you like?";
do{
cin>>piecesSlection;
count=count++;
if (piecesSlection>size||GamePieces[piecesSlection]=='_')
{
do
{
cout<<"This is an illegal move ";
cout<<"Please enter anthor number ";
cin>>piecesSlection;


}while(piecesSlection>size||GamePieces[piecesSlection]=='_');
}
GamePieces[piecesSlection]='_';
cout<<"Would you like anthor? ";
cin>>answer;
if(answer=='y'&&count<3||answer=='Y'&&count<3)
cout<<"Please enter your choice ";
if(count>2)
cout<<"You have reached the limit. You are only allowed three."<<endl;
}while(answer=='y'&&count<3||answer=='Y'&&count<3);
}

Can somebody help me get this to work

Explanation / Answer

#include #include #include #include using namespace std; int compChoose(int counters); int userChoose(int counters); bool whoseTurn(); // Generate random numbers that is between 1 and 3 int random() { int random; random=(rand()%(3-1+1)+1); return random; } int main() { //total counters // const int NUM_COUNTERS = 13; //declare variables string player; int counters; srand((unsigned)time(NULL)); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote