Question

Please write the program in python: 3. Design and implement a simulation of the game of...

Please write the program in python:

3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like
racquetball, in that a team can only score points when it is serving. Games are played to 15,
but must be won by at least two points.

7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If
the initial roll is 2, 3, or 12, the player loses. If the roll is 7 or 11, the player wins. Any other
initial roll causes the player to “roll for point.” That is, the player keeps rolling the dice until
either rolling a 7 or re-rolling the value of the initial roll. If the player re-rolls the initial value
before rolling a 7, it’s a win. Rolling a 7 first is a loss.
Write a program to simulate multiple games of craps and estimate the probability that the
player wins. For example, if the player wins 249 out of 500 games, then the estimated
probability of winning is 249/500 = 0.498

8. Blackjack (twenty-one) is a casino game played with cards. The goal of the game is to draw
cards that total as close to 21 points as possible without going over. All face cards count as
10 points, aces count as 1 or 11, and all other cards count their numeric value.
The game is played against a dealer. The player tries to get closer to 21 (without going over)
than the dealer. If the dealer busts (goes over 21), the player automatically wins (provided
the player had not already busted). The dealer must always take cards according to a fixed
set of rules. The dealer takes cards until he or she achieves a total of at least 17. If the dealer’s
hand contains an ace, it will be counted as 11 when that results in a total between 17 and 21
inclusive; otherwise, the ace is counted as 1.
Write a program that simulates multiple games of blackjack and estimates the probability that
the dealer will bust. Hints: treat the deck of cards as infinite (casinos use a “shoe” containing
many decks). You do not need to keep track of the cards in the hand, just the total so far
(treating an ace as 1) and a bool variable hasAce that tells whether or not the hand contains
an ace. A hand containing an ace should have 10 points added to the total exactly when
doing so would produce a stopping total (something between 17 and 21 inclusive).


9. A blackjack dealer always starts with one card showing. It would be useful for a player to
know the dealer’s bust probability (see previous problem) for each possible starting value.
Write a simulation program that runs multiple hands of blackjack for each possible starting
value (ace–10) and estimates the probability that the dealer busts for each starting value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3.

from random import random

def printIntro():
    print("This program simulates a game of volleyball between two teams\
    called \"A\" and \"B\". The abilities of each team is indicated by a\
    probability (a number between 0 and 1) that the team wins the point.")

def getInputs():
    # Returns three simulation parameters probA, probB and n
    a = float(input("What is the prob. team A wins a rally? "))
    b = float(input("What is the prob. team B wins a rally? "))
    n = int(input("How many games to simulate? "))
    return a, b, n

def simNGames(n, probA, probB):
    # Simulate n games and return winsA and winsB
    winsA = 0
    winsB = 0
    for i in range(n):
        scoreA, scoreB = simOneGame(probA, probB)
        if scoreA > scoreB:
            winsA = winsA + 1
        else:
            winsB = winsB + 1
    return winsA, winsB

def simOneGame(probA, probB):
    scoreA = 0
    scoreB = 0
    while not gameOver(scoreA, scoreB):
        if random()*probA > random()*probB:
            scoreA = scoreA + 1
        else:
            scoreB = scoreB + 1
    return scoreA, scoreB

def gameOver(a, b):
    # a and b represent scores for a volleyball game.
    # Returns True if the game is over, False otherwise
    return (a >=15 and a - b >= 2) or (b >=15 and b - a >= 2)

def printSummary(winsA, winsB):
    # prints a summary of wins for each team.
    n = winsA + winsB
    print("\nGames simulated:", n)
    print("Wins for A: %d (%0.1f%%)" % (winsA, float(winsA)/n*100))
    print("Wins for B: %d (%0.1f%%)" % (winsB, float(winsB)/n*100))

def main():
    printIntro()
    probA, probB, n = getInputs()
    winsA, winsB = simNGames(n, probA, probB)
    printSummary(winsA, winsB)
main()

1 from random import random 2 3 def printIntro() 4 print(This program simulates a game of volleyball between two teams 5 cal

36 37 def gameOver(a, b): 38 # a and b represent scores for a volleyball game 39 # Returns True if the game is over, False ot

Add a comment
Know the answer?
Add Answer to:
Please write the program in python: 3. Design and implement a simulation of the game of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player...

    using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player plays against the house. The game starts with the player throwing a pair of standard, six-sided dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3, or 12, the player loses. For all other roll values, the player will repeatedly roll the pair of dice until either she rolls the initial value...

  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • 4. In one version of the game played by a dealer and a player, 2 cards...

    4. In one version of the game played by a dealer and a player, 2 cards of a standard 52-card bridge deck are dealt to the player and 2 cards to the dealer. For this exercise, assume that drawing an ace and a face card (Jack, Queen and King for each shape) is called blackjack. If the dealer does not draw a blackjack and the player does, the player wins. If both the dealer and player draw blackjack, a tie...

  • 2. "Craps" is a game played by rolling two fair dice. To play one round of...

    2. "Craps" is a game played by rolling two fair dice. To play one round of this game, the player rolls the dice and the outcome is determined by the following rules: If the total number of dots is 7 or 11 (a "natural"), then the player wins. If the total number of dots is 2, 3, or 12 C'craps"), then the player loses. If the total number of dots is 4, 5, 6,8,9, or 10, then this number is...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • USE PYTHON ONLY Please write a Python program to let you or the user play the...

    USE PYTHON ONLY Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money. Initially, you have 100 dollars in your account, and the dealer also has 100 dollars in his/her account. You would be asked to enter a bet to start the game. If your bet is zero, the game would be stopped immediately. Otherwise, dealer would roll 2 dice and get a number from ( random.randint(1, 6) +...

  • programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work...

    programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work in pairs; this means that a submission may have 2 names attached but those 2 people must have worked on the project. No free rides! The way to submit the program to me is as follows: put the entire program (main and any other functions) into a single compile. Compile it to be sure that you have the correct set of #include statements and...

  • You are helping a corporation create a new system for keeping track of casinos and customers....

    You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. You may complete this project individually or in a group of no more than 2 other people. Requirements do not change if you choose to complete the project individually or as part of a group. Customer-specific requirements You can create...

  • 9. In the casino dice game Craps, players make wagers on a sequence of rolls of...

    9. In the casino dice game Craps, players make wagers on a sequence of rolls of a pair of dice. A sequence of rolls starts with the "shooter" making an initial roll of two dice called the "come-out” roll. If the sum of the dice on the initial roll is 7 or 11 then a player with a bet on the Pass Line wins. If the initial roll results in a sum of 2, 3, or 12 ("craps") then a...

  • programming language c++ its a project if anyone can help me it's will be appreciated thnk...

    programming language c++ its a project if anyone can help me it's will be appreciated thnk u. u have to create a code based on the information im giving u you can do it in 1 or 2 day i can wait 1:26 #WW 2.53% Example: A user starts with 1000 points. Game #1 - user chooses to risk 200 points. User wins game (beats the dealer). User now has 1200 points. Game #2 - user chooses to risk 500...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT