I was asked to program the following:
Develop a two-player dice game that will have the players roll two 6-sided dice each and get points depending on what they roll. There are 5 rounds in a game. In each round, each player rolls the two dice. The rules are:
- The points rolled on each player’s dice are added to their score.
- If the total is an even number, an additional 10 points are added to their score.
- If the total is an odd number, 5 points are subtracted from their score.
- If they roll a double, they get to roll one extra die and get the number of points rolled added to their score.
- The score of a player cannot go below 0 at any point.
- The person with the highest score at the end of the 5 rounds wins.
- If both players have the same score at the end of the 5 rounds, they each roll 1 die and whoever gets the highest score wins (this repeats until someone wins).
Here is what I came up with but I think it is inefficient and too long:
import time
import random
import sys
print("\nRound 1 is about to commence!")
time.sleep(3)
print("\nPlayer 1's dice is rolling....")
time.sleep(3)
P1Rnd1Dice = random.randint(1,6)
P1Rnd1Dice2 = random.randint(1,6)
print("\nPlayer 1 has rolled a", P1Rnd1Dice, "and a", P1Rnd1Dice2)
time.sleep(3)
print("\nPlayer 2's dice is rolling....")
time.sleep(3)
P2Rnd1Dice = random.randint(1,6)
P2Rnd1Dice2 = random.randint(1,6)
print("\nPlayer 2 has rolled a", P2Rnd1Dice, "and a", P2Rnd1Dice2)
time.sleep(3)
P1OvrScore = 0
P1Rnd1Roll = P1Rnd1Dice + P1Rnd1Dice2
P1OvrScore = P1OvrScore + P1Rnd1Roll
print("\nPlayer 1's round 1 throw sums up to", P1Rnd1Roll,"which is added to their total score to give them", P1OvrScore, "overall")
time.sleep(4)
if P1Rnd1Roll % 2 == 0:
P1OvrScore = P1OvrScore + 10
print("\nIn addition, Player 1's total is an even number, so they get an additional 10 points added to their score, which is now", P1OvrScore)
time.sleep(4)
else:
P1OvrScore = P1OvrScore - 5
print("\nIn addition, Player 1's total is an odd number, so they get 5 points taken away from their score, which is now", P1OvrScore)
time.sleep(4)
if P1Rnd1Dice == P1Rnd1Dice2:
P1Rnd1BnsDice = random.randint(1,6)
P1OvrScore = P1OvrScore + P1Rnd1BnsDice
print("\nFurthermore, Player 1 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 1's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 1's bonus roll has resulted in a", P1Rnd1BnsDice, ", which is added to their total to give them", P1OvrScore)
time.sleep(4)
P2OvrScore = 0
P2Rnd1Roll = P2Rnd1Dice + P2Rnd1Dice2
P2OvrScore = P2OvrScore + P2Rnd1Roll
print("\nPlayer 2's round 1 throw sums up to", P2Rnd1Roll,"which is added to their total score to give them", P2OvrScore, "overall")
time.sleep(4)
if P2Rnd1Roll % 2 == 0:
P2OvrScore = P2OvrScore + 10
print("\nIn addition, Player 2's total is an even number, so they get an additional 10 points added to their score, which is now", P2OvrScore)
time.sleep(4)
else:
P2OvrScore = P2OvrScore - 5
print("\nIn addition, Player 2's total is an odd number, so they get 5 points taken away from their score, which is now", P2OvrScore)
time.sleep(4)
if P2Rnd1Dice == P2Rnd1Dice2:
P2Rnd1BnsDice = random.randint(1,6)
P2OvrScore = P2OvrScore + P2Rnd1BnsDice
print("\nFurthermore, Player 2 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 2's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 2's bonus roll has resulted in a", P2Rnd1BnsDice, ", which is added to their total to give them", P2OvrScore)
time.sleep(4)
if P1OvrScore < 0 and P2OvrScore > 0:
print("\nAfter the conclusion of round 1, Player 1's total is below 0 and Player 2's total is greater than 0, meaning Player 2 automatically wins!")
sys.exit()
elif P1OvrScore > 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 1, Player 2's total is below 0 and Player 1's total is greater than 0, meaning Player 1 automatically wins!")
sys.exit()
elif P1OvrScore < 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 1, both Player 1's total and Player 2's total is below 0, meaning both players lose")
sys.exit()
else:
print("\nAfter the conclusion of round 1, both players' totals are above 0, meaning they can continue onto round 2")
time.sleep(4)
#_______________________________________________________________ End of round 1 ______________________________________________ Next: Round 2 __________________________________________________#
print("\nRound 2 is about to commence!")
time.sleep(3)
print("\nPlayer 1's dice is rolling....")
time.sleep(3)
P1Rnd2Dice = random.randint(1,6)
P1Rnd2Dice2 = random.randint(1,6)
print("\nPlayer 1 has rolled a", P1Rnd2Dice, "and a", P1Rnd2Dice2)
time.sleep(3)
print("\nPlayer 2's dice is rolling....")
time.sleep(3)
P2Rnd2Dice = random.randint(1,6)
P2Rnd2Dice2 = random.randint(1,6)
print("\nPlayer 2 has rolled a", P2Rnd2Dice, "and a", P2Rnd2Dice2)
time.sleep(3)
P1Rnd2Roll = P1Rnd2Dice + P1Rnd2Dice2
P1OvrScore = P1OvrScore + P1Rnd2Roll
print("\nPlayer 1's round 2 throw sums up to", P1Rnd2Roll,"which is added to their total score to give them", P1OvrScore, "overall")
time.sleep(4)
if P1Rnd2Roll % 2 == 0:
P1OvrScore = P1OvrScore + 10
print("\nIn addition, Player 1's total is an even number, so they get an additional 10 points added to their score, which is now", P1OvrScore)
time.sleep(4)
else:
P1OvrScore = P1OvrScore - 5
print("\nIn addition, Player 1's total is an odd number, so they get 5 points taken away from their score, which is now", P1OvrScore)
time.sleep(4)
if P1Rnd2Dice == P1Rnd2Dice2:
P1Rnd2BnsDice = random.randint(1,6)
P1OvrScore = P1OvrScore + P1Rnd2BnsDice
print("\nFurthermore, Player 1 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 1's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 1's bonus roll has resulted in a", P1Rnd2BnsDice, ", which is added to their total to give them", P1OvrScore)
time.sleep(4)
P2Rnd2Roll = P2Rnd2Dice + P2Rnd2Dice2
P2OvrScore = P2OvrScore + P2Rnd2Roll
print("\nPlayer 2's round 2 throw sums up to", P2Rnd2Roll,"which is added to their total score to give them", P2OvrScore, "overall")
time.sleep(4)
if P2Rnd2Roll % 2 == 0:
P2OvrScore = P2OvrScore + 10
print("\nIn addition, Player 2's total is an even number, so they get an additional 10 points added to their score, which is now", P2OvrScore)
time.sleep(4)
else:
P2OvrScore = P2OvrScore - 5
print("\nIn addition, Player 2's total is an odd number, so they get 5 points taken away from their score, which is now", P2OvrScore)
time.sleep(4)
if P2Rnd2Dice == P2Rnd2Dice2:
P2Rnd2BnsDice = random.randint(1,6)
P2OvrScore = P2OvrScore + P2Rnd2BnsDice
print("\nFurthermore, Player 2 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 2's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 2's bonus roll has resulted in a", P2Rnd2BnsDice, ", which is added to their total to give them", P2OvrScore)
time.sleep(4)
if P1OvrScore < 0 and P2OvrScore > 0:
print("\nAfter the conclusion of round 2, Player 1's total is below 0 and Player 2's total is greater than 0, meaning Player 2 automatically wins!")
sys.exit()
elif P1OvrScore > 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 2, Player 2's total is below 0 and Player 1's total is greater than 0, meaning Player 1 automatically wins!")
sys.exit()
elif P1OvrScore < 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 2, both Player 1's total and Player 2's total is below 0, meaning both players lose")
sys.exit()
else:
print("\nAfter the conclusion of round 2, both players' totals are above 0, meaning they can continue onto round 2")
time.sleep(4)
#_______________________________________________________________ End of round 2 ______________________________________________ Next: Round 3 __________________________________________________#
print("\nRound 3 is about to commence!")
time.sleep(3)
print("\nPlayer 1's dice is rolling....")
time.sleep(3)
P1Rnd3Dice = random.randint(1,6)
P1Rnd3Dice2 = random.randint(1,6)
print("\nPlayer 1 has rolled a", P1Rnd3Dice, "and a", P1Rnd3Dice2)
time.sleep(3)
print("\nPlayer 2's dice is rolling....")
time.sleep(3)
P2Rnd3Dice = random.randint(1,6)
P2Rnd3Dice2 = random.randint(1,6)
print("\nPlayer 2 has rolled a", P2Rnd3Dice, "and a", P2Rnd3Dice2)
time.sleep(3)
P1Rnd3Roll = P1Rnd3Dice + P1Rnd3Dice2
P1OvrScore = P1OvrScore + P1Rnd3Roll
print("\nPlayer 1's round 3 throw sums up to", P1Rnd3Roll,"which is added to their total score to give them", P1OvrScore, "overall")
time.sleep(4)
if P1Rnd3Roll % 2 == 0:
P1OvrScore = P1OvrScore + 10
print("\nIn addition, Player 1's total is an even number, so they get an additional 10 points added to their score, which is now", P1OvrScore)
time.sleep(4)
else:
P1OvrScore = P1OvrScore - 5
print("\nIn addition, Player 1's total is an odd number, so they get 5 points taken away from their score, which is now", P1OvrScore)
time.sleep(4)
if P1Rnd3Dice == P1Rnd3Dice2:
P1Rnd3BnsDice = random.randint(1,6)
P1OvrScore = P1OvrScore + P1Rnd3BnsDice
print("\nFurthermore, Player 1 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 1's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 1's bonus roll has resulted in a", P1Rnd3BnsDice, ", which is added to their total to give them", P1OvrScore)
time.sleep(4)
P2Rnd3Roll = P2Rnd3Dice + P2Rnd3Dice2
P2OvrScore = P2OvrScore + P2Rnd3Roll
print("\nPlayer 2's round 3 throw sums up to", P2Rnd3Roll,"which is added to their total score to give them", P2OvrScore, "overall")
time.sleep(4)
if P2Rnd3Roll % 2 == 0:
P2OvrScore = P2OvrScore + 10
print("\nIn addition, Player 2's total is an even number, so they get an additional 10 points added to their score, which is now", P2OvrScore)
time.sleep(4)
else:
P2OvrScore = P2OvrScore - 5
print("\nIn addition, Player 2's total is an odd number, so they get 5 points taken away from their score, which is now", P2OvrScore)
time.sleep(4)
if P2Rnd3Dice == P2Rnd3Dice2:
P2Rnd3BnsDice = random.randint(1,6)
P2OvrScore = P2OvrScore + P2Rnd3BnsDice
print("\nFurthermore, Player 2 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 2's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 2's bonus roll has resulted in a", P2Rnd3BnsDice, ", which is added to their total to give them", P2OvrScore)
time.sleep(4)
if P1OvrScore < 0 and P2OvrScore > 0:
print("\nAfter the conclusion of round 3, Player 1's total is below 0 and Player 2's total is greater than 0, meaning Player 2 automatically wins!")
sys.exit()
elif P1OvrScore > 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 3, Player 2's total is below 0 and Player 1's total is greater than 0, meaning Player 1 automatically wins!")
sys.exit()
elif P1OvrScore < 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 3, both Player 1's total and Player 2's total is below 0, meaning both players lose")
sys.exit()
else:
print("\nAfter the conclusion of round 3, both players' totals are above 0, meaning they can continue onto round 2")
time.sleep(4)
#_______________________________________________________________ End of round 3 ______________________________________________ Next: Round 4 __________________________________________________#
print("\nRound 4 is about to commence!")
time.sleep(3)
print("\nPlayer 1's dice is rolling....")
time.sleep(3)
P1Rnd4Dice = random.randint(1,6)
P1Rnd4Dice2 = random.randint(1,6)
print("\nPlayer 1 has rolled a", P1Rnd4Dice, "and a", P1Rnd4Dice2)
time.sleep(3)
print("\nPlayer 2's dice is rolling....")
time.sleep(3)
P2Rnd4Dice = random.randint(1,6)
P2Rnd4Dice2 = random.randint(1,6)
print("\nPlayer 2 has rolled a", P2Rnd4Dice, "and a", P2Rnd4Dice2)
time.sleep(3)
P1Rnd4Roll = P1Rnd4Dice + P1Rnd4Dice2
P1OvrScore = P1OvrScore + P1Rnd4Roll
print("\nPlayer 1's round 4 throw sums up to", P1Rnd4Roll,"which is added to their total score to give them", P1OvrScore, "overall")
time.sleep(4)
if P1Rnd4Roll % 2 == 0:
P1OvrScore = P1OvrScore + 10
print("\nIn addition, Player 1's total is an even number, so they get an additional 10 points added to their score, which is now", P1OvrScore)
time.sleep(4)
else:
P1OvrScore = P1OvrScore - 5
print("\nIn addition, Player 1's total is an odd number, so they get 5 points taken away from their score, which is now", P1OvrScore)
time.sleep(4)
if P1Rnd4Dice == P1Rnd4Dice2:
P1Rnd4BnsDice = random.randint(1,6)
P1OvrScore = P1OvrScore + P1Rnd4BnsDice
print("\nFurthermore, Player 1 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 1's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 1's bonus roll has resulted in a", P1Rnd4BnsDice, ", which is added to their total to give them", P1OvrScore)
time.sleep(4)
P2Rnd4Roll = P2Rnd4Dice + P2Rnd4Dice2
P2OvrScore = P2OvrScore + P2Rnd4Roll
print("\nPlayer 2's round 2 throw sums up to", P2Rnd4Roll,"which is added to their total score to give them", P2OvrScore, "overall")
time.sleep(4)
if P2Rnd4Roll % 2 == 0:
P2OvrScore = P2OvrScore + 10
print("\nIn addition, Player 2's total is an even number, so they get an additional 10 points added to their score, which is now", P2OvrScore)
time.sleep(4)
else:
P2OvrScore = P2OvrScore - 5
print("\nIn addition, Player 2's total is an odd number, so they get 5 points taken away from their score, which is now", P2OvrScore)
time.sleep(4)
if P2Rnd4Dice == P2Rnd4Dice2:
P2Rnd4BnsDice = random.randint(1,6)
P2OvrScore = P2OvrScore + P2Rnd4BnsDice
print("\nFurthermore, Player 2 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 2's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 2's bonus roll has resulted in a", P2Rnd4BnsDice, ", which is added to their total to give them", P2OvrScore)
time.sleep(4)
if P1OvrScore < 0 and P2OvrScore > 0:
print("\nAfter the conclusion of round 4, Player 1's total is below 0 and Player 2's total is greater than 0, meaning Player 2 automatically wins!")
sys.exit()
elif P1OvrScore > 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 4, Player 2's total is below 0 and Player 1's total is greater than 0, meaning Player 1 automatically wins!")
sys.exit()
elif P1OvrScore < 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 4, both Player 1's total and Player 2's total is below 0, meaning both players lose")
sys.exit()
else:
print("\nAfter the conclusion of round 4, both players' totals are above 0, meaning they can continue onto round 2")
time.sleep(4)
#_______________________________________________________________ End of round 4 ______________________________________________ Next: Round 5 __________________________________________________#
print("\nRound 5 is about to commence!")
time.sleep(3)
print("\nPlayer 1's dice is rolling....")
time.sleep(3)
P1Rnd5Dice = random.randint(1,6)
P1Rnd5Dice2 = random.randint(1,6)
print("\nPlayer 1 has rolled a", P1Rnd5Dice, "and a", P1Rnd5Dice2)
time.sleep(3)
print("\nPlayer 2's dice is rolling....")
time.sleep(3)
P2Rnd5Dice = random.randint(1,6)
P2Rnd5Dice2 = random.randint(1,6)
print("\nPlayer 2 has rolled a", P2Rnd5Dice, "and a", P2Rnd5Dice2)
time.sleep(3)
P1Rnd5Roll = P1Rnd5Dice + P1Rnd5Dice2
P1OvrScore = P1OvrScore + P1Rnd5Roll
print("\nPlayer 1's round 5 throw sums up to", P1Rnd5Roll,"which is added to their total score to give them", P1OvrScore, "overall")
time.sleep(4)
if P1Rnd5Roll % 2 == 0:
P1OvrScore = P1OvrScore + 10
print("\nIn addition, Player 1's total is an even number, so they get an additional 10 points added to their score, which is now", P1OvrScore)
time.sleep(4)
else:
P1OvrScore = P1OvrScore - 5
print("\nIn addition, Player 1's total is an odd number, so they get 5 points taken away from their score, which is now", P1OvrScore)
time.sleep(4)
if P1Rnd5Dice == P1Rnd5Dice2:
P1Rnd5BnsDice = random.randint(1,6)
P1OvrScore = P1OvrScore + P1Rnd5BnsDice
print("\nFurthermore, Player 1 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 1's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 1's bonus roll has resulted in a", P1Rnd5BnsDice, ", which is added to their total to give them", P1OvrScore)
time.sleep(4)
P2Rnd5Roll = P2Rnd5Dice + P2Rnd5Dice2
P2OvrScore = P2OvrScore + P2Rnd5Roll
print("\nPlayer 2's round 5 throw sums up to", P2Rnd5Roll,"which is added to their total score to give them", P2OvrScore, "overall")
time.sleep(4)
if P2Rnd5Roll % 2 == 0:
P2OvrScore = P2OvrScore + 10
print("\nIn addition, Player 2's total is an even number, so they get an additional 10 points added to their score, which is now", P2OvrScore)
time.sleep(4)
else:
P2OvrScore = P2OvrScore - 5
print("\nIn addition, Player 2's total is an odd number, so they get 5 points taken away from their score, which is now", P2OvrScore)
time.sleep(4)
if P2Rnd5Dice == P2Rnd5Dice2:
P2Rnd5BnsDice = random.randint(1,6)
P2OvrScore = P2OvrScore + P2Rnd5BnsDice
print("\nFurthermore, Player 2 has rolled a double and therefore recieves an extra roll")
time.sleep(4)
print("\nPlayer 2's bonus dice is rolling...")
time.sleep(3)
print("\nPlayer 2's bonus roll has resulted in a", P2Rnd5BnsDice, ", which is added to their total to give them", P2OvrScore)
time.sleep(4)
if P1OvrScore < 0 and P2OvrScore > 0:
print("\nAfter the conclusion of round 5, Player 1's total is below 0 and Player 2's total is greater than 0, meaning Player 2 automatically wins!")
sys.exit()
elif P1OvrScore > 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 5, Player 2's total is below 0 and Player 1's total is greater than 0, meaning Player 1 automatically wins!")
sys.exit()
elif P1OvrScore < 0 and P2OvrScore < 0:
print("\nAfter the conclusion of round 5, both Player 1's total and Player 2's total is below 0, meaning both players lose.")
sys.exit()
#_______________________________________________________________ End of round 5 ______________________________________________ Next: Conclusion + Declaration of winner __________________________________________________#
if P1OvrScore > P2OvrScore:
print("\nFollowing the end of round 5, the game is now over. Player 1 has finished with a total of", P1OvrScore,"and Player 2 has finished with a total of", P2OvrScore)
print("\nThis means that Player 1 has won the game after finishing with a higher total than Player 2")
elif P1OvrScore < P2OvrScore:
print("\nFollowing the end of round 5, the game is now over. Player 1 has finished with a total of", P1OvrScore,"and Player 2 has finished with a total of", P2OvrScore)
print("\nThis means that Player 2 has won the game after finishing with a higher total than Player 1")
elif P1OvrScore == P2OvrScore:
print("\nFollowing the end of round 5, the game is now over. Player 1 has finished with a total of", P1OvrScore,"and Player 2 has finished with a total of", P2OvrScore)
print("\nThis means that neither Player 1 or Player 2 has won the game after they both finish with the same total")
Could anyone help me make this shorter and more efficient?