Write a python program that allows a player to play a game

Assignment Help Python Programming
Reference no: EM132371782

Programming Assignment

ASSIGNMENT OVERVIEW

You are required to write a Python program that allows a player to play a game of Dice Poker against the computer. The program will allow a player to play as many games of dice poker as they wish. Once the player chooses to stop playing, the program will report the game summary to the screen.

DICE POKER SPECIFICATION

You are required to write a Python program called yourEmailId_poker.py that allows a player to play a game of Dice Poker against the computer. The program will allow a player to play as many games of dice poker as they wish.

Dice Poker

Poker is a popular card game where the goal is to beat the dealer (and other players) by having the hand which out ranks all other hands. Typically, each player is dealt five playing cards called a hand. Each hand is then compared against the other players in order to determine the winning hand, that is, the hand that out ranks the other hands. Each hand has a rank and is ranked according to the rules of poker:

This card game translates well into a dice game. Instead of a deck of 52 cards, you will use five, six sided dice in order to play the game.

Although there are many variations of the rules and game play of dice poker, we will be adhering to the following rules and game play for the assignment.

You are required to write a Python program that allows a player to play a game of dice poker against the computer (i.e. the dealer). The program will allow a player to play as many games of dice poker as they wish. Once the player chooses to stop playing, the program will report the game summary to the screen.

Dice Poker Game Play and Rules:

To begin, the player and the dealer (i.e. the computer) are dealt a hand, that is, they each roll five dice.

The player and the dealer’s hands are displayed to the screen.

The hands are then ranked on a scale from 0 to 6 according to the following ranking rules:

665_table.jpg

The rankings are displayed to the screen as text, i.e. Full house, Three of a kind, etc.

The player with the highest ranked hand wins the game! If both players have equal ranked hands, the game is a draw.

Once the player no longer wishes to play against the dealer (computer), the game summary is displayed to the screen.

You do not have to write the code that displays the die face values to the screen, a module containing a function that does that for you has been provided. The dice.py file is a module that contains a function called display_hand that displays the face values of the dice to the screen for you. You are required to use this as part of this assignment, however, please do not modify the dice.py file.

STAGES

It is recommended that you develop this part of the assignment in the suggested stages. Many problems in later stages are due to errors in early stages. Make sure you have finished and thoroughly tested each stage before continuing.

The following stages of development are recommended:

Stage 1

You will need the dice.py file for this assignment. This has been provided for you. Please download this file from the course website (Assessment tab) and ensure that it is in the same directory as the yourEmailId_poker.py file. Test to ensure that this is working correctly by entering the following in your yourEmailId_poker.py file:

import dice

player_hand = [2, 3, 4, 5, 6]

print("Player's hand:")

dice.display_hand(player_hand, 5)

Run the yourEmailId_poker.py file. If this is working correctly, you should now see the following output in the Python shell when you run your program:

Player's hand:
Die 1 Die 2 Die 3 Die 4 Die 5
[2] [3] [4] [5] [6]
* * * * * * * *
* * * *
* * * * * * * *
Note, this is for developmental purposes only, and you will need to modify and correctly position the above code. You will also need to provide a variable for the argument 5 being passed into the dice.display_hand() function (i.e. this is considered a magic number).

Stage 2

Create a list to store the player’s hand, i.e. the five dice values. For example:

player_hand = [0, 0, 0, 0, 0] …or…

player_hand = []

Add code to simulate the rolling of five dice, i.e. deal the player’s hand. That is, you should generate five random numbers, each in the range of 1 through 6 (inclusive) and assign each number to a list element. Use the random.randint(1,6) function to simulate the roll of a die. Hint: Use a loop in order to assign each random number (die roll) to a list element.

Display the player’s hand (i.e. the randomly generated dice roll) to the screen, e.g.:

:

# Place code to randomly generate the roll of five dice here…

:

:

# Display player's hand to the screen.

print("Player's hand:")

dice.display_hand(player_hand, 5)

Sample output (this will look different given we are generating random values here):
Player's hand:
Die 1 Die 2 Die 3 Die 4 Die 5
[3] [6] [1] [4] [2]
* * * * * *
* * * *
* * * * * *

You may like to implement the deal_hand(max_dice) function in this stage or you may prefer to wait until stage 11 (see stage 11 for function description).

Make sure the program runs correctly. Once you have that working, back up your program. Note: When developing software, you should always have fixed points in your development where you know your software is bug free and runs correctly.

Stage 3

Add code to count how many times each die face value was rolled. Hint: Use a list in order to store this information.

To define a list in order to count how many times each die face value was rolled:

die_count = [0, 0, 0, 0, 0, 0, 0]

1396_Tab 1.jpg

Given that die face values are 1 – 6 inclusive, we create a list with seven elements but ignore the zero element of the list. This will make it easier to increment the appropriate list element. That is, die_count[1] should contain the number of 1s that were rolled, die_count[2] the number of 2s rolled, etc.

For example: In the example provided in stage 1, the player’s hand is assigned the following dice values: 5, 2, 1, 1, 6.

In light of this, the die_count should be as follows:

289_tab 2.jpg

To access and update the appropriate list element (using the value of the die as an index):

die_value = player_hand[0]

die_count[die_value] = die_count[die_value] + 1

For example: If die_value is assigned the value 3

957_Tab 3.jpg

Hint: You should use a loop in order to count how many times each die face value was rolled. In the example above, this would mean that player_hand[0] would then be player_hand[index] if placed within a loop.

Stage 4

