generated from mwc/lab_dice
I didnt mind writting classes for each problem, it was nice to think of one thing at a time instead of the whole checkpoint all together, which sometimes it has felt like that in the past. That being said, I like jupyter notebook the best still, adds more guidence which i feel I need.
187 lines
4.3 KiB
Python
187 lines
4.3 KiB
Python
from collections import Counter
|
|
|
|
class GoalOnes:
|
|
"One point for each one"
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
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 GoalThreeofaKind:
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"ThreeofaKind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
counts = Counter(self.dice)
|
|
for count in counts.value():
|
|
if count >= 3:
|
|
return True
|
|
return False
|
|
if True:
|
|
total += sum(self.dice)
|
|
return total
|
|
|
|
|
|
class GoalFourofaKind:
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"FourofaKind ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
counts = Counter(self.dice)
|
|
for count in counts.value():
|
|
if count >= 4:
|
|
return True
|
|
return False
|
|
if True:
|
|
total += sum(self.dice)
|
|
return total
|
|
|
|
class GoalFullHouse:
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"FullHouse ({potential_score}"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if
|
|
total +=25
|
|
return total
|
|
|
|
class GoalSmallStraight:
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"SmallStraight ({potential_score}"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if
|
|
total +=30
|
|
return total
|
|
|
|
class GoalLargeStraight:
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"LargeStraight ({potential_score}"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if
|
|
total +=40
|
|
return total
|
|
|
|
class GoalYahtzee:
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Yahtzee ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
counts = Counter(self.dice)
|
|
for count in counts.value():
|
|
if count >= 5:
|
|
return True
|
|
return False
|
|
if True:
|
|
total += 50
|
|
return total
|
|
|
|
class GoalChance:
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Yahtzee ({potential_score})"
|
|
|
|
def score(self, dice):
|
|
total = 0
|
|
for die in dice:
|
|
if
|
|
total +=sum(self.dice)
|
|
return total |