【Baldur's Gate 3】DND基礎(chǔ)知識【走進(jìn)博德之門3】


import time
import random
"""
Y: Expected value
X: Dice count
DMAX: max value of Dice
"""
MAX_LOOP = 1000000
MODE = 1 # 0 use simple aglorithms
def calculate(X, DMAX):
Y = (DMAX - X ) / 2 + X
return Y
if MODE == 0:
dice_count = int(eval(input("請輸入骰子數(shù)量: ")))
max_value = int(eval(input("請輸入骰子面數(shù): "))) * dice_count
expected_value = calculate(dice_count, max_value)
print("數(shù)學(xué)期望是:??", expected_value)
time.sleep(5)
exit(0)
if MODE == 1:
aglo = input("print enter calculation?aglorithms, such '2d6'\t")
aglo_list = aglo.split('d')
dice_count = int(aglo_list[0])
dice_max = int(aglo_list[-1])
print("你輸入的骰子是{0}D{1}".format(dice_count, dice_max))
output = 0
for _ in range(MAX_LOOP):
once_roll = 0
for count in range(dice_count):
roll = random.randint(1,dice_max)
once_roll += roll
output += once_roll / MAX_LOOP
print("{0}次擲骰結(jié)果: {1}".format(MAX_LOOP, output))
time.sleep(5)
exit(0)