Determine the rank of the player’s hand (i.e. an integer value between 0 and 6 as described in the section 'Dice Poker Game Play and Rules'). Hint: Use the die_count list that holds how many times each die face value was rolled in order to determine the rank of the hand.

You may like to implement the rank_hand(hand) function in this stage or you may prefer to wait until stage 11 (see stage 11 for function description). If implementing the rank_hand(hand) function, be mindful of where to place the code implemented in stage 3.

Stage 5

Given the rank value ascertained in stage 4, display the corresponding rank name to the screen (see section 'Dice Poker Game Play and Rules' for rank names).

You may like to implement the display_rank(rank) function in this stage or you may prefer to wait until stage 11 (see stage 11 for function description).

Stage 6

Add code to simulate the dealer's hand (i.e. computer). That is, repeat steps 1 – 4 in order to do this for the dealer.

Stage 7

Add code to determine whether the player wins, loses or draws with the dealer (computer). Display the appropriate message to the screen, i.e.:

** Player wins! **

** Dealer wins! **

** Draw! **

Stage 8

Now… it’s time to allow the player to play more than one game. Let’s add a loop which loops until the user enters 'n' (to stop playing the game). Think about where this code should go – what needs to be repeated, etc.

Stage 9

Add code to keep track of how many games were played, won, lost and drawn. Display this to the screen (as seen in the sample output at the end of this handout).

Stage 10

Add code to validate all user input:

Would you like to play dice poker [y|n]?

Sample output:

Would you like to play dice poker [y|n]? p

Please enter either 'y' or 'n'.

Would you like to play dice poker [y|n]? y

Play again [y|n]?

Sample output:

Play again [y|n]? z

Please enter either 'y' or 'n'.

Play again [y|n]? n

Stage 11

Modify your code to include and make use of the following five functions:

display_details()

roll_die()

deal_hand(max_dice)

rank_hand(hand)

display_rank(rank)

1. Write a function called display_details() that will display your details to the screen. The function takes no parameters and does not return a value. The function simply displays your details to the screen. Your function should produce the following output (with your details).

Output:

File : wayby001_poker.py

Author : Batman

Stud ID : 0123456X

Email ID : wayby001

This is my own work as defined by the

University's Academic Misconduct Policy.

2. Write a function called roll_die() that simulates the rolling of one die. The function will generate a random number in the range 1 – 6 (the face value on the die are 1 – 6 inclusive). The function takes no parameters and returns the random number generated.

For example:
die = roll_die()

3. Write a function called deal_hand() that takes the size of the list to create as a parameter.

The function generates five (size) random numbers, each in the range of 1 through 6 (inclusive) and assigns each number to a list element, i.e. deals the player/dealer hand. The function must call the roll_die() function to simulate the roll of a die. Hint: Use a loop in order to assign each random number (die roll) to a list element. The function returns a list containing the randomly generated numbers (i.e. the player/dealer hand).

4. Write a function called rank_hand() that takes a list of integers (i.e. player/dealer hand) as a parameter.

The function determines the rank of the hand based on the combination of dice values stored in the list. The function returns an integer value between 0 and 6 (inclusive) depending on the combination of dice values as described in the section 'Dice Poker Game Play and Rules'.

5. Write a function called display_rank() that takes an integer value representing the rank (number) of the hand as a parameter.

The function displays the corresponding rank name to the screen based on the rank number being passed in as a parameter. See section 'Dice Poker Game Play and Rules' for rank names, e.g.

If the rank number passed in as a parameter is 5, the function should display 'Four of a kind' to the screen; if the rank number is 4, the function should display 'Full house' to the screen, etc. The function does not return a value.

Reminder:

Defining a function does not execute the function – you will need to call the function(s) from the appropriate place(s) from within the main function in the program (some functions, more than once).

Stage 12 – THIS IS IMPORTANT!

Finally, check the sample output (see section titled ‘Sample Output’) and if necessary, modify your code so that:

The output produced by your program EXACTLY matches the sample output provided.

Your program EXACTLY behaves as described in these specs and the sample output provided.

Attachment:- PSP Assignment.rar

Reference no: EM132371782

Questions Cloud

Question - Which one of the groups are simple : Assignment - Simple Groups, Center and Commutat-Group, Solvable Groups. Question - Which one of the groups below are simple
What is the research question and hypothesis : Assignment - Application of Multiple Regression. The data is attached in Excel format. You will need to upload it in to SPSS. What is the research question
Research on chevron use of seismic imaging technology : Do some Internet research on Chevron's use of seismic imaging technology. explain how it works and how it has helped Chevron discover new oil and gas reservoirs
How the role of culture is addressed in the treatment : Briefly summarize the research article and explain how the role of culture is addressed in the treatment of the specific forensic population in the study.
Write a python program that allows a player to play a game : COMP 1039-Problem Solving and Programming-The University of South Australia-Write a Python program that allows a player to play a game of Dice Poker against.
How reggie can start to develop a growth mindset : Use brain plasticity (neuroplasticity) to explain how Reggie can start to develop a growth mindset. What can Reggie do to actually change his brain.
Evaluate applied use and multicultural use of inventory : There are several personality inventories. Some examples are the Predictive Index, Myers-Briggs, and the Kiersey Termperament Sorter. (Note: this is not).
How would you go about determining accuracy : How would you ensure the highest level of accuracy with your simulation, and how would you go about determining accuracy?
Describe some of the techniques associated with acceptance : Describe some of the techniques associated with acceptance and commitment therapy (ACT). Mental illness is the outcome of a complex web of factors involving.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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