The purpose of this lab assignment is Problem Statement: 1. In Project 1, you will...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The purpose of this lab assignment is ● Problem Statement: 1. In Project 1, you will write a program to simulate a simple game named Nim: two players alternately take marbles from a pile. In each turn, a player must make a legal move taking at least one but at most half of the marbles from the pile and then let the other player take a turn. The player who is to take the last marble loses the game. to continue practicing how to define your own functions to help you make big progress with Project 1 This Lab assignment will help you solve two sub-problems of Project 1: complete the definitions of TWO functions, named computer_play and printMarbles, shown as follows: /* * It represents the legal move when it is the computer's turn to play The computer takes "smart strategy" trying to win the game: (1) if the current pile size is not a Power-of-Two-minus-One, it * takes * ★ it ★ enough marbles to make the remaining size a Power-of-Two- (2) if the current pile size is already a Power-of-Two-minus-One, minus-One makes a random move taking at least one but at most half *@param pile int&: the pile size before and after the computer's turn, call by reference *@return: void function */ void computer_play (int& pile) It represents the legal move when it is the computer's turn to play Nim game. The computer always takes "smart strategy" trying to win the game. Under "smart strategy", the computer needs to make the following legal move to win the game: (1) take off enough marbles to make the size of the remaining pile a Power-of-Two-minus-One (1, 3, 7, 15, 31, and so on, are some examples of the Power-of-Two-minus-One) if the current pile size is not one of those Power-of-Two-minus-One; (2) When the current pile size is already a Power-of-Two-minus-One, make a random move taking at least one but at most half of the marbles. *** void computer_play (int& pile) It represents the legal move when it is the computer's turn to play Nim game. The computer always takes "smart strategy" trying to win the game. Under "smart strategy", the computer needs to make the following legal move to win the game: (1) take off enough marbles to make the size of the remaining pile a Power-of-Two-minus-One (1, 3, 7, 15, 31, and so on, are some examples of the Power-of-Two-minus-One) if the current pile size is not one of those Power-of-Two-minus-One; (2) When the current pile size is already a Power-of-Two-minus-One, make a random move taking at least one but at most half of the marbles. After each legal move either from the computer or the human player, your program should display the number of marbles on current pile (you are required to use constant named MARBLE to display on screen: cout << MARBLE; and it represents a single marble on the pile). Complete the definition of the following function: /* * It displays the marbles on the pile: the number of marbles depends on passing in parameter *@param pile int: representing how many marbles are on the pile to display *@return: void function void printMarbles (int pile) #include <iostream> #include <ceath> #include <cstdlib> #include <ctine> #include <iomanip> using namespace std; // define some constants const int PILE MAX= 50; const int PILE MIN = 10; const char MARBLE static castechar(232); //use code 232 in ASCII Table to represent sarble const int WIDTH= 10; // for Layout purpose const int PILE SIZE TEST 50; //the pile size for testing purpose in Labs only // void printfarbles(int pile) \\ It displays the sarbles on the pile: the number of marbles depends on passing in parameter paran pile int: representing how many marbles are on the pile to display @return: void function [/ // display marbles on the pile void printfarblegint pile); // void computer.play(int& pile) \\ It represents the legal move when it is the computer's turn to play The computer takes "snart strategy" trying to win the game: (1) if the current pile size is not a Poser-of-Teo-sinus-One, it takes enough marbles to make the remaining size a Power-of-Two- minus-One I (2) if the current pile size is already a Power-of-Two-minus-One, it makes a randon move taking at least one but at most half @param pile int&: the pile size before and after the computer's turn, call by reference @return: void function */ // represent the legal move when it is the computer's turn to play the game void computer play (int& pile); int pilesize= PILE_MAX; while (pilesize >= 1) if (pilesize == ) Bint main() int seed static_castint>(time(0)); srand(seed); // Generate the initial size of pile (of marbles) // at the range of [PILE MIN, PILE_MAX] // for testing purpose only: we "hard-code" the initial size of pile to a constant PILE_SIZE_TEST int pilesize PILE_SIZE_TEST; // comment out the testing purpose at line number 40, enable the following statement, which is the general case //int pileSize = PILE MIN + rand() (PILE MAX - PILE MIN + 1); cout << *************** cout < cout << cout << " In combinatorial game theory: a two-player deterministic perfect information turn-based game cout << is a first-player-win, if with perfect play the first player to move, always force a win cout << I will show you (not prove to you) that cout Phot " the game of Nin is a CONDITIONAL first-player-win game :) The name of Min 2 A **** << endl; << endl; << endl; << endl; << en << endl; "<<endl; see and The purpose of this lab assignment is ● Problem Statement: 1. In Project 1, you will write a program to simulate a simple game named Nim: two players alternately take marbles from a pile. In each turn, a player must make a legal move taking at least one but at most half of the marbles from the pile and then let the other player take a turn. The player who is to take the last marble loses the game. to continue practicing how to define your own functions to help you make big progress with Project 1 This Lab assignment will help you solve two sub-problems of Project 1: complete the definitions of TWO functions, named computer_play and printMarbles, shown as follows: /* * It represents the legal move when it is the computer's turn to play The computer takes "smart strategy" trying to win the game: (1) if the current pile size is not a Power-of-Two-minus-One, it * takes * ★ it ★ enough marbles to make the remaining size a Power-of-Two- (2) if the current pile size is already a Power-of-Two-minus-One, minus-One makes a random move taking at least one but at most half *@param pile int&: the pile size before and after the computer's turn, call by reference *@return: void function */ void computer_play (int& pile) It represents the legal move when it is the computer's turn to play Nim game. The computer always takes "smart strategy" trying to win the game. Under "smart strategy", the computer needs to make the following legal move to win the game: (1) take off enough marbles to make the size of the remaining pile a Power-of-Two-minus-One (1, 3, 7, 15, 31, and so on, are some examples of the Power-of-Two-minus-One) if the current pile size is not one of those Power-of-Two-minus-One; (2) When the current pile size is already a Power-of-Two-minus-One, make a random move taking at least one but at most half of the marbles. *** void computer_play (int& pile) It represents the legal move when it is the computer's turn to play Nim game. The computer always takes "smart strategy" trying to win the game. Under "smart strategy", the computer needs to make the following legal move to win the game: (1) take off enough marbles to make the size of the remaining pile a Power-of-Two-minus-One (1, 3, 7, 15, 31, and so on, are some examples of the Power-of-Two-minus-One) if the current pile size is not one of those Power-of-Two-minus-One; (2) When the current pile size is already a Power-of-Two-minus-One, make a random move taking at least one but at most half of the marbles. After each legal move either from the computer or the human player, your program should display the number of marbles on current pile (you are required to use constant named MARBLE to display on screen: cout << MARBLE; and it represents a single marble on the pile). Complete the definition of the following function: /* * It displays the marbles on the pile: the number of marbles depends on passing in parameter *@param pile int: representing how many marbles are on the pile to display *@return: void function void printMarbles (int pile) #include <iostream> #include <ceath> #include <cstdlib> #include <ctine> #include <iomanip> using namespace std; // define some constants const int PILE MAX= 50; const int PILE MIN = 10; const char MARBLE static castechar(232); //use code 232 in ASCII Table to represent sarble const int WIDTH= 10; // for Layout purpose const int PILE SIZE TEST 50; //the pile size for testing purpose in Labs only // void printfarbles(int pile) \\ It displays the sarbles on the pile: the number of marbles depends on passing in parameter paran pile int: representing how many marbles are on the pile to display @return: void function [/ // display marbles on the pile void printfarblegint pile); // void computer.play(int& pile) \\ It represents the legal move when it is the computer's turn to play The computer takes "snart strategy" trying to win the game: (1) if the current pile size is not a Poser-of-Teo-sinus-One, it takes enough marbles to make the remaining size a Power-of-Two- minus-One I (2) if the current pile size is already a Power-of-Two-minus-One, it makes a randon move taking at least one but at most half @param pile int&: the pile size before and after the computer's turn, call by reference @return: void function */ // represent the legal move when it is the computer's turn to play the game void computer play (int& pile); int pilesize= PILE_MAX; while (pilesize >= 1) if (pilesize == ) Bint main() int seed static_castint>(time(0)); srand(seed); // Generate the initial size of pile (of marbles) // at the range of [PILE MIN, PILE_MAX] // for testing purpose only: we "hard-code" the initial size of pile to a constant PILE_SIZE_TEST int pilesize PILE_SIZE_TEST; // comment out the testing purpose at line number 40, enable the following statement, which is the general case //int pileSize = PILE MIN + rand() (PILE MAX - PILE MIN + 1); cout << *************** cout < cout << cout << " In combinatorial game theory: a two-player deterministic perfect information turn-based game cout << is a first-player-win, if with perfect play the first player to move, always force a win cout << I will show you (not prove to you) that cout Phot " the game of Nin is a CONDITIONAL first-player-win game :) The name of Min 2 A **** << endl; << endl; << endl; << endl; << en << endl; "<<endl; see and
Expert Answer:
Answer rating: 100% (QA)
c include stdio h include stdlib h include time h Function to check if a number is a poweroftwominus... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Describe and make a description about SM INVESTMENT CORPORATION. Then answer WHY SHOULD YOU INVEST IN THIS COMPANY? Elaborate and formulate a well structured explanation. You might want to consider...
-
The game of Nim. This is a well-known game with a number of variants. The following variant has an interesting winning strategy. Two players alternately take marbles from a pile. In each move, a...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Use the test of your choice to determine whether the following series converge. + + +
-
Repeat Problem 84, but do not assume r m.r
-
Describe a few differences between children's temperaments in different cultures and why those temperaments might benefit them in their environments. What factors influence?
-
Consider the delivery time data in Example 3.1. In Section 4.2.5 noted that these observations were collected in four cities, San Diego, Boston, Austin, and Minneapolis. Example 3.1 a. Develop a...
-
Compute the multifactor productivity measure for each of the weeks shown for production of chocolate bars. What do the productivity figures suggest? Assume 40-hour weeks and an hourly wage of $ 12....
-
Get the data set of these topologies from Internet Topology Zoo [1], download GML, GraphML files of DFN and AARNet topology. Using auto Mininet [4] convert them into .py format. Use any one topology...
-
WRITE IN PYTHON AND IN THE GIVEN CODE coderbyte medium Back-end Challenge In the Python file, write a program to perform a GET request on the route Time left: Unlimited time...
-
1. As an equipment manufacturing company, suppliers are a very important part of the operation. Can you discuss the supply chain and has any significant world events ever disturbed the supply chain?...
-
An electron \(\mathrm{e}^{-}\)and positron \(\mathrm{e}^{+}\)moving at the same speed in the Earth reference frame collide head-on and produce a proton \(\mathrm{p}\) and an antiproton...
-
Planets \(\mathrm{A}\) and \(\mathrm{B}\) are 10 light years apart in the reference frame of planet A. (One light year is the distance light travels in one year.) A deep-space probe is launched from...
-
Rolling a pair of dice and getting an outcome (sum) of 12. For Exercises 1118, use the theoretical method to determine the probability of the given outcome or event. State any assumptions that you...
-
Which of the following forms of energy contribute to the mass of a gas molecule: \((a)\) energy due to the molecule rotating about its center of mass, \((b)\) energy due to compression of atoms in...
-
A space colony defines the origin of a coordinate system in reference frame \(\mathrm{C}\), and you are at rest in this reference frame at position \(x=+3.000 \times 10^{5} \mathrm{~km}\). A ship...
-
Take the Implicit Association Test (IAT)at implicit.harvard.edu. (Links to an externalsite.) Feel free to go in through the anonymous guest optionrather than registering yourself. Choose an IAT that...
-
The following information is for Montreal Gloves Inc. for the year 2020: Manufacturing costs Number of gloves manufactured Beginning inventory $ 3,016,700 311,000 pairs 0 pairs Sales in 2020 were...
-
Write declarations for storing the following quantities. Choose between integers and floating-point numbers. Declare constants when appropriate. a. The number of days per week b. The number of days...
-
Resonant circuits are used to select a signal (e.g., a radio station or TV channel) from among other competing signals. Resonant circuits are characterized by the frequency response shown in the...
-
Draw a bulls eyea set of concentric rings in alternating black and white colors. Hint: Fill a black circle, then fill a smaller white circle on top, and so on. Your program should be composed of...
-
Plaintiff applied for a job at Neiman Marcuss Oak Brook, Illinois, store as an entry-level dress collections sales associate. Ohle was interviewed and was informed that she should expect an offer for...
-
Plaintiff Deborah Ehling was hired by Monmouth-Ocean Hospital Service Corp. (MONOC) in 2004 as a registered nurse and paramedic. Plaintiffs claims in this case arise out of an incident involving her...
-
Reynaldo Delgado died following an explosion at a smelting plant in Deming, New Mexico, after a supervisor ordered him to perform a task that, according to Delgados widow, was virtually certain to...
Study smarter with the SolutionInn App