Question

In: Computer Science

Python The goal of this assignment is to build a simulation of a popular children’s dice...

Python

The goal of this assignment is to build a simulation of a popular children’s dice game named Beat That. Beat That is an educational game in which children learn strategic thinking and the concept of place value. While the rules of the game can be flexible, we will be playing a basic version in which 2 players (Player A and Player B) are rolling 2 dice in a 5-round game.

Game play is based on rounds. In each round, players take a turn in which they roll 2 dice. After rolling the dice, the player decides how to use the two dice values to form a 2-digit number. The goal is to arrange the digits so that they form the highest number possible. Since you are developing your computer programming skills rather than your number literacy skills, your program will automatically make the choice for the player – choosing the highest of the two possible combinations as the player’s number choice for that round. In choosing for the player in this manner you are simulating the play of expert player of Beat That rather than simulating the play of a novice.

At the close of the round, your program will compare players’ number choices for that round to determine the round scoring. The player with the highest number choice wins the round. There are 3 possible scoring outcomes of a round:

• The Players Tie this Round • Player A Wins this Round • Player B Wins this Round

The program will print a message to announce the outcome of the round.

The player who wins a round scores 1 point in the overall game. The player who loses the round does not score a point in the overall game.   If the players are tied for the round, then neither player scores a point in the overall game.

When 5 rounds have been played, the program will determine the outcome of the overall game based upon points earned. There are 3 possible outcomes of a game:

• The Players Tie the Game • Player A Wins the Game • Player B Wins the Game

The python program will print a message to announce the outcome of the game. Based upon the description above, the program should implement the functionality for playing a 5-round game of Beat That.  

When coding and testing this program, follow the approach that I take in the second part of the tutorial video where I design and build a program that simulates a multi-round Coin Toss game.

When this program is run, the console session should look like this:
Playing round 1 of Beat That... Player A rolls (2, 1) Player A chooses 21 Player B rolls (5, 2) Player B chooses 52 Player B Wins This Round!
Playing round 2 of Beat That... Player A rolls (2, 2) Player A chooses 22 Player B rolls (1, 5) Player B chooses 51 Player B Wins This Round!
Playing round 3 of Beat That... Player A rolls (4, 2) Player A chooses 42 Player B rolls (6, 1) Player B chooses 61 Player B Wins This Round!
Playing round 4 of Beat That... Player A rolls (6, 4) Player A chooses 64 Player B rolls (4, 2) Player B chooses 42 Player A Wins This Round!
Playing round 5 of Beat That... Player A rolls (2, 5) Player A chooses 52 Player B rolls (1, 5) Player B chooses 51 Player A Wins This Round!

7
Game score: Player A has won 2 rounds. Player B has won 3 rounds. Player B Wins This Game!
Before finishing your work . Please remember to apply refactoring and retesting steps

Solutions

Expert Solution

from random import randint

def startGame(round,p1Name,p2Name,p1Wins,p2Wins):
print("\nPlaying round", round ,"of Beat That...")
print(p1Name,"rolls")
p1 = rollDice(p1Name)
print(p2Name,"rolls")
p2 = rollDice(p2Name)
if p1 > p2:
print(p1Name,"Wins this Round!")
p1Wins += 1
elif p2 > p1:
print(p2Name,"Wins this Round!")
p2Wins +=1
else:
print("The Players Tie this Round")
return p1Wins,p2Wins

def maxNumber(num):
a = []
for i in range(len(num)):
a.append(max(num))
num.remove(max(num))
maxNum = ''.join(map(str,a))
return maxNum

def getDiceRollValue(numOfDice):
num = []
for i in range(numOfDice):
a = randint(1, 6)
num.append(a)
return num

def rollDice(playerName):
rollValue = getDiceRollValue(numOfDice)
print(rollValue)
maxNumOutofRoll = maxNumber(rollValue)
print(playerName, "chooses",maxNumOutofRoll)
return maxNumOutofRoll

def winner(p1Name,p2Name,p1Wins,p2Wins):
print("Game Score:",p1Name,"has won",p1Wins,"rounds.",p2Name,"has won",p2Wins,"rounds.")
if p1Wins > p2Wins:
print(p1Name,"Wins This Game!")
elif p2Wins > p1Wins:
print(p2Name,"Wins This Game!")
else:
print("The Players Tie the Game")

numOfDice = 2
numOfRounds = 5
p1Name = "Player 1"
p2Name = "Player 2"
p1Wins = 0
p2Wins = 0
for i in range(1,numOfRounds+1):
p1Wins,p2Wins = startGame(i,p1Name,p2Name,p1Wins,p2Wins)

winner(p1Name,p2Name,p1Wins,p2Wins)



Related Solutions

The assignment is to build a program in Python that can take a string as input...
The assignment is to build a program in Python that can take a string as input and produce a “frequency list” of all of the wordsin the string (see the definition of a word below.)  For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words.  In the output, each line contains of a...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
a) Three fair dice are tossed 1000 times. Create a simulation of these 1000 tosses, and...
a) Three fair dice are tossed 1000 times. Create a simulation of these 1000 tosses, and compute the probability that the sum of the three dice 7 or less. (Hint: randbtween) b) Mike and Monica arrive randomly at the golf course between 8am and 10am. What is the probability they arrive within 30min of each other? (Hint: 120*rand() ?)
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Create a simulation layout for rolling three dice 627 times. Calculate the probability of the three...
Create a simulation layout for rolling three dice 627 times. Calculate the probability of the three adding to 11. Use Excel and show formulas used
Create a simulation layout for rolling 3 dice 627 times. Calculate the probability of the 3...
Create a simulation layout for rolling 3 dice 627 times. Calculate the probability of the 3 adding to 11. ***Use Excel and show formulas used***
I need to build a simple model of a coffee shop using Arena simulation
I need to build a simple model of a coffee shop using Arena simulation
Verification and Validation of Simulation Models 3. How to build a model that is well connected...
Verification and Validation of Simulation Models 3. How to build a model that is well connected with the verification and validation process? 4. What is meant by calibration, and what is the process of calibration so that it can obtain a model that means to be used for simulation?
Simulation 5 Use the attached template to build an Excel spreadsheet for a purchase of $1,000,000...
Simulation 5 Use the attached template to build an Excel spreadsheet for a purchase of $1,000,000 face value, 6% 5-year bond with interest payments every 6 months. Market interest rate is 5%. Include the following items: Inputs: Bond initial purchase amount Stated Interest Rate Maturity in Years Number of payments/year Market interest rate Calculations section 1: --Fair value with separate calculations for interest and principal --Discount or premium --Record the journal entry required when the bonds are purchased. Calculations Section...
1.- In this assignment you will implement a simulation of the interaction of user programs with...
1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation on two different devices. User programs: User programs will communicate with DOIO (OS) to request an I/O operation. (This will simulate a system call) User programs will give to DOIO three parameters: User id, device number (dev is a random number in the range 1 and 2 that represents device one or device two) and an address...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT