generated from mwc/lab_dice
play.py yahtzee.py yahtzee_goals.py
This commit is contained in:
12
play.py
12
play.py
@@ -3,12 +3,24 @@ from yahtzee_goals import (
|
||||
GoalOnes,
|
||||
GoalTwos,
|
||||
GoalThrees,
|
||||
GoalFours,
|
||||
GoalFives,
|
||||
GoalSixes,
|
||||
Goal_is_three_of_a_kind,
|
||||
Goal_is_four_of_a_kind,
|
||||
Goal_is_full_house,
|
||||
)
|
||||
|
||||
goals = [
|
||||
GoalOnes(),
|
||||
GoalTwos(),
|
||||
GoalThrees(),
|
||||
GoalFours(),
|
||||
GoalFives(),
|
||||
GoalSixes(),
|
||||
Goal_is_three_of_a_kind(),
|
||||
Goal_is_four_of_a_kind(),
|
||||
Goal_is_full_house(),
|
||||
]
|
||||
|
||||
game = Yahtzee(goals)
|
||||
|
||||
@@ -97,7 +97,7 @@ class Yahtzee:
|
||||
|
||||
def get_unused_goals(self):
|
||||
"""
|
||||
Conditional appending of the list of unused_goals.
|
||||
Conditional appending of the list of unused_goals, displayed in the menu.
|
||||
"""
|
||||
unused_goals = []
|
||||
for goal in self.goals:
|
||||
@@ -120,7 +120,8 @@ class Yahtzee:
|
||||
|
||||
def get_dice_to_reroll(self, choice_ints):
|
||||
"""Conditional logic to append dice to the dice_to_reroll list,
|
||||
and removes dice that weren't chosen from the choice_ints list.
|
||||
and removes dice that weren't chosen from the choice_ints list
|
||||
(the Dice: displayed in the show_status function)
|
||||
"""
|
||||
dice_to_reroll = []
|
||||
for die in self.dice:
|
||||
|
||||
107
yahtzee_goals.py
107
yahtzee_goals.py
@@ -1,3 +1,6 @@
|
||||
from collections import Counter
|
||||
from die import Die
|
||||
|
||||
|
||||
class GoalOnes:
|
||||
"One point for each one"
|
||||
@@ -13,6 +16,7 @@ class GoalOnes:
|
||||
total += 1
|
||||
return total
|
||||
|
||||
|
||||
class GoalTwos:
|
||||
"Two points for each two"
|
||||
|
||||
@@ -27,6 +31,7 @@ class GoalTwos:
|
||||
total += 2
|
||||
return total
|
||||
|
||||
|
||||
class GoalThrees:
|
||||
"Three points for each three"
|
||||
|
||||
@@ -40,3 +45,105 @@ class GoalThrees:
|
||||
if die.face == 3:
|
||||
total += 3
|
||||
return total
|
||||
|
||||
|
||||
class GoalFours:
|
||||
"Four points for each four"
|
||||
|
||||
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:
|
||||
"Fives points for each five"
|
||||
|
||||
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"
|
||||
|
||||
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_is_three_of_a_kind:
|
||||
"Score is total all 5 dice for three-of-a-kind"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"3 of a kind ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if a == 3:
|
||||
total += die.face
|
||||
return total
|
||||
|
||||
class Goal_is_four_of_a_kind:
|
||||
"Score is total all 5 dice for four-of-a-kind"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"4 of a kind ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if a == 4:
|
||||
total += die.face
|
||||
return total
|
||||
|
||||
|
||||
class Goal_is_full_house:
|
||||
"25 points for a full house (three-of-a-kind plus a pair of a different number)"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"Full House ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if (a == 3 and len(values) == 2):
|
||||
total = 25
|
||||
return total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user