generated from mwc/lab_dice
288 lines
6.8 KiB
Python
288 lines
6.8 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:
|
|
"Total of all six dice, if there are at least three of one number"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self,dice):
|
|
potential_score = self.score(dice)
|
|
return f"Three of a Kind ({potential_score})"
|
|
|
|
def is_three_of_a_kind(self, faces):
|
|
faces.sort()
|
|
if faces[0]==faces[2]:
|
|
return True
|
|
elif faces[1]==faces[3]:
|
|
return True
|
|
elif faces[2]==faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self,dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_three_of_a_kind(faces):
|
|
total = 0
|
|
for face in faces:
|
|
total += face
|
|
return total
|
|
else:
|
|
return 0
|
|
|
|
class FourOfAKind:
|
|
"Total of all six dice, if there are at least four of one number"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self,dice):
|
|
potential_score = self.score(dice)
|
|
return f"Four of a Kind ({potential_score})"
|
|
|
|
def is_four_of_a_kind(self, faces):
|
|
faces.sort()
|
|
if faces[0]==faces[3]:
|
|
return True
|
|
elif faces[1]==faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self,dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_four_of_a_kind(faces):
|
|
total = 0
|
|
for face in faces:
|
|
total += face
|
|
return total
|
|
else:
|
|
return 0
|
|
|
|
class FullHouse:
|
|
"If there are two of one number and three of another, earn 25 points"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self,dice):
|
|
potential_score = self.score(dice)
|
|
return f"Full House ({potential_score})"
|
|
|
|
def is_full_house(self, faces):
|
|
faces.sort()
|
|
if faces[0] == faces[1] and faces[2] == faces[4]:
|
|
return True
|
|
elif faces[0] == faces[2] and faces[3] == faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self, dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_full_house(faces):
|
|
return 25
|
|
else:
|
|
return 0
|
|
|
|
|
|
class SmallStraight:
|
|
"If there is any sequence of four numbers, earn 30 points"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Small Straight ({potential_score})"
|
|
|
|
def is_small_straight(self,faces):
|
|
faces.sort()
|
|
count = 0
|
|
|
|
if faces[0]+1 == faces[1] and faces[1]+1 == faces[2] and faces[2]+1 == faces[3]:
|
|
return True
|
|
elif faces[1]+1 == faces[2] and faces[2]+1 == faces[3] and faces[3]+1 == faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self,dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_small_straight(faces):
|
|
return 30
|
|
else:
|
|
return 0
|
|
|
|
|
|
|
|
class LargeStraight:
|
|
"If there is any sequence of 5 numbers, earn 40 points"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self,dice):
|
|
potential_score = self.score(dice)
|
|
return f"Large Straignt ({potential_score})"
|
|
|
|
def is_Large_Straight(self,faces):
|
|
faces.sort()
|
|
count = 0
|
|
for i in range(0,4):
|
|
if faces[i] == faces[i+1] - 1:
|
|
count += 1
|
|
else:
|
|
count = 0
|
|
if count == 4:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self,dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_Large_Straight(faces):
|
|
return 40
|
|
else:
|
|
return 0
|
|
|
|
class Chance:
|
|
"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
|
|
|
|
|
|
class Yahtzee:
|
|
"Six of a Kind 50 points, 100 points for yahtzees after the first"
|
|
used = False
|
|
|
|
def diceFaces(self,dice):
|
|
return [die.face for die in dice]
|
|
|
|
def prompt(self,dice):
|
|
|
|
potential_score = self.score(dice)
|
|
return f"Yahtzee ({potential_score})"
|
|
|
|
def is_yahtzee(self, faces):
|
|
faces.sort()
|
|
if faces[0] == faces[4]:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def score(self,dice):
|
|
faces = self.diceFaces(dice)
|
|
if self.is_yahtzee(faces):
|
|
return 50
|
|
else:
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|