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. + + +
-
For its description of the reflected intensity of light normally incident on an interface between two transparent media (a) When light is normally incident on an interface between vacuum and a...
-
Chianti Company manufactures airbrake systems for long-haul trucks. The prime cost to produce one system is $800, the conversion cost is $400, and the total manufacturing cost is $1,000. Required:...
-
The five countries that have won the FIFA World cup more than once include Uruguay (2), Italy (4), Germany (4), Brazil (5), and Argentina (2). Use a Pareto chart to display the data. Organize the...
-
The following transactions and adjusting entries were completed by Legacy Furniture Co. during a three-year period. All are related to the use of delivery equipment. The double-declining-balance...
-
BRT Ltd's financial statements show the following figures: Sales revenue $240.29 million Net Income $65.53 million Total Assets $204 million Return on equity 12.24% Cash dividend paid $38.15 million...
-
Anil, along with his wife, Billy, and family friend, Charlie, started a property development business in 2015. The main activities of the business are to purchase land and develop buildings, and sell...
-
If the period of a sound wave is 10s, what is its frequency? (assume its speed is 343m/s) . What is the wavelength?
-
Selected financial data for Skysong Inc. and Concord Ltd. (in $ thousands) a Statement of Income Total revenue Cost of sales Gross profit Operating expenses. Profit from operations Interest expense...
-
Discuss the terms multitasking , multiprocessing , and multithreading . Give an example of each to illustrate your thoughts?
-
What leadership practices can be implemented to help prevent or mitigate these challenges? Which aspects of cross-cultural leadership do you think would be the most effective when applied to criminal...
-
Which of the following statements with regard to the ITA 54 definition of a principal residence is correct? Choose the correct answer. A. The definition of principal residence excludes land,...
-
Which of the following is/are correct? 3a non abelian group in which all proper subgroups are cyclic 7 any infinite group in which every element is of finite order and self inverse 3a infinite group...
-
Air pollution generated by a steel mill is an example of a) a positive production externality. b) a negative production externality. c) a public good. d) the free-rider problem. State and local taxes...
-
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...
-
If rp is positive in Equation 14.9, then foreign assets are perceived as being more risky than domestic counterparts. In that case, according to Equation 14.9, what will happen to the exchange rate...
-
Consider the monetary approach to exchange rates (MAER) model given in Equation 15.19. Suppose that each of the domestic hat variables in that equation is growing at exactly the same rate as its...
-
Philip and Lance have decided to form a partnership by investing \($100000\) and \($80000\) respectively. The following plans for dividing profits and losses are under consideration. Sharing profits...
Study smarter with the SolutionInn App