-
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
6dbe7fe
commit 83529ca
Showing
3 changed files
with
303 additions
and
52 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,47 +1,74 @@ | ||
|
||
########### | ||
##Eclipse | ||
########### | ||
.plugins/ | ||
.lock | ||
.log | ||
.ini | ||
.metadata/ | ||
.project | ||
.settings/ | ||
.pydevproject | ||
org.* | ||
com.* | ||
.classpath | ||
*.ini | ||
*.log | ||
/Debug | ||
/Release | ||
.cproject | ||
|
||
############# | ||
## Windows detritus | ||
############# | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
# Mac crap | ||
.DS_Store | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
############# | ||
## Python | ||
############# | ||
|
||
# ========================= | ||
# Operating System Files | ||
# ========================= | ||
*.pyx | ||
*.pyc | ||
|
||
# OSX | ||
# ========================= | ||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist/ | ||
build/ | ||
eggs/ | ||
parts/ | ||
var/ | ||
sdist/ | ||
develop-eggs/ | ||
.installed.cfg | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
############ | ||
## TI-GCC | ||
############ | ||
*.tpr | ||
*.89z | ||
*.9xz | ||
*.v2z | ||
*.o | ||
*.s | ||
|
||
########### | ||
## gcc | ||
########### | ||
*.exe | ||
|
||
########### | ||
## Jython | ||
########### | ||
*.class |
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,241 @@ | ||
# | ||
# Written for Python 2.5.4 | ||
# | ||
# To use this module: from diceroll import roll | ||
# | ||
# Make a dice roll for calling module | ||
# | ||
########################################################## | ||
|
||
'''Usage: from diceroll import roll''' | ||
|
||
from random import randint | ||
import os | ||
import logging | ||
|
||
__version__ = '2.2' | ||
__release__ = '2.2.1' | ||
__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 | ||
dcount: the number of dice to roll | ||
''' | ||
|
||
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 | ||
""" | ||
|
||
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 |