generated from mwc/lab_dice
236 lines
5.6 KiB
Python
236 lines
5.6 KiB
Python
from collections import Counter
|
|
|
|
|
|
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 Goal_Three_of_a_Kind:
|
|
"Total of all 5 dice"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Three of a Kind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
total += die.face
|
|
c = Counter(faces)
|
|
of_a_kind = max(c.values())
|
|
if (of_a_kind >= 3):
|
|
return total
|
|
else:
|
|
return 0
|
|
|
|
|
|
class Goal_Four_of_a_Kind:
|
|
"Total of all 5 dice"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Four of a Kind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
total += die.face
|
|
c = Counter(faces)
|
|
of_a_kind = max(c.values())
|
|
if (of_a_kind >= 4):
|
|
return total
|
|
else:
|
|
return 0
|
|
|
|
class GoalFullHouse:
|
|
"25 Points"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Full House ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
c = Counter(faces)
|
|
if len(c) == 2 and (3 in c.values()) and (2 in c.values()):
|
|
return 25
|
|
else:
|
|
return 0
|
|
|
|
class GoalSmallStraight:
|
|
"30 Points"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Small Straight ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
c = Counter(faces)
|
|
if (len(c) >= 4):
|
|
if (1 in c.keys()) and (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()):
|
|
return 30
|
|
elif (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()):
|
|
return 30
|
|
elif (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()) and (6 in c.keys()):
|
|
return 30
|
|
else:
|
|
return 0
|
|
else:
|
|
return 0
|
|
|
|
class GoalLargeStraight:
|
|
"40 Points"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Large Straight ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
c = Counter(faces)
|
|
if (len(c) >= 5):
|
|
if (1 in c.keys()) and (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()):
|
|
return 40
|
|
elif (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()) and (6 in c.keys()):
|
|
return 40
|
|
else:
|
|
return 0
|
|
else:
|
|
return 0
|
|
|
|
class GoalYahtzee:
|
|
"50 Points"
|
|
used = False
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Yahtzee ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
faces = []
|
|
for die in dice:
|
|
faces.append(die.face)
|
|
c = Counter(faces)
|
|
of_a_kind = max(c.values())
|
|
if (of_a_kind == 5):
|
|
return 50
|
|
else:
|
|
return 0
|
|
|
|
class GoalChance:
|
|
"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
|
|
faces = []
|
|
for die in dice:
|
|
total += die.face
|
|
return total
|