Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you explain this program in detail. It is the game of NIM where each player picks up 1-4 sticks from a pile of 22.
can you explain this program in detail. It is the game of NIM where each player picks up 1-4 sticks from a pile of 22. I just want to know hpw it works in detial. Thank you
in c++
//NIM game between two players with 22 sticks #include
#include using namespace std;
int main ()
{
// declaring variables
const int total = 22; bool winner;
string play_again = "y";
int n, mtotal;
while(play_again == "y") {
winner = false;
mtotal = total;
do
{
//Turn for the player 1 to choose the stick (s)
if (mtotal > 0)
{
cout
cout
cin >> n;
if (n >= 1 && n
cout
mtotal -= n;
}
else
{
cout
} if (mtotal
{
winner = true;
cout
}
//turn for the player 1 to choose the stick(s)
if (mtotal > 0)
{
cout
cout
cin >> n;
if (n >= 1 && n
{
cout
mtotal -= n;
}
else
{
cout
}
if (mtotal
{
winner = true;
cout din wardee oli tuta play Wales si total: urn for the player 1 to choose the It metal 1- pics LE out 1 ale Toen for de player to choose the al cut cin LE wekis" Et I. ay in your out you want to play wala ein >> play De 1 //NIM game between two players with 22 sticks #include #include using namespace std; int main() { 1/declaring variables const int total - 22; bool winner string play again - "y": int n, mtotal; while(play again y) winner = false; mtotal - total; do 1/Turn for the player 1 to choose the stick(s) 1 (mtotal > 0) { cout > it in 166 C4) { cout turn for the player 1 to choose the stick(s) 11 (total > 0) cout > if (n >= 1 L cin >> play again; } return 0; >
}
}
}while(!winner);
//Play again if you love this game
cout
7:46 LTET Rame between the players with include cin >> play_again;
}
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