Write a function called initscores to open the file

Assignment Help Software Engineering
Reference no: EM13324642

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: EM13324642

Questions Cloud

Evaluate equilibrium problem to calculate the ph : Solve an equilibrium problem (using an ICE table) to calculate the pH 1)a solution that is 0.13M in NH3 and 0.15M in NH4Cl 2) 185.0 mL of 0.12M C2H5NH2 with 265 mL of 0.20M C2H5NH3Cl
Provides adequate definition of strong inductive argument : Which of the following provides an adequate definition of a strong inductive argument?
Education published data from study of literacy among adults : In 2004 The U.S. Department of Education published data from a study of literacy among adults in the U.S. Adults were defined as people residing in the U.S.age 16 and older living in households or prisons. The study included 19,714 people living in h..
Explain the solution reaches equilibrium : A solution is made that is 1.1×10^?3 M in Zn(NO3)2 and 0.150 M in NH3. After the solution reaches equilibrium, what concentration of Zn2+(aq) remains
Write a function called initscores to open the file : Write a function called initScores to open the file and returns the list scores with the numbers in the text file.
What is your real rate of return : If you earned a rate of return of 6% on your bond investments last year. During that time the inflation rate was 1.8%. What is your real rate of return?
How to to play in a novice or expert mode : 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.
Explain potassium hydroxide is used to precipitate : 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 - 2.8*10^-3 M Fe(NO3)2 B - 1.6*10^-3 M MgBr2
What is the percent uncertainty in the measurement : An experimental measurement has a result 7.95 +- 0.01, and a predicted value of 8.00. What is the percent uncertainty in the measurement

Reviews

Write a Review

Software Engineering Questions & Answers

  How the verify method can be used to plan out system

Analyze how the verify method can be used to plan out system effectively and ensure that the number of transactions do not produce record-level locking while the database is in operation.

  Software management

SOFT337 – Software Management, Demonstrate the  ability to investigate, gather appropriate sources, analyse, evaluate key challenges and discuss future trends within the chosen area of your choice .

  Write down critical success factors for project manager

Write down the critical success factors for project manager? what skills must managers look for when hiring someone who would be successful in this job?

  Describe the issues central to ensuring quality of software

Minimum number of words 500, referencing with Harvard style and the number of references not less than three Academic Articles or books.

  Identify the principal for viewpoint hierarchy diagram

Identify the principal viewpoints which might be taken into account in the specification of this system and organize these using a viewpoint hierarchy diagram.

  Sketch the dependency diagram

Sketch the dependency diagram. There are suitable examples in reading assignments of dependence diagrams. In what normal form is this table? Describe why.

  How to sketch flow chart to read employee master file

How to sketch flow chart to read employee master file and to output number of employees in each department who have a basic degree.

  Process of modeling using entity-relationship diagrams

Process of starting with world objects and modeling by using entity-relationship diagrams is referred to as top-down process.

  Software development practices

Agile Development is a blanket term that covers a wide variety of software development practices many of which have been codified and documented.

  For the prototype user interface

For the prototype user interface, design a switchboard that leads from main sections to sub-sections of related system tasks. The main sections may include member information, registration, payments

  Define complete professional-development requirements

Once an activity has been completed, employees will use the system to submit the documentation. The system should support notifications to management personnel whenever their direct reports have submitted documentation. The system should also noti..

  Sketch the eer diagram for unique number and single location

A department controls number of projects, each of which has unique name, unique number, and a single location. Sketch the EER Diagram for this situation.

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