You are on page 1of 6

import random

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

for e in range(0, 5):


if int(dice[e]) == 1:
ones_proj += 1
elif int(dice[e]) == 2:
twos_proj += 2
elif int(dice[e]) == 3:
threes_proj += 3
elif int(dice[e]) == 4:
fours_proj += 4
elif int(dice[e]) == 5:
fives_proj += 5
elif int(dice[e]) == 6:
sixes_proj += 6
dice_sorted = sorted(dice)
if dice_sorted[0] == dice_sorted[2] or dice_sorted[1] == dice_sorted[3] or dice_sorted[2] == dice_sorted[4]:
three_kind_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]
if dice_sorted[0] == dice_sorted[3] or dice_sorted[1] == dice_sorted[4]:
four_kind_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]

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
]

print("SCOREBOARD Your Score Projected Score")


print("---------------------------------------------------")
print("(1) Ones: " + str(ones).zfill(2) + " " + str(ones_proj).zfill(2))
print("(2) Twos: " + str(twos).zfill(2) + " " + str(twos_proj).zfill(2))
print("(3) Threes: " + str(threes).zfill(2) + " " + str(threes_proj).zfill(2))
print("(4) Fours: " + str(fours).zfill(2) + " " + str(fours_proj).zfill(2))
print("(5) Fives: " + str(fives).zfill(2) + " " + str(fives_proj).zfill(2))
print("(6) Sixes: " + str(sixes).zfill(2) + " " + str(sixes_proj).zfill(2))
print("(7) 3 of a Kind: " + str(three_kind).zfill(2) + " " + str(three_kind_proj).zfill(2))
print("(8) 4 of a Kind: " + str(four_kind).zfill(2) + " " + str(four_kind_proj).zfill(2))
print("(9) Full House: " + str(full_house).zfill(2) + " " + str(full_house_proj).zfill(2))
print("(10) Sm Straight: " + str(sm_str).zfill(2) + " " + str(sm_str_proj).zfill(2))
print("(11) Lg Straight: " + str(lg_str).zfill(2) + " " + str(lg_str_proj).zfill(2))
print("(12) YAHTZEE: " + str(yahtzee).zfill(2) + " " + str(yahtzee_proj).zfill(2))
print("(13) Chance: " + str(chance).zfill(2) + " " + str(chance_proj).zfill(2))
score = int(input("Which category do you want to add score to? (1-13): "))

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

for e in range(0, 5):


if int(dice[e]) == 1:
ones_proj += 1
elif int(dice[e]) == 2:
twos_proj += 2
elif int(dice[e]) == 3:
threes_proj += 3
elif int(dice[e]) == 4:
fours_proj += 4
elif int(dice[e]) == 5:
fives_proj += 5
elif int(dice[e]) == 6:
sixes_proj += 6
dice_sorted = sorted(dice)
if dice_sorted[0] == dice_sorted[2] or dice_sorted[1] == dice_sorted[3] or dice_sorted[2] == dice_sorted[4]:
three_kind_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]
if dice_sorted[0] == dice_sorted[3] or dice_sorted[1] == dice_sorted[4]:
four_kind_proj = dice[0] + dice[1] + dice[2] + dice[3] + dice[4]

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
]

print("SCOREBOARD Your Score Projected Score")


print("---------------------------------------------------")
print("(1) Ones: " + str(ones).zfill(2) + " " + str(ones_proj).zfill(2))
print("(2) Twos: " + str(twos).zfill(2) + " " + str(twos_proj).zfill(2))
print("(3) Threes: " + str(threes).zfill(2) + " " + str(threes_proj).zfill(2))
print("(4) Fours: " + str(fours).zfill(2) + " " + str(fours_proj).zfill(2))
print("(5) Fives: " + str(fives).zfill(2) + " " + str(fives_proj).zfill(2))
print("(6) Sixes: " + str(sixes).zfill(2) + " " + str(sixes_proj).zfill(2))
print("(7) 3 of a Kind: " + str(three_kind).zfill(2) + " " + str(three_kind_proj).zfill(2))
print("(8) 4 of a Kind: " + str(four_kind).zfill(2) + " " + str(four_kind_proj).zfill(2))
print("(9) Full House: " + str(full_house).zfill(2) + " " + str(full_house_proj).zfill(2))
print("(10) Sm Straight: " + str(sm_str).zfill(2) + " " + str(sm_str_proj).zfill(2))
print("(11) Lg Straight: " + str(lg_str).zfill(2) + " " + str(lg_str_proj).zfill(2))
print("(12) YAHTZEE: " + str(yahtzee).zfill(2) + " " + str(yahtzee_proj).zfill(2))
print("(13) Chance: " + str(chance).zfill(2) + " " + str(chance_proj).zfill(2))
score = int(input("Which category do you want to add score to? (1-13): "))

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)
]

while i < len(choice):


if int(choice[i]) == 1:
dice[0] = die1
i += 1
elif int(choice[i]) == 2:
dice[1] = die2
i += 1
elif int(choice[i]) == 3:
dice[2] = die3
i += 1
elif int(choice[i]) == 4:
dice[3] = die4
i += 1
elif int(choice[i]) == 5:
dice[4] = die5
i += 1

for d in range(0, 5):


if dice[d] == "":
dice[d] = random.randint(1, 6)
a += 1

for h in range(0, 14):


if categories[h] == "":
categories[h] = 0

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

final_score = bonus + upper_sum + lower_sum

highscores = [
323,
267,
227
]

if final_score > highscores[0]:


print("\nCongratulations, " + name + "! You got a new high score! You scored: " + str(final_score))
elif final_score == highscores[0]:
print("\nCongratulations, " + name + "! You tied for the high score! You scored: " + str(final_score))
elif final_score > highscores[1]:
print("\nCongratulations, " + name + "! You scored the second highest score! You scored: " + str(final_score))
elif final_score == highscores[1]:
print("\nCongratulations, " + name + "! You tied for second in high score! You scored: " + str(final_score))
elif final_score > highscores[2]:
print("\nCongratulations, " + name + "! You scored the third highest score! You scored: " + str(final_score))
elif final_score == highscores[2]:
print("\nCongratulations, " + name + "! You tied for third in high score! You scored: " + str(final_score))
else:
print("\nBetter luck next time, " + name + ". You scored: " + str(final_score) + "\n")

print("Highscores:")
print(" (1): 323 - ACF - 12/29/21")
print(" (2): 267 - EAF - 12/29/21")
print(" (3): 227 - ACF - 12/28/21")

You might also like