Small tweaks

This commit is contained in:
Luke Rogers 2012-03-13 00:40:37 +13:00
parent b1dece0edd
commit a1eb155b14
2 changed files with 7 additions and 6 deletions

View file

@ -41,5 +41,5 @@ def coin(inp):
return "You flip a coin and get " + sidename + "." return "You flip a coin and get " + sidename + "."
else: else:
flips = flip_simple(count) flips = flip_simple(count)
return "You flip %s coins and get "\ return "You flip %s coins and get " \
"%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1])) "%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1]))

View file

@ -9,7 +9,8 @@ from util import hook
whitespace_re = re.compile(r'\s+') whitespace_re = re.compile(r'\s+')
valid_diceroll = r'^([+-]?(?:\d+|\d*d(?:\d+|F))(?:[+-](?:\d+|\d*d(?:\d+|F)))*)( .+)?$' valid_diceroll = r'^([+-]?(?:\d+|\d*d(?:\d+|F))(?:[+-](?:\d+|\d*d(?:\d+|' \
'F)))*)( .+)?$'
valid_diceroll_re = re.compile(valid_diceroll, re.I) valid_diceroll_re = re.compile(valid_diceroll, re.I)
sign_re = re.compile(r'[+-]?(?:\d*d)?(?:\d+|F)', re.I) sign_re = re.compile(r'[+-]?(?:\d*d)?(?:\d+|F)', re.I)
split_re = re.compile(r'([\d+-]*)d?(F|\d*)', re.I) split_re = re.compile(r'([\d+-]*)d?(F|\d*)', re.I)
@ -23,12 +24,12 @@ def nrolls(count, n):
if count < 100: if count < 100:
return [random.randint(0, 1) for x in xrange(count)] return [random.randint(0, 1) for x in xrange(count)]
else: # fake it else: # fake it
return [int(random.normalvariate(.5*count, (.75*count)**.5))] return [int(random.normalvariate(.5 * count, (.75 * count) ** .5))]
else: else:
if count < 100: if count < 100:
return [random.randint(1, n) for x in xrange(count)] return [random.randint(1, n) for x in xrange(count)]
else: # fake it else: # fake it
return [int(random.normalvariate(.5*(1+n)*count, return [int(random.normalvariate(.5 * (1 + n) * count,
(((n+1)*(2*n+1)/6.-(.5*(1+n))**2)*count)**.5))] (((n+1)*(2*n+1)/6.-(.5*(1+n))**2)*count)**.5))]
@ -36,8 +37,8 @@ def nrolls(count, n):
#@hook.regex(valid_diceroll, re.I) #@hook.regex(valid_diceroll, re.I)
@hook.command @hook.command
def dice(inp): def dice(inp):
".dice <diceroll> -- Simulates dicerolls. Example of <diceroll>: '.dice 2d20-d5+4 roll 2'." \ ".dice <diceroll> -- Simulates dicerolls. Example of <diceroll>:" \
"D20s, subtract 1D5, add 4" " '.dice 2d20-d5+4 roll 2'. D20s, subtract 1D5, add 4"
try: # if inp is a re.match object... try: # if inp is a re.match object...
(inp, desc) = inp.groups() (inp, desc) = inp.groups()