Objective: To create a production system to play a dice game

Task: To write a Python module to make decisions in playing the dice game

Game rule

  • In every game, the player has 5 dice.
  • The player is allowed 5 rerolls.
  • For each reroll, the player can decide which dice to be kept and choose any number of dice to reroll.
  • The game ends after 5 rerolls or when the player decides not to reroll.
  • After the game ends, points are calculated based on the output combination of the dice.
  • Every player will play 5 games.

Points

Dice Combinations Points
Five-in-a-row Sum of dice + 70
Straight (1-2-3-4-5, 2-3-4-5-6) Sum of dice + 60
Full house (Three + Two of a kind) Sum of dice + 50
Four-of-a-kind (Four + One) Sum of dice + 40
Three-of-a-kind (Three + one + One) Sum of dice + 30
Other combinations Sum of dice

Code

class Player :
def __init__ ( self , . . . ) :
. . .
def play ( self , dice_face , available_rerolls ):
. . .
return [ . . . ] #indices of dice to be rerolled

class Player :

create a class with the name Player

def play ( self , dice_face , available_rerolls ):

1. create a method called play for the class
2. inputs:

  • dice_face - an array of the current dice faces
  • available_rerolls - number of rerolls available in the current game

return [ . . . ] #indices of dice to be rerolled

1. return a list from the function play
2. the list contains the indices of dice (in dice_face) to be rerolled
3. an empty list implies the player would like to stop rerolling for the current game

Example

1. At the beginning of a game, the dice will be rolled. For example, the result of the initial roll is 6,6,5,3,1

dice_face = [6,6,5,3,1]
available_rerolls = 5

2. If the player decides to keep the two sixes, i.e. the dice with index 0 and 1, the return value of the play function is [2,3,4] as the dice with index 2, 3, and 4 are to be rerolled.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.