lab_dice/yahtzee_goals.py

270 lines
6.9 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 GoalThreeOfAKind:
"If three of a kind, total of all 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
for number in [1, 2, 3, 4, 5, 6]:
count = 0
for die in dice:
if die.face == number:
count = count + 1
if count >= 3:
for die in dice:
total += die.face
return total
class GoalFourOfAKind:
"If four of a kind, total of all 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
for number in [1, 2, 3, 4, 5, 6]:
count = 0
for die in dice:
if die.face == number:
count = count + 1
if count >= 4:
for die in dice:
total += die.face
return total
class GoalFullHouse:
"If three of one number and two of another, 25 points"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Full House ({potential_score})"
def score(self, dice):
total = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
for die in dice:
if die.face == 1:
count1 = count1 + 1
if die.face == 2:
count2 = count2 + 1
if die.face == 3:
count3 = count3 + 1
if die.face == 4:
count4 = count4 + 1
if die.face == 5:
count5 = count5 + 1
if die.face == 6:
count6 = count6 + 1
if count1 == 3 or count2 == 3 or count3 == 3 or count4 == 3 or count5 == 3 or count6 == 3:
if count1 == 2 or count2 == 2 or count3 == 2 or count4 == 2 or count5 == 2 or count6 == 2:
total = 25
return total
class GoalSmallStraight:
"If four in a row (1,2,3,4 or 2,3,4,5 or 3,4,5,6), get 30 points"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Small Straight ({potential_score})"
def score(self, dice):
total = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
for die in dice:
if die.face == 1:
count1 = 1
if die.face == 2:
count2 = 1
if die.face == 3:
count3 = 1
if die.face == 4:
count4 = 1
if die.face == 5:
count5 = 1
if die.face == 6:
count6 = 1
if count1 == 1 and count2 == 1 and count3 == 1 and count4 == 1:
total = 30
elif count2 == 1 and count3 == 1 and count4 == 1 and count5 == 1:
total = 30
elif count3 == 1 and count4 == 1 and count5 == 1 and count6 == 1:
total = 30
return total
class GoalLargeStraight:
"If five in a row (1,2,3,4,5 or 2,3,4,5,6), get 40 points"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Large Straight ({potential_score})"
def score(self, dice):
total = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
for die in dice:
if die.face == 1:
count1 = 1
if die.face == 2:
count2 = 1
if die.face == 3:
count3 = 1
if die.face == 4:
count4 = 1
if die.face == 5:
count5 = 1
if die.face == 6:
count6 = 1
if count1 == 1 and count2 == 1 and count3 == 1 and count4 == 1 and count5 == 1:
total = 40
elif count2 == 1 and count3 == 1 and count4 == 1 and count5 == 1 and count6 == 1:
total = 40
return total
class GoalYahtzee:
"If five of a kind, get 50 points"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"YAHTZEE ({potential_score})"
def score(self, dice):
total = 0
for number in [1, 2, 3, 4, 5, 6]:
count = 0
for die in dice:
if die.face == number:
count = count + 1
if count >= 5:
for die in dice:
total = 50
return total
class GoalChance:
"Any five dice, total all 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