Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randrange
- # Function 1
- def checkMultiplier(multiplier):
- if multiplier < 1 or multiplier > 3.5:
- print(str(multiplier) + " is not an acceptable value.")
- print("Try to insert a value between 1 and 3.5")
- multiplier = float(input("Multiplier: "))
- return checkMultiplier(multiplier)
- else:
- print(str(multiplier) + " is a nice choice of multiplier.")
- return multiplier
- # FUNCTION 2
- def checkTarget(target, targetLimit):
- if target < targetLimit:
- print("Target points must be greater or equal than " + str(targetLimit))
- target = int(input("Target points: "))
- return checkTarget(target, targetLimit)
- else:
- print("Target = " + str(target))
- return target
- # FUNCTION 3
- def dice():
- return randrange(1, 7), randrange(1, 7)
- # FUNCTION 4
- def show(list1, list2, multiplier):
- if len(list1) != len(list2):
- print("ERROR with lists' lengths")
- return -1000
- points1Real = 0
- points1 = 0
- points2Real = 0
- points2 = 0
- print(" THOMAS | USER")
- print("Dice Points | Dice Points")
- for i in range(len(list1)):
- result = " " + str(list1[i]) + " " + str(list1[i]) + " |"
- result += " " + str(list2[i]) + " "
- if list2[i] == 6:
- points2 += multiplier * 6
- result += str(points2)
- else:
- result += "0"
- print(result)
- # Print sums
- print("-----------------------------------")
- points1Real = sum(list1)
- points1 = points1Real
- points2Real = sum(list2)
- print(" " + str(points1Real) + " " + str(points1) + " | " + str(points2Real) + " " + str(points2))
- return points1, points2
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # MAIN FUNCTION
- # 1. Intro
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- print("Hello user, let's play a game with dice.")
- print("I will inform you about my strategy and how I am taking points in our game.")
- print("Then, I will let you know about your strategy and I will let you make a decision.")
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- print("!!!! THOMAS !!!! I will take so many points as the dice throw result.")
- print("!!!!! USER !!!!! Your dice throws will count when you throw 6, but with a multiplier.")
- print("You can maybe win without a multiplier if you throw many 6-s, but I want the game to be fair.")
- print("So, I want you to tell me the multiplier in 6-s. Be logic. Don't write down 4,5,6,...")
- print("Typical values of multiplier are close to 2. You can write 1.5 or 2.5 also or other numbers.")
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- # 2. Choose multiplier value
- multiplier = float(input("Multiplier: "))
- multiplier = checkMultiplier(multiplier)
- # 3. Let the game begin
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- print("Computer will create randomly numbers from 1 to 6 for THOMAS and USER")
- target = int(input("Target points: "))
- targetLimit = 40
- target = checkTarget(target, targetLimit)
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- # 4. Let the game begin
- print("Multiplier = " + str(multiplier) + ", target = " + str(target))
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- print()
- print()
- thomasPoints = 0
- userPoints = 0
- thomasList = list()
- userList = list()
- counter = 0
- while thomasPoints < target and userPoints < target:
- counter += 1
- print("~~~~~~~~~~~~~ Round " + str(counter) + " ~~~~~~~~~~~~~")
- thomasDice, userDice = dice()
- print("THOMAS ----> " + str(thomasDice) + ", USER ----> " + str(userDice))
- thomasList.append(thomasDice)
- userList.append(userDice)
- thomasPoints, userPoints = show(thomasList, userList, multiplier)
- print()
- if thomasPoints == userPoints:
- print("Game over after " + str(counter) + " rounds! It's a tie!")
- else:
- result = "Game Over after " + str(counter) + " rounds! "
- winner = ""
- if thomasPoints > userPoints:
- winner = "THOMAS"
- else:
- winner = "USER"
- result += winner + " wins!"
- print(result)
- print("Score: THOMAS - USER : " + str(thomasPoints) + " - " + str(userPoints))
- print("Average THOMAS dice throw: " + str(round(thomasPoints / counter, 2)))
- print("Average USER dice throw: " + str(round(userPoints/ counter, 2)) + " = " + str(multiplier) + " * " + str(round(userPoints/counter/multiplier, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement