generated from mwc/lab_dice
299 lines
8.1 KiB
Python
299 lines
8.1 KiB
Python
|
|
class GoalOnes:
|
|
"One point for each one"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Ones ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 1:
|
|
total += 1
|
|
return total
|
|
|
|
class GoalTwos:
|
|
"Two points for each two"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Twos ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 2:
|
|
total += 2
|
|
return total
|
|
|
|
class GoalThrees:
|
|
"Three points for each three"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Threes ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 3:
|
|
total += 3
|
|
return total
|
|
|
|
class GoalFours:
|
|
"Four points for each four"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Fours ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 4:
|
|
total += 4
|
|
return total
|
|
|
|
class GoalFives:
|
|
"Five points for each five"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Fives ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 5:
|
|
total += 5
|
|
return total
|
|
|
|
class GoalSixes:
|
|
"Six points for each six"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Sixes ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if die.face == 6:
|
|
total += 6
|
|
return total
|
|
|
|
class ThreeofaKind:
|
|
"""If 3 or more dice are the same, returns the value of all 5 dice,
|
|
otherwise returns a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Three of a Kind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_3_of_a_kind(dice):
|
|
return self.dice_total(dice)
|
|
else:
|
|
return 0
|
|
|
|
def check_3_of_a_kind(self,dice):
|
|
for value in range(7):
|
|
instances = 0
|
|
for die in dice:
|
|
if die.face == value:
|
|
instances +=1
|
|
if instances >= 3:
|
|
return True
|
|
return False
|
|
|
|
def dice_total(self,dice):
|
|
total = 0
|
|
for die in dice:
|
|
total += die.face
|
|
return total
|
|
|
|
class FourofaKind:
|
|
"""If 4 or more dice are the same, returns the value of all 5 dice,
|
|
otherwise returns a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Four of a Kind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_4_of_a_kind(dice):
|
|
return self.dice_total(dice)
|
|
else:
|
|
return 0
|
|
|
|
def check_4_of_a_kind(self,dice):
|
|
for value in range(7):
|
|
instances = 0
|
|
for die in dice:
|
|
if die.face == value:
|
|
instances +=1
|
|
if instances >= 4:
|
|
return True
|
|
return False
|
|
|
|
def dice_total(self,dice):
|
|
total = 0
|
|
for die in dice:
|
|
total += die.face
|
|
return total
|
|
|
|
class FullHouse:
|
|
"""If there are 3 of the same dice and 2 of the same dice, returns 25,
|
|
otherwise returns a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Full House ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_full_house(dice):
|
|
return 25
|
|
else:
|
|
return 0
|
|
|
|
def check_full_house(self,dice):
|
|
for value in range(7):
|
|
instances = 0
|
|
for die in dice:
|
|
if die.face == value:
|
|
instances +=1
|
|
if instances == 3:
|
|
triple_dice = value
|
|
list_die = [1,2,3,4,5,6]
|
|
list_die.remove(value)
|
|
for value in list_die:
|
|
instances_2 = 0
|
|
for die in dice:
|
|
if die.face == value:
|
|
instances_2 +=1
|
|
if instances_2 ==2:
|
|
return True
|
|
return False
|
|
|
|
class SmallStraight:
|
|
"""If there are 4 dice that can be put in consecutive order,
|
|
return 30, otherwise return a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Small Straight ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_small_straight(dice):
|
|
return 30
|
|
else:
|
|
return 0
|
|
|
|
def check_small_straight(self,dice):
|
|
dice_faces =[]
|
|
for die in dice:
|
|
dice_faces.append(die.face)
|
|
dice_faces.sort()
|
|
'''need to check for duplicates first, do not need to check index 0 or 4'''
|
|
if dice_faces[1]==dice_faces[2]:
|
|
dice_faces.remove(dice_faces[1])
|
|
if dice_faces[2]==dice_faces[3]:
|
|
dice_faces.remove(dice_faces[2])
|
|
'''now check if ordered list increases by 1, do not need to check last index'''
|
|
if dice_faces[0] + 1 == dice_faces[1]:
|
|
if dice_faces[1] + 1 == dice_faces[2]:
|
|
if dice_faces[2] + 1 == dice_faces[3]:
|
|
return True
|
|
else:
|
|
'''now reverse the list and check if they decrease by 1, do not need to check last index'''
|
|
dice_faces.sort(reverse=True)
|
|
if dice_faces[0] - 1 == dice_faces[1]:
|
|
if dice_faces[1] - 1 == dice_faces[2]:
|
|
if dice_faces[2] - 1 == dice_faces[3]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
class LargeStraight:
|
|
"""If there are 5 dice that can be put in consecutive order,
|
|
return 40, otherwise return a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Large Straight ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_large_straight(dice):
|
|
return 40
|
|
else:
|
|
return 0
|
|
|
|
def check_large_straight(self,dice):
|
|
dice_faces =[]
|
|
for die in dice:
|
|
dice_faces.append(die.face)
|
|
dice_faces.sort()
|
|
if dice_faces[0] + 1 == dice_faces[1]:
|
|
if dice_faces[1] + 1 == dice_faces[2]:
|
|
if dice_faces[2] + 1 == dice_faces[3]:
|
|
if dice_faces[3] + 1 ==dice_faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
class YAHTZEE:
|
|
"""If there are 5 dice that are all the same,
|
|
return 50, otherwise return a score of 0"""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"YAHTZEE ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
if self.check_YAHTZEE(dice):
|
|
return 50
|
|
else:
|
|
return 0
|
|
|
|
def check_YAHTZEE(self,dice):
|
|
dice_faces =[]
|
|
for die in dice:
|
|
dice_faces.append(die.face)
|
|
if dice_faces[0]==dice_faces[1]==dice_faces[2]==dice_faces[3]==dice_faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
class Chance:
|
|
"""Returns the total of all 5 dice."""
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Chance ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
total += die.face
|
|
return total
|
|
|
|
|
|
def dice_total(self,dice):
|
|
total = 0
|
|
for die in dice:
|
|
total += die.face
|
|
return total |