5 Commits
Author SHA1 Message Date
cblanken bc70b88bf7 Bump version 2.0.0 2022-09-26 11:44:51 -04:00
cblanken 21aab46b96 Refactor board_randomizer
- Make file read separate and return "dice" or a list of strings from
  dice handling functions for use in downstream programs
2022-09-26 11:40:36 -04:00
cblanken f18c30cb60 Rename Super Big Boggle dice file 2022-09-23 10:20:48 -04:00
cblanken da915b723c Update wordlist splitting script
- Force lowercase on split
- Only match single (non compound) words
- Don't match punctuation
- Sort and uniquify
2022-09-23 10:20:48 -04:00
cblanken d5a102713d Fix die letters for 'New Boggle' dice 2022-09-23 10:20:38 -04:00
5 changed files with 39 additions and 39 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "boggler" name = "boggler"
version = "1.0.2" version = "2.0.0"
authors = [ authors = [
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" }, { name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
] ]
+10 -10
View File
@@ -4,9 +4,9 @@ from random import randint, shuffle
from math import sqrt from math import sqrt
from os import path from os import path
def read_dice_file(path): def read_dice_file(dice_path: str):
'''Return list of die strings from file ignoring all comments (#)''' '''Return list of die strings from file ignoring all comments (#)'''
with open(path, 'r+', encoding="utf-8") as file: with open(path.abspath(dice_path), 'r+', encoding="utf-8") as file:
return [line.rstrip().split(',') for line in file.readlines() if line[0] != "#"] return [line.rstrip().split(',') for line in file.readlines() if line[0] != "#"]
def roll_die(die: str): def roll_die(die: str):
@@ -17,20 +17,19 @@ def roll_dice(dice: list[str]):
'''Return a random roll for each die''' '''Return a random roll for each die'''
return [ roll_die(die) for die in dice ] return [ roll_die(die) for die in dice ]
def get_random_board(dice_path): def get_random_board(dice: list[str]):
dice_strings = read_dice_file(dice_path) shuffle(dice)
shuffle(dice_strings) rolls = roll_dice(dice)
rolls = roll_dice(dice_strings)
# Format dice rolls for boards file # Format dice rolls for boards file
board_size = int(sqrt(len(rolls))) board_size = int(sqrt(len(rolls)))
board = [] board = []
for i in range(0, len(dice_strings), board_size): for i in range(0, len(dice), board_size):
board.append(rolls[i:i+board_size]) board.append(rolls[i:i+board_size])
return board return board
def get_random_board_csv(dice_path): def get_random_board_csv(dice: list[str]):
board = get_random_board(dice_path) board = get_random_board(dice)
board = [",".join(row) for row in board] board = [",".join(row) for row in board]
return board return board
@@ -39,7 +38,8 @@ if __name__ == '__main__':
print('Usage: python3 board_randomizer.py <dice_file>') print('Usage: python3 board_randomizer.py <dice_file>')
else: else:
try: try:
board = get_random_board_csv(path.abspath(argv[1])) dice = read_dice_file(path.abspath(argv[1]))
board = get_random_board_csv(dice)
for row in board: for row in board:
print(row) print(row)
except Exception as e: except Exception as e:
@@ -1,5 +1,5 @@
# Listed alphabetically # Listed alphabetically
a,a,a,e,e,g a,a,e,e,g,n
a,b,b,j,o,o a,b,b,j,o,o
a,c,h,o,p,s a,c,h,o,p,s
a,f,f,k,p,s a,f,f,k,p,s
1 # Listed alphabetically
2 a,a,a,e,e,g a,a,e,e,g,n
3 a,b,b,j,o,o
4 a,c,h,o,p,s
5 a,f,f,k,p,s
+27 -27
View File
@@ -1,35 +1,35 @@
#!/bin/sh #!/bin/sh
if [ -z $1 ] || [ -z $2 ]; then if [ -z $1 ] || [ -z $2 ]; then
echo "Usage: ./filter_prefix.sh WORDLIST OUT_DIR" echo "Usage: WORDLIST OUT_DIR"
exit 0 exit 0
else else
grep -P "^a" $1 > "$2/words_a.txt" grep -ioP "^a[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_a.txt"
grep -P "^b" $1 > "$2/words_b.txt" grep -ioP "^b[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_b.txt"
grep -P "^c" $1 > "$2/words_c.txt" grep -ioP "^c[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_c.txt"
grep -P "^d" $1 > "$2/words_d.txt" grep -ioP "^d[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_d.txt"
grep -P "^e" $1 > "$2/words_e.txt" grep -ioP "^e[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_e.txt"
grep -P "^f" $1 > "$2/words_f.txt" grep -ioP "^f[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_f.txt"
grep -P "^g" $1 > "$2/words_g.txt" grep -ioP "^g[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_g.txt"
grep -P "^h" $1 > "$2/words_h.txt" grep -ioP "^h[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_h.txt"
grep -P "^i" $1 > "$2/words_i.txt" grep -ioP "^i[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_i.txt"
grep -P "^j" $1 > "$2/words_j.txt" grep -ioP "^j[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_j.txt"
grep -P "^k" $1 > "$2/words_k.txt" grep -ioP "^k[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_k.txt"
grep -P "^l" $1 > "$2/words_l.txt" grep -ioP "^l[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_l.txt"
grep -P "^m" $1 > "$2/words_m.txt" grep -ioP "^m[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_m.txt"
grep -P "^n" $1 > "$2/words_n.txt" grep -ioP "^n[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_n.txt"
grep -P "^o" $1 > "$2/words_o.txt" grep -ioP "^o[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_o.txt"
grep -P "^p" $1 > "$2/words_p.txt" grep -ioP "^p[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_p.txt"
grep -P "^q" $1 > "$2/words_q.txt" grep -ioP "^q[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_q.txt"
grep -P "^r" $1 > "$2/words_r.txt" grep -ioP "^r[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_r.txt"
grep -P "^s" $1 > "$2/words_s.txt" grep -ioP "^s[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_s.txt"
grep -P "^t" $1 > "$2/words_t.txt" grep -ioP "^t[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_t.txt"
grep -P "^u" $1 > "$2/words_u.txt" grep -ioP "^u[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_u.txt"
grep -P "^v" $1 > "$2/words_v.txt" grep -ioP "^v[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_v.txt"
grep -P "^w" $1 > "$2/words_w.txt" grep -ioP "^w[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_w.txt"
grep -P "^x" $1 > "$2/words_x.txt" grep -ioP "^x[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_x.txt"
grep -P "^y" $1 > "$2/words_y.txt" grep -ioP "^y[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_y.txt"
grep -P "^z" $1 > "$2/words_z.txt" grep -ioP "^z[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_z.txt"
touch "$2/words__.txt" touch "$2/words__.txt"
exit 0 exit 0
fi fi