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. + + +
-
Sam computed a 95% confidence interval for m from a specific random sample. His confidence interval was 10.1 < < 12.2. He claims that the probability that is in this interval is 0.95. What is wrong...
-
Spam imposes significant negative externalities on email users (see the Application "Negative Externalities from Spam). If the sender had to pay a small fee for each email, would the extent and...
-
Sessions Athletic Gear borrowed \($5,000,000\) from its parent, PF Consolidated Inc., at an interest rate of 5%. The loan was made on September 30, 2016, with interest due semiannually on March 31...
-
Pet Luggage Company makes two pet carriers, the Cat-allac and the Dog-eriffic. They are both made of plastic with metal doors, but the Cat-allac is smaller. Information for the two products for the...
-
During one week, four production employees of Morgan Manufacturing Company worked the hours shown below. All these employees receive overtime pay at one and one-half times their regular hourly rate...
-
Should Best Buy focus on becoming a showroom for companies that lack their own physical retail outlets? What are the pros and cons of this approach?
-
Melanie is a small business owner. Her financial year ends on 31st December. She uses a single column cash book and a petty cash book. The imprest amount for her petty cash book is $500. All payments...
-
What is the difference between a cost object's direct cost and its full cost? Provide an example in a healthcare organization context. Be specific about the type of healthcare organization that you...
-
The par level for coffee beans is to hold 19kg. There are only 10 kg left. What should be the reorder quantity be in kg? Please show the process with formula.
-
Provide an example where you compared good and services by its value and compared perceived benefits and price? How dod your assessment of value led to purchase decision? Do you think you will be...
-
A company produces and sells a single product. Budgeted sales are $2.4 million, budgeted fixed costs are $360,000 and the margin of safety is $400,000. What are budgeted variable costs?
-
The related data of Dindi Company: Unit sold12,000 Units produced10,000 Total direct materialsP589,000 Total direct labor325,000 Total variable overhead375,000 Total fixed overhead167,000 Total...
-
Calculate the following: a) current assets b) property, plant and equipment c) intangible assets d) non current investments e) total assets f) current liabilities g) non current liabilities h) total...
-
How can a promoter avoid personal liability for pre-incorporation contracts?
-
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...
-
A survey of U.S. adults found that 69% have a favorable view of farming and agriculture. You randomly select 45 U.S. adults and ask whether they have a favorable view of farming and agriculture. A...
-
Thirty-four percent of U.S. college graduates work in jobs that do not require a college degree. You randomly select 20 U.S. college graduates. Find the probability that the number working in a job...
-
Find the probability that the number who feel they have little or no control over data collected about them by companies is (a) at most 200, (b) less than 210 , and (c) exactly 202 . Identify any...
Study smarter with the SolutionInn App