-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
621c5a4
commit 27ab54c
Showing
5 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[["project","index","diceroll","tutorial"],["Project Summary","Welcome to diceroll’s documentation!","diceroll module","diceroll Tutorial"],{"currentmodul":[],"show":[],"dtotal":[2],"d8":[2],"d9":[2],"d6":[2],"d4":[2],"d3":[2],"1":[0,2],"depend":[1],"dice":[2],"how":[3],"d30":[2],"should":[1],"0":[2],"add":[2],"program":[2],"4":[1,2],"2017":[1],"dm":[2],"return":[2],"python":[1],"dd":[2],"autodocu":[],"print":[2],"know":[],"requir":[1],"introduct":[1],"like":[1],"die":[2],"try":[],"flux":[2],"achiev":[0,1],"t":[],"contain":[1],"x":[2],"page":[1],"summari":[0,1],"d100":[2],"sep":[1],"some":[2],"direct":[1],"second":[0],"toctre":[1],"project":[0,1],"what":[0],"for":[2],"05":[1],"08":[1],"content":[1],"3":[2],"version":[2],"adapt":[1],"undoc":[],"import":[2,3],"die_rol":[2],"learn":[0,1],"usag":[2],"goodflux":[2],"releas":[2],"100":[2],"by":[1],"valu":[2],"on":[0,1,2],"about":[3],"of":[0,2],"31":[1],"30":[1],"manag":[0],"s":[1],"tutori":[1,3],"place":[],"d66":[2],"or":[2],"first":[0],"dtype":[2],"modul":[1,2],"number":[2],"8217":[1],"lesson":[0,1],"your":[1],"from":[0,2,3],"describ":[0],"to":[0,1,2,3],"unknown":[],"two":[2],"least":[1],"name":[],"2":[0,1],"master":[1],"6":[2],"badflux":[2],"type":[2],"3d6":[2],"option":[],"search":[1],"but":[1],"it":[1],"1d6":[2],"short":[3],"sphinx":[1],"info":[2],"10":[2],"us":[3],"will":[2],"paragraph":[0],"can":[1],"error":[],"root":[1],"and":[1],"quickstart":[1],"creat":[1],"give":[],"int":[2],"descript":[0,3],"is":[0,1,3],"dcount":[2],"side":[2],"argument":[2],"indic":[1],"an":[2],"ar":[2],"at":[1],"file":[1],"tabl":[1],"my":[0,1],"sat":[1],"d10":[2],"welcom":[1],"in":[],"titl":[0],"invalid":[2],"member":[],"2dd":[2],"5":[1,2],"which":[],"dicerul":[3],"you":[1],"document":[1],"roll":[2,3],"complet":[0,1],"index":[1],"chart":[2],"automodul":[],"4d4":[2],"a":[0,2,3],"bysourc":[],"2d6":[2],"don":[],"d12":[2],"i":[0],"d20":[2],"goal":[0,1],"explicit":[],"inherit":[],"exampl":[2],"u":[],"thi":[0,1,3],"the":[0,1,2],"order":[],"dicerol":[1,2,3]}] | ||
[["project","index","diceroll","tutorial"],["Project Summary","Welcome to diceroll’s documentation!","diceroll module","diceroll Tutorial"],{"dtotal":[2],"d8":[2],"d9":[2],"d6":[2],"d4":[2],"d3":[2],"depend":[1],"dice":[2],"2dd":[2],"d30":[2],"should":[1],"0":[2],"add":[2],"program":[2],"4":[1,2],"2017":[1],"dm":[2],"return":[2],"python":[1],"dd":[2],"requir":[1],"introduct":[1],"like":[1],"die":[2],"flux":[2],"achiev":[0,1],"contain":[1],"x":[2],"manag":[0],"summari":[0,1],"d100":[2],"sep":[1],"some":[2],"direct":[1],"second":[0],"toctre":[1],"will":[2],"what":[0],"for":[2],"05":[1],"08":[1],"content":[1],"3":[2],"version":[2],"adapt":[1],"print":[2],"import":[2,3],"die_rol":[2],"usag":[2],"goodflux":[2],"releas":[2],"100":[2],"by":[1],"valu":[2],"on":[0,1,2],"about":[3],"of":[0,2],"31":[1],"30":[1],"page":[1],"s":[1],"tutori":[1,3],"d66":[2],"or":[2],"first":[0],"dtype":[2],"modul":[1,2],"number":[2],"8217":[1],"lesson":[0,1],"your":[1],"from":[0,2,3],"describ":[0],"to":[0,1,2,3],"two":[2],"least":[1],"2":[0,1],"master":[1],"6":[2],"badflux":[2],"type":[2],"3d6":[2],"search":[1],"but":[1],"argument":[2],"1d6":[2],"2d6":[2],"info":[2],"10":[2],"us":[3],"project":[0,1],"paragraph":[0],"can":[1],"learn":[0,1],"root":[1],"and":[1],"quickstart":[1],"creat":[1],"int":[2],"is":[0,1,3],"dcount":[2],"side":[2],"it":[1],"indic":[1],"an":[2],"ar":[2],"at":[1],"file":[1],"tabl":[1],"my":[0,1],"sat":[1],"d10":[2],"welcom":[1],"d12":[2],"titl":[0],"invalid":[2],"1":[0,2],"how":[3],"5":[1,2],"dicerul":[3],"you":[1],"document":[1],"roll":[2,3],"complet":[0,1],"index":[1],"chart":[2],"4d4":[2],"a":[0,2,3],"short":[3],"sphinx":[1],"i":[0],"d20":[2],"goal":[0,1],"descript":[0,3],"exampl":[2],"thi":[0,1,3],"the":[0,1,2],"dicerol":[1,2,3]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
# | ||
# Written for Python 2.5.4 | ||
# | ||
# To use this module: from diceroll import roll | ||
# | ||
# Make a dice roll | ||
# | ||
########################################################## | ||
|
||
''' | ||
Usage: | ||
from diceroll import roll | ||
print roll('2D6') - roll two 6-sided dice | ||
''' | ||
|
||
from random import randint | ||
import os | ||
import logging | ||
|
||
__version__ = '2.2' | ||
__release__ = '2.2.1 (Beta)' | ||
__author__ = 'Shawn Driscoll <shawndriscoll@hotmail.com>\nshawndriscoll.blogspot.com' | ||
|
||
module_log = logging.getLogger('diceroll') | ||
module_log.setLevel(logging.INFO) | ||
|
||
if not os.path.exists('Logs'): | ||
os.mkdir('Logs') | ||
|
||
fh = logging.FileHandler('Logs/diceroll.log', 'w') | ||
|
||
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(message)s', | ||
datefmt = '%a, %d %b %Y %H:%M:%S') | ||
fh.setFormatter(formatter) | ||
module_log.addHandler(fh) | ||
|
||
module_log.info('Logging started.') | ||
module_log.info('roll() v' + __version__ + ' started, and running...') | ||
|
||
number_of_dice = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'] | ||
|
||
def die_rolls(dtype, dcount): | ||
''' | ||
Two arguments: | ||
dtype: the number of sides for the dice (int) | ||
dcount: the number of dice to roll (int) | ||
Value returned: | ||
dtotal: the value returned from die_rolls (int) | ||
''' | ||
|
||
dtotal = 0 | ||
if dcount == 1: | ||
module_log.debug('Using %s %d-sided die...' % (number_of_dice[dcount], dtype)) | ||
else: | ||
if dcount < 11: | ||
module_log.debug('Using %s %d-sided dice...' % (number_of_dice[dcount], dtype)) | ||
else: | ||
module_log.debug('Using %d %d-sided dice...' % (dcount, dtype)) | ||
|
||
for i in range(dcount): | ||
rolled = randint(1, dtype) | ||
if rolled == 8 or rolled == 18: | ||
module_log.debug('Rolled an %s' % rolled) | ||
else: | ||
module_log.debug('Rolled a %s' % rolled) | ||
dtotal += rolled | ||
return dtotal | ||
|
||
def roll(dice): | ||
''' | ||
The dice types to roll are: D3, D4, D6, D8, D9, D10, D12, D20, D30, D100, D66, DD, FLUX, GOODFLUX, BADFLUX | ||
Some examples are: | ||
roll('D6') or roll('1D6') -- roll one 6-sided die | ||
roll('2D6') -- roll two 6-sided dice | ||
roll('D10') -- roll a 10-sided die (1 - 10) | ||
roll('D100') -- roll a 100-sided die (1 - 100) | ||
roll('D66') -- roll for a D66 chart | ||
roll('FLUX') -- a FLUX roll (-5 to 5) | ||
roll('3D6+6') -- add +6 DM to roll | ||
roll('4D4-4') -- add -4 DM to roll | ||
roll('2DD+3') -- roll (2D6+3) x 10 | ||
roll('info') -- release version of program | ||
An invalid roll will return a 0 (int). | ||
''' | ||
|
||
log = logging.getLogger('Imperial_Chargen_085b.diceroll') | ||
|
||
if dice == 'info': | ||
ver = 'roll(), release version ' + __release__ + ' for Python 2.5.4' | ||
module_log.info('roll() release version: %s' % __release__) | ||
return __version__, ver | ||
|
||
dice = str(dice).upper().strip() | ||
|
||
log.debug(dice) | ||
module_log.debug('Asked to roll %s:' % dice) | ||
|
||
dice_mod = 0 | ||
|
||
if dice == 'FLUX': | ||
flux1 = randint(1, 6) | ||
flux2 = randint(1, 6) | ||
rolled = flux1 - flux2 | ||
module_log.info('%s = %d - %d = %d' % (dice, flux1, flux2, rolled)) | ||
return rolled | ||
else: | ||
if dice == 'GOODFLUX': | ||
flux1 = randint(1, 6) | ||
flux2 = randint(1, 6) | ||
if flux1 < flux2: | ||
rolled = flux2 - flux1 | ||
module_log.info('%s = %d - %d = %d' % (dice, flux2, flux1, rolled)) | ||
else: | ||
rolled = flux1 - flux2 | ||
module_log.info('%s = %d - %d = %d' % (dice, flux1, flux2, rolled)) | ||
return rolled | ||
else: | ||
if dice == 'BADFLUX': | ||
flux1 = randint(1, 6) | ||
flux2 = randint(1, 6) | ||
if flux1 > flux2: | ||
rolled = flux2 - flux1 | ||
module_log.info('%s = %d - %d = %d' % (dice, flux2, flux1, rolled)) | ||
else: | ||
rolled = flux1 - flux2 | ||
module_log.info('%s = %d - %d = %d' % (dice, flux1, flux2, rolled)) | ||
return rolled | ||
|
||
ichar1 = dice.find('DD') | ||
if ichar1 == -1: | ||
ichar1 = dice.find('D') | ||
if ichar1 == 0: | ||
num_dice = 1 | ||
|
||
if ichar1 <> -1: | ||
if ichar1 <> 0: | ||
num_dice = int(dice[0:ichar1]) | ||
# print 'Number of dice =', num_dice | ||
if num_dice < 1: | ||
log.error('Negative dice count! [ERROR]') | ||
module_log.error('Number of dice = ' + str(num_dice) + ' [ERROR]') | ||
|
||
if num_dice >= 1: | ||
ichar2 = dice.find('+') | ||
if ichar2 <> -1: | ||
dice_mod = int(dice[ichar2:len(dice)]) | ||
# print 'dice mod =', dice_mod | ||
else: | ||
ichar2 = dice.find('-') | ||
if ichar2 <> -1: | ||
dice_mod = int(dice[ichar2:len(dice)]) | ||
# print 'dice mod =', dice_mod | ||
|
||
if ichar2 <> -1: | ||
dice_type = dice[ichar1: ichar2] | ||
dice_type = dice_type.rstrip() | ||
else: | ||
dice_type = dice[ichar1: len(dice)] | ||
# print 'dice type =', dice_type, 'Len = ', len(dice_type) | ||
|
||
if dice_type == 'D6': | ||
rolled = die_rolls(6, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D66' and num_dice == 1 and dice_mod == 0: | ||
roll_1 = randint(1, 6) | ||
roll_2 = randint(1, 6) | ||
rolled = roll_1 * 10 + roll_2 | ||
module_log.info('%s = %d%s+%d = %d and %d = %d' % (dice, num_dice, dice_type, dice_mod, roll_1, roll_2, rolled)) | ||
return rolled | ||
elif dice_type == 'D100' and num_dice == 1: | ||
roll_1 = (randint(1, 10) - 1) * 10 | ||
roll_2 = randint(1, 10) | ||
rolled = roll_1 + roll_2 + dice_mod | ||
module_log.info('%s = %d%s+%d = %d and %d + %d = %d' % (dice, num_dice, dice_type, dice_mod, roll_1, roll_2, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D10': | ||
rolled = die_rolls(10, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D20': | ||
rolled = die_rolls(20, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D30': | ||
rolled = die_rolls(30, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D12': | ||
rolled = die_rolls(12, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D8': | ||
rolled = die_rolls(8, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D4': | ||
rolled = die_rolls(4, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D9': | ||
rolled = die_rolls(9, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'D3': | ||
rolled = die_rolls(3, num_dice) + dice_mod | ||
module_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
elif dice_type == 'DD': | ||
rolled = (die_rolls(6, num_dice) + dice_mod) * 10 | ||
module_log.info('%s = (%d%s+%d) * 10 = %d' % (dice, num_dice, dice_type, dice_mod, rolled)) | ||
return rolled | ||
|
||
log.error('Wrong dice type entered! [ERROR]') | ||
module_log.error('!!!!!!!!!!!!!!!!!!!!! DICE ERROR! ' + dice + ' is unknown !!!!!!!!!!!!!!!!!!!!!!!!!') | ||
|
||
print "** DICE ERROR! '%s' is unknown **" % dice | ||
print "The types of dice to roll are (in string values):" | ||
print "roll('D6') or roll('1D6') -- roll one 6-sided die" | ||
print "roll('2D6') -- roll two 6-sided dice" | ||
print "roll('D10') -- roll a 10-sided die (1 - 10)" | ||
print "roll('D100') -- roll a 100-sided die (1 - 100)" | ||
print "roll('D66') -- roll for a D66 chart" | ||
print "roll('FLUX') -- a FLUX roll (-5 to 5)" | ||
print "roll('2DD+3') -- roll (2D6+3) x 10" | ||
print "-/+ DMs can be added to rolls:" | ||
print "roll('3D6+6') -- add +6 DM to roll" | ||
print "roll('4D4-4') -- add -4 DM to roll" | ||
print "roll('info') -- release version of program" | ||
return 0 |