Ask Python Expert

Assignment: Dice Poker

Our goal is to write a game program that allows a user to play video poker using dice. The program will display a hand consisting of five dice. The basic set of rules is as follows:

? The player starts with $100.
? Each round costs $10 to play. This amount is subtracted from the user's money at the start of the round.
? The player initially rolls a completely random hand.
? The player gets two chances to enhance the hand by rerolling some or all of the dice.
? At the end of the hand, the player's money is updated according to the following payout schedule:

? Two Pairs = $5
? Three of a Kind = $8
? Full House (A Pair and a Three of a Kind) = $12
? Four of a Kind = $15
? Straight (1-5 or 2-6) $20
? Five of a Kind = $30

1. Now we are ready to turn our attention to the task of actually implementing the poker game. We know that the PokerApp will need to keep track of the dice and the amount of money. Let's initialize these values in the constructor.

1. Define a new class named PokerApp in the same file as the Dice class.

2. Inside the PokerApp define an init method that only has one parameter, self.

3. Inside the init method, create an instance of the Dice class, Dice(), and store the instance in an instance variable called dice. Remember to precede the instance variable with self and a dot.

4. Inside the init method, create an instance variable named money and initialize it to 100. Remember self-dot.

5. To test the PokerApp class and its contructor use the following driver code:

1. game = PokerApp()

2. print game.money

3. Printing the dice instance variable is a little more tricky. Try it by adding the following code to the driver code above:

1. print game.dice

2. This doesn't work because the dice instance variable is an object. To print the value inside the object you must use dot notation and call the instance variable on that object. Change the last line of code to:

1. print game.dice.dice

2. Now we want to loop the program allowing the user to continue playing hands until he or she is either out of money or chooses to quit. Sincee it costs $10 to play a hand, we can continue as long as the amount of money is at least $10.

1. Define a method called wantToPlay that has a parameter self.

1. Inside the method, use raw_input to ask the user "Do you wish to try your luck?" and store the result in a local variable named ans.

2. Now we need to see if the user responded with "yes" or "y". If the first letter of ans is uppercase or lowercase "y" then return True, otherwise return "False." Hint: The first letter of a string is index zero.

2. Define another method called run with a parameter, self.

1. Inside the method, ouput the following: You currently have $100.

2. Inside the method, create a loop that executes as long as the money balance is at least $10 and a call to the wantToPlay method is true. Don't forget the self-dot.

3. Inside the loop make a call to a method named playRound and send no arguments.

3. Most of the work of the program has now been pushed into the playRound method. Each round will consist of a series of rolls. Based on these rolls, the program will have to adjust the player's score.

1. Define the playRound method with only the self parameter.

2. Inside the playRound method, subtract 10 from the money.

3. Make a call to another instance method called doRolls that takes no arguements. This method will be in charge rolling the dice and rerolling if the user chooses. We will write this method in the next section.

4. When control returns from the doRolls method we will have the final hand to be played so we need to score the hand by calling the score method in the dice class. To do this we must use call the method using the dice instance variable (don't forget the self-dot). The score method will return two values: the type of hand and the payout. So here's how it will look:

1. result, score = self.dice.score()

5. Print the values returned by the score method according to this sample output: Full House. You win $12.

6. Add the payout to the player's money.

7. Print the new amount player money according the following sample output: You currently have $102.

4. Finally, we are down to the nitty-gritty details of implementing the dice rolling process.

Initially, all of the dice will be rolled. Then we need a loop that continues rolling user-selected dice until either athe user chooses to quit rolling or the limit of three rolls is reached.

1. Roll all the dice using the roll method in the Dice class.

2. Create a local variable to keep track of the roll number. Initialize this variable to 1 since we are on the first roll.

3. Print the roll of the dice using the following sample: Dice: [2, 3, 2, 1, 5, 5]

4. Get input from the user asking for which dice to reroll and store in a local variable named toRoll: toRoll = input("Enter list of which to change ([] to stop) ")

5. Create a loop that will execute as long as the roll count is less than three and the user didn't type in an empty list to stop.

1. Inside the body of the loop, call the roll method of the dice class rolling the dice the user selected.

2. Increment the roll count by 1.

3. Output the new hand of rolled dice. Use the same code as earlier.

4. Create a conditional statement that asks the user if they want to roll again but only if the roll count is still less than three.

5. Your PokerApp class should now be complete. To run the game you should only need to create a PokerApp object and then call its run method. These commands should not be part of the class and therefore should not be indented.

1. game = PokerApp()
2. game.run().

Python, Programming

  • Category:- Python
  • Reference No.:- M92313635

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As