Write a function playnovice

Assignment Help Software Engineering
Reference no: EM13324633

Part 1
You will implement a program where the computer plays against a human opponent. The game will start with a random number of marbles between 10 and 100. A random number between 0 and 1 will be used to decide who takes the first turn (0 computer, 1 human opponent) and the human opponent has to decide whether he or she wants the computer to play in a novice or expert mode. In the novice mode the computer will always take a random number between 1 and half of the marbles that there are in the pile at the moment whenever it is its turn. In the expert mode the computer always takes enough marbles to make the number of marbles left on the pile a power of 2 minus 1 (e.g, 3, 7, 31) except if the size of the pile is already one less than the power of 2. In that case the computer will take a random number of marbles. Note that the computer will always win in expert mode if it has the first turn but also a human opponent will always win if he or she knows the winning strategy.

Part 2
Once the game has been implemented you will use it for a Nim on-line Man-Machine competition. Every time that the game is played the result of the game will be updated in a text file. The file consists of two lines: the first line stores the times that the computer has won and lost and the second line the times that any human user has won and lost. At end of the competition the winner will be displayed. To make it more realistic you can ask some of your friends to play the game without telling them the winning strategy.

Question 1
Write a function playNovice(marbles) that given the number of marbles returns a random number between 1 and half of the number of marbles.

>>> playNovice(90)

35

Test your function several times with numbers between 10 and 100

Question 2
Write a function userPlay(marbles) that asks the user for the number of marbles that he or she would like to take and returns that number. The function should keep asking the user for the number of marbles if he or she takes more than half of the marbles.

Question 3
Write a program that creates one pile of marbles with a random number of marbles and decides who starts the game. The program will call userPlay when the user plays and playNovice when it is the computer turns.

Question 4
Modify the code of question 3 so the program keeps playing until there is only one marble left and inform at the end who has won the game.

Test that the program works by displaying the output of running the program.

Question 5
Write a function playExpert(marbles) that given a number of marbles returns the number of marbles that the computer will take following the expert mode rules. The number of marbles left on the pile will be a power of 2 minus 1 (e.g, 3, 7, 31) except if the size of the pile is already one less than the power of 2. In that case the computer will return a random number of marbles.
>>> playExpert(90)
27 (if computer takes 27 there will 90-27= 63 (26-
1) marbles left )

>>playExpert(31) number of marbles a power of 2 minus 1
12
Make sure that your tests show that the function works for both cases.

Question 6
Amend the program in question 4 so the user decides whether the computer plays in novice or expert mode.

Test that the program works by showing the results of playing using the two different modes.

Question 7
Update question 6 (or question 4 if you did not manage to implement playExpert) and a create a function called gameNim() that plays the game and returns 0 if the computer lost and 1 otherwise.

Question 8
Now you have to create a list called scores that stores 4 numbers: the first two numbers are the number of win and lost games for the computer and the other two for the human opponent. Create a text file called scores.txt with notepad with two lines: the first two lines are the computer scores and the second line human scores.

Write a function called initScores to open the file and returns the list scores with the numbers in the text file.

>>initScores(scores)
[0,0,0,0]

Test it by adding numbers manually in the text file

Question 9
Now write a function updateScores(scores) that saves the information on the list scores to the text file scores.txt

Question 10
Write a program that initializes the list scores with the values in the text file scores.txt and calls the gameNim() function, once the game has finished the list scores are updated with the results. The program will play as many games as the users wants. Once the user stops playing the scores.txt file is updated. That means that if you play the games again later, the scores list will start with the values stored in the file and not with all the scores to 0

Question 11
Add a function to display who has won the competition - the machine or the human opponents

Question 12: Analysis and results
Write a report about your final implementation and the results of testing the game. You should talk about:
- Whether or not you have managed to implement the playExpert mode of the game. If you do not manage to implement it you should carry on with the rest of the questions in novice mode.
- Any errors in your program.
- The testing of the final game by displaying the results of running the final game once.
- Results of the competition you should answer questions like: how many times did you play the game? How many people try the game? What can you extract from the final results? Is it the computer better than the human opponent?

Reference no: EM13324633

Questions Cloud

Examples of effective lobbying-electioneering : What are some recent examples of effective lobbying, electioneering, building coalitions, grassroots pressure, and litigation.
Explain what minimum concentration of na2so4 is required : Consider a solution that is 1.1*10^-2 M in Ba2+ and 2.0*10^-2 M in Ca2+. A - If sodium sulfate is used to selectively precipitate one of the cations while leaving the other cation in solution, which cation will precipitate first? Ba2+ precipitates..
Find how high will the ball go : A boy throws up a ball 15m/s, how high will the ball go and what is the duration (total time) in the air from throw to catch
Define the ph at the equivalence point in the titration : What is the pH at the equivalence point in the titration of 25.00 mL of 0.020 M NH3 with 0.015 M HBr? Kb for NH3 = 1.8 x 10^-5
Write a function playnovice : Write a function userPlay(marbles) that asks the user for the number of marbles that he or she would like to take and returns that number. The function should keep asking the user for the number of marbles if he or she takes more than half of the ..
How far from the base of the cliff does the car land : A stunt man drives a car at a speed of 20 m/s off a 24-m-high cliff. The road leading to the cliff is inclined upward at an angle of 20? How far from the base of the cliff does the car land
Find out the minimum concentration of koh : Potassium hydroxide is used to precipitate each of the cations from their respective solution. Determine the minimum concentration of KOH required for precipitation to begin in each case. A - 1.4*10^-2 M CaCl2 B - 2.8*10^-3 M Fe(NO3)2 C - 1.6*10^-..
What is the smallest value can have before the string breaks : A small sphere of mass m= 7.60 g and a charge q1 = 29.9 nC is attracted to the end of a string, what is the smallest value d can have before the string breaks
What are u.s. tax consequences of hans u.s. activities : During Year 1, Hans had rental income of $300,000 and operating expenses (depreciation, interest, insurance, etc.) of $220,000. On the advice of his accountant, Hans made a Code Sec. 871(d) election in Year 1.

Reviews

Write a Review

Software Engineering Questions & Answers

  Emergency control room for a call-logging component

Design the Requires and the Provides interfaces of at least two components that might be used in a system in an emergency control room for a call-logging component that records calls made.

  Determine the greatest magnitude negative number

Determine the greatest magnitude negative number one can represent in an 8-bit 2's complement code? Write your result in binary and decimal.

  Functional specifications for the software

When looking at a need for a change or improvement in a current system, what are two of the most important processes to examine and explain your answer.

  Write a program that asks the user

Are you really really sure you do not want to use this program? (y/n)

  Define the terms variable and constant

Discuss and define the terms "variable" and "constant" as used in computer programming. Estimate the many types of data that can be used in developing a solution.

  Explain code review methodology-walkthrough

As the quality assurance manager, which code review methodology-walkthrough or inspection-would you recommend? Justify your answer.

  Create high-level e-r diagram for hospital

Your first assignment is to work as part of the team of three persons to create high-level E-R diagram for hospital. You conduct interviews with number of hospital administrators and staff to recognize key entities.

  Describe what actions you would take and in what sequence

Consider a situation in which your team has just finished the design phase and is about to start coding. Your key applications designer just walked in and handed you a resignation notice.

  Use steganography to effectively hide one file

Steganography Lab. Create a file on your desktop using Notepad that will be hidden in the image.

  Find multicanonical monte carlo methods and rare growth

MATH7601: Project Descriptions. Multicanonical Monte Carlo Methods and Rare Growth Factors. One of the big unsolved research problem in Gaussian elimination is the question of backward stability. Even with partial pivoting examples are known.

  Poor database mission statement

Use internet to find an example of what you think is a good database mission statement. Then, find an example of what a poor database mission statement.

  Creating a pseudocode

Suppose you are the manager of a company and have list of workers with the number of days they were absent from work.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd