Professional Documents
Culture Documents
print("\nWelcome to Yahtzee!")
name = input("\nWhat's your name? ")
print("Okay " + name + ", let's play!")
ones = ""
twos = ""
threes = ""
fours = ""
fives = ""
sixes = ""
three_kind = ""
four_kind = ""
full_house = ""
sm_str = ""
lg_str = ""
yahtzee = ""
chance = ""
categories = [
ones,
twos,
threes,
fours,
fives,
sixes,
three_kind,
four_kind,
full_house,
sm_str,
lg_str,
yahtzee,
chance
]
b=1
while b <= 13:
dice = [
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6)
]
a=1
while a <= 3:
die1 = dice[0]
die2 = dice[1]
die3 = dice[2]
die4 = dice[3]
die5 = dice[4]
print("\nTurn " + str(b) + ", Roll " + str(a) + ": You rolled: " + str(die1) + " " + str(die2) + " " + str(
die3) + " " + str(die4) + " " + str(die5))
if a == 3:
ones_proj = 0
twos_proj = 0
threes_proj = 0
fours_proj = 0
fives_proj = 0
sixes_proj = 0
three_kind_proj = 0
four_kind_proj = 0
full_house_proj = 0
sm_str_proj = 0
lg_str_proj = 0
yahtzee_proj = 0
chance_proj = 0
def is_full_house(roll):
return sorted(dice.count(card) for card in set(dice)) == [2, 3]
if is_full_house(dice):
full_house_proj = 25
chance_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]
dice = set(dice)
dice = list(dice)
if len(dice) == 4:
if dice[3] - dice[0] == 3:
sm_str_proj = 30
elif len(dice) == 5:
if dice[4] - dice[0] == 4:
sm_str_proj = 30
if len(dice) == 5:
if dice[4] - dice[0] == 4:
lg_str_proj = 40
if len(dice) == 1:
yahtzee_proj = 50
projected = [
ones_proj,
twos_proj,
threes_proj,
fours_proj,
fives_proj,
sixes_proj,
three_kind_proj,
four_kind_proj,
full_house_proj,
sm_str_proj,
lg_str_proj,
yahtzee_proj,
chance_proj
]
categories = [
ones,
twos,
threes,
fours,
fives,
sixes,
three_kind,
four_kind,
full_house,
sm_str,
lg_str,
yahtzee,
chance
]
categories[score - 1] = projected[score - 1]
ones = categories[0]
twos = categories[1]
threes = categories[2]
fours = categories[3]
fives = categories[4]
sixes = categories[5]
three_kind = categories[6]
four_kind = categories[7]
full_house = categories[8]
sm_str = categories[9]
lg_str = categories[10]
yahtzee = categories[11]
chance = categories[12]
b += 1
break
add_to_score = input("Do you want to add this roll to score or re-roll? (S/R) ")
if add_to_score.lower() == "s":
ones_proj = 0
twos_proj = 0
threes_proj = 0
fours_proj = 0
fives_proj = 0
sixes_proj = 0
three_kind_proj = 0
four_kind_proj = 0
full_house_proj = 0
sm_str_proj = 0
lg_str_proj = 0
yahtzee_proj = 0
chance_proj = 0
def is_full_house(roll):
return sorted(dice.count(card) for card in set(dice)) == [2, 3]
if is_full_house(dice):
full_house_proj = 25
chance_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]
dice = set(dice)
dice = list(dice)
if len(dice) == 4:
if dice[3] - dice[0] == 3:
sm_str_proj = 30
elif len(dice) == 5:
if dice[4] - dice[0] == 4:
sm_str_proj = 30
if len(dice) == 5:
if dice[4] - dice[0] == 4:
lg_str_proj = 40
if len(dice) == 1:
yahtzee_proj = 50
projected = [
ones_proj,
twos_proj,
threes_proj,
fours_proj,
fives_proj,
sixes_proj,
three_kind_proj,
four_kind_proj,
full_house_proj,
sm_str_proj,
lg_str_proj,
yahtzee_proj,
chance_proj
]
categories = [
ones,
twos,
threes,
fours,
fives,
sixes,
three_kind,
four_kind,
full_house,
sm_str,
lg_str,
yahtzee,
chance
]
categories[score - 1] = projected[score - 1]
ones = categories[0]
twos = categories[1]
threes = categories[2]
fours = categories[3]
fives = categories[4]
sixes = categories[5]
three_kind = categories[6]
four_kind = categories[7]
full_house = categories[8]
sm_str = categories[9]
lg_str = categories[10]
yahtzee = categories[11]
chance = categories[12]
b += 1
break
else:
choice = input("\nWhich dice do you want to keep? \nType the die numbers without spaces to keep (i.e. "
"\"134\"): ")
i=0
dice = [
"",
"",
"",
"",
""
]
if len(choice) == 0:
dice = [
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6),
random.randint(1, 6)
]
bonus = 0
upper_sum = categories[0] + categories[1] + categories[2] + categories[3] + categories[4] + categories[5]
lower_sum = categories[6] + categories[7] + categories[8] + categories[9] + categories[10] + categories[11] + categories[12]
if upper_sum >= 63:
bonus = 35
highscores = [
323,
267,
227
]
print("Highscores:")
print(" (1): 323 - ACF - 12/29/21")
print(" (2): 267 - EAF - 12/29/21")
print(" (3): 227 - ACF - 12/28/21")