Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP 1039

Problem Solving and Programming

Programming Assignment 1

Contents

Introduction

Assignment Overview

Graduate Qualities

Part I Specification

.     Practical Requirements (Part I)

.     Stages (Part I)

Part II Specification

.     Practical Requirements (Part II)

.     Stages (Part II)

Submission Details

Extensions and Late Submissions


Academic Misconduct

Marking Criteria

Sample Output (Part I and Part II)

INTRODUCTION

This document describes the        assignment      Problem Solving and Programming.

The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course by applying your knowledge and skills to the implementation of a game called Dice Poker

This assignment is an individual task that will require an individual submission (i.e. the work that you submit MUST be your own).  If you are an internal student, you will be required to submit your work via learnonline before Friday 29 September, 11.30 pm (internal students).

This document  is a  kind of specification of the  required end  product that will  be generated  by  implementing the assignment.  Like many specifications, it is written in English and hence will contain some imperfectly specified parts. Please make sure you seek clarification if you are not clear on any aspect of this 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.

Please ensure that you read the section titled ‘Dice Poker Specification’ below for further details.

GRADUATE QUALITIES

By  undertaking this  assessment, you will  progress  in  developing  the  qualities  of a  University  of  South Australia graduate.

The Graduate qualities being assessed by this assignment are:

.     The  ability  to  demonstrate  and  apply  a  body  of  knowledge  (GQ1)  gained  from  the  lectures,  workshops, practicals and  readings.   This  is  demonstrated  in  your  ability  to  apply  problem solving and  programming theory to a practical situation.

.     The development of skills required for lifelong learning (GQ2), by searching for information and learning to use and  understand the resources provided (Python standard  library,  lectures, workshops, practical exercises, etc); in order to complete a programming exercise.

.     The ability to effectively problem solve (GQ3) using Python to complete the programming problem.   Effective problem solving is demonstrated by the ability to understand what is required, utilise the relevant information from lectures, workshops and practical work, write Python code, and evaluate the effectiveness of the code by testing it.

.     The ability to work autonomously (GQ4) in order to complete the task.

.     The use of communication skills (GQ6) by producing code that has been properly formatted; and writing adequate, concise and clear comments.

.     The application of international standards (GQ7) by making sure your solution conforms to the standards presented in the Python Style Guide slides (available on the course website).

DICE POKER SPECIFICATION PART 1

You are required to write a Python program called yourEmailId_poker_p1.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. https://en.wikipedia.org/wiki/Poker 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: https://en.wikipedia.org/wiki/List  of  poker_hands. 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 dealers hands are displayed to the screen.

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

Rank

Number

Rank Name

Description

Example

Rank 6

Five of a kind

All five dice have the same face value.

Rank 5

Four of a kind

Four dice have the same face value with one die having a different value.

Rank 4

Full house

Three of a kind and a pair.

Rank 3

Three of a kind

Three dice have the same face value and the other two have different values.

Rank 2

Two pairs

Two pairs with one die having a different value.

Rank 1

One pair

Two dice have the same value and the others have different values.

Rank 0

Nothing special

All five dice have different values.

. 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.

PRACTICAL REQUIREMENTS PART 1

It is expected that your solution will include the use of:

.     Your solution in a file called yourEmailId_poker_p1.py.

.     Appropriate and well constructed while and/or for loops (as necessary).

.     Appropriate  if, if-else, if-elif-else statements (as necessary).

.     The use of random.randint(1,6) function in order to simulate the roll of a six sided die.

.     The supplied dice.py module (containing the display_hand function).   This is provided for you – please DO NOT modify this file.

.     A list to represent/store the players hand, i.e. player_hand = [0, 0, 0, 0, 0]

.     A list to represent/store the dealer’s (computer’s) hand, i.e. dealer_hand = [0, 0, 0, 0, 0]

.     A list to store how many times each die face value was rolled.

.     A list to store the player’s hands dealt statistics.

.     A loop in order to count how many times each die face value was rolled.

.     A loop in order to count the player’s hands dealt statistics.

.     Nested loops in order to display player’s hand stats to the screen.

.     Output that strictly adheres to the assignment specifications.   If you are  not sure about these details, you should  check with the ‘Sample  Output’  provided  at  the  end  of this  document  or  post  a  message  to the discussion forum.

.     Good programming practice:

o  Consistent  commenting,  layout  and  indentation.   You  are  to  provide  comments  to  describe:  your details,  program  description,  all  variable  definitions, all function  definitions,  and  every  significant section of code.

o  Meaningful variable names (no single letter identifier names).

Your solutions MAY use:

.     You may make use of the len() and range()built-in functions.

.     You may make use of the list.append() method.

Your solutions MUST NOT use:

.     break or continue statements in your solution. Do not use the quit() or exit() functions or the break or   return statements (or any other techniques) as a way to break out of loops.   Doing so will result in a significant mark deduction.

.     List or String methods in order to count how many times each die face value was rolled.

.     Built-in functions in order to count how many times each die face value was rolled.

.     Your own (user-defined) functions.

PLEASE NOTE:  You are   reminded  that  you should ensure that   all   input and output conform  to the specifications listed here; if you are not sure about these details you should check with the sample output provided at the end of this document or post a message to the discussion forum in order to seek clarification.

Please  ensure  that  you  use  Python  3.11.4  or  a  later  version  (i.e.  the  latest  version)  in  order  to  complete  your assignments.  Your programs MUST run using Python 3.11.4 (or latest version).

STAGES PART 1

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_p1.py file.

Test to ensure that this is working correctly by entering the following in your yourEmailId_poker_p1.py file:

import dice

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

print("Player's hand:")

dice.display_hand(player_hand)

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

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.

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 players 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)

Sample output (this will look different given we are generating random values here):

Die 1     Die 2     Die 3     Die 4     Die 5

[3]       [6]       [1]       [4]       [2]

*         * *                     * *       * *        * *        *

*       * *                  * *         *

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: You MUST 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]

die count

0

0

0

0

0

0

0

0          1          2         3          4         5         6

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:

die count

0

2

1

0

0

1

1

0          1          2         3          4         5         6

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.

die count

0

0

0

1

0

0

0

0          1          2         3          4         5         6

Hint: You MUST use a loop in order to count how many times each die face value was rolled.   In the example above, this would mean that the index in the statement player_hand[0] would need to be modified 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.

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).

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