Add boggle board randomizer given a 'dice' file

This commit is contained in:
2022-01-05 18:52:08 -05:00
parent 287476f7b4
commit 9cca821805
2 changed files with 52 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
from sys import argv
from random import randint
def readDiceFile(path):
with open(path, 'r+') as f:
# Ignore first two lines
f.readline()
f.readline()
dice = []
line = ''.join(f.readline().rstrip().split(','))
while(line):
dice.append(line)
line = ''.join(f.readline().rstrip().split(','))
return dice
def rollDie(die):
return str(die[randint(0, len(die) - 1)])
def rollDice(dice):
rolls = []
for die in dice:
roll = rollDie(die)
rolls.append(roll)
return rolls
if __name__ == '__main__':
if len(argv) != 2:
print('Usage: python3 board_randomizer DICE_FILE')
else:
dice = readDiceFile(argv[1])
print(dice)
print(rollDice(dice))
+18
View File
@@ -0,0 +1,18 @@
front,right,back,left,top,bottom (start with 'one of' the first alphabetical chars
-----------
a,h,s,p,o,c
e,r,l,i,x,d
a,g,a,e,e,a
e,y,t,l,r,t
e,o,t,s,s,i
d,r,y,v,l,e
h,n,l,n,z,r
e,r,w,t,v,h
h,i,u,n,m,qu
e,e,h,n,w,g
d,t,y,t,i,s
a,b,b,o,o,j
e,i,u,n,s,e
a,s,p,f,k,f
c,m,u,o,i,t
a,w,t,o,o,t