12 Commits
Author SHA1 Message Date
cblanken a80111072f Bump release version 2022-12-30 20:55:44 -05:00
cblanken fa01d442a5 Fix bug in board randomizer
- The board randomizer did not account for dice files that don't contain an exact integer squared number of dice. For example the 5x5 dice file contains 26 possible dice since 1 extra die is provided.
- The fix takes the square root of the number of dice and takes the floor of that number as the total number of dice to choose.
2022-12-30 19:54:00 -05:00
cblanken 733c1474b0 Add 5x5 dice file 2022-12-30 19:51:41 -05:00
cblanken 54f79c0afe Remove dead code from boggler.py 2022-11-16 20:37:30 -05:00
cblanken 9f364ee90e Remove old dictionary word prefix lists 2022-11-16 20:36:55 -05:00
cblanken e219954ba6 Add function to flatten boggle board results into 1D list 2022-10-10 12:00:42 -04:00
cblanken f4accfe959 Update wordlist splitting script
- use ripgrep to exclude proper nouns (with capitals) output only the
  capture group
2022-09-28 13:01:39 -04:00
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
11 changed files with 79 additions and 58787 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "boggler"
version = "1.0.2"
version = "2.0.1"
authors = [
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
]
+14 -14
View File
@@ -1,12 +1,12 @@
'''Module to generate random Boggle boards for testing'''
from sys import argv, stderr
from random import randint, shuffle
from math import sqrt
from math import sqrt, floor
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 (#)'''
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] != "#"]
def roll_die(die: str):
@@ -17,20 +17,19 @@ def roll_dice(dice: list[str]):
'''Return a random roll for each die'''
return [ roll_die(die) for die in dice ]
def get_random_board(dice_path):
dice_strings = read_dice_file(dice_path)
shuffle(dice_strings)
rolls = roll_dice(dice_strings)
def get_random_board(dice: list[str]):
shuffle(dice)
rolls = roll_dice(dice)
# Format dice rolls for boards file
board_size = int(sqrt(len(rolls)))
board_size = int(floor(sqrt(len(rolls))))
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])
return board
def get_random_board_csv(dice_path):
board = get_random_board(dice_path)
def get_random_board_csv(dice: list[str]):
board = get_random_board(dice)
board = [",".join(row) for row in board]
return board
@@ -39,9 +38,10 @@ if __name__ == '__main__':
print('Usage: python3 board_randomizer.py <dice_file>')
else:
try:
board = get_random_board_csv(path.abspath(argv[1]))
for row in board:
print(row)
dice = read_dice_file(path.abspath(argv[1]))
board = get_random_board_csv(dice)
for r in range(0, int(floor(sqrt(len(dice))))):
print(board[r])
except Exception as e:
print("Argument must be a valid file path!", file=stderr)
+9
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
from os import path
from multiprocessing import Pool
import functools
import operator
class BoardCell:
'''Boggle Board cell'''
@@ -418,3 +420,10 @@ def read_boggle_file(file):
'''Return list of rows from Boggle board csv file'''
with open(file, 'r', encoding='utf-8') as file:
return [x.rstrip().split(',') for x in file.readlines()]
def find_paths_by_word(board_letters, dictionary_path, max_len):
'''Return list of paths by word'''
boggle_board = BoggleBoard(board_letters, max_len)
boggle_tree = build_full_boggle_tree(boggle_board, dictionary_path)
paths_by_word = functools.reduce(operator.iconcat, [x.word_paths for x in boggle_tree.values()], [])
return paths_by_word
@@ -1,5 +1,5 @@
# Listed alphabetically
a,a,a,e,e,g
a,a,e,e,g,n
a,b,b,j,o,o
a,c,h,o,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
View File
@@ -0,0 +1,27 @@
# Listed alphabetically
a,a,a,f,r,s
a,a,e,e,e,e
a,a,f,i,r,s
a,d,e,n,n,n
a,e,e,e,e,m
a,e,e,g,m,u
a,e,g,m,n,n
a,f,i,r,s,y
an,er,he,in,qu,th
b,j,k,qu,x,z
c,c,e,n,s,t
c,e,i,i,l,t
c,e,i,l,p,t
c,e,i,p,s,t
d,d,h,n,o,t
d,h,h,l,n,o
d,h,l,n,o,r
d,l,o,h,h,r
e,i,i,i,t,t
e,m,o,t,t,t
e,n,s,s,s,u
f,i,p,r,s,y
g,o,r,r,v,w
i,k,l,qu,u,w
n,o,o,t,u,w
o,o,o,t,t,u
1 # Listed alphabetically
2 a,a,a,f,r,s
3 a,a,e,e,e,e
4 a,a,f,i,r,s
5 a,d,e,n,n,n
6 a,e,e,e,e,m
7 a,e,e,g,m,u
8 a,e,g,m,n,n
9 a,f,i,r,s,y
10 an,er,he,in,qu,th
11 b,j,k,qu,x,z
12 c,c,e,n,s,t
13 c,e,i,i,l,t
14 c,e,i,l,p,t
15 c,e,i,p,s,t
16 d,d,h,n,o,t
17 d,h,h,l,n,o
18 d,h,l,n,o,r
19 d,l,o,h,h,r
20 e,i,i,i,t,t
21 e,m,o,t,t,t
22 e,n,s,s,s,u
23 f,i,p,r,s,y
24 g,o,r,r,v,w
25 i,k,l,qu,u,w
26 n,o,o,t,u,w
27 o,o,o,t,t,u
+27 -27
View File
@@ -1,35 +1,35 @@
#!/bin/sh
if [ -z $1 ] || [ -z $2 ]; then
echo "Usage: ./filter_prefix.sh WORDLIST OUT_DIR"
echo "Usage: WORDLIST OUT_DIR"
exit 0
else
grep -P "^a" $1 > "$2/words_a.txt"
grep -P "^b" $1 > "$2/words_b.txt"
grep -P "^c" $1 > "$2/words_c.txt"
grep -P "^d" $1 > "$2/words_d.txt"
grep -P "^e" $1 > "$2/words_e.txt"
grep -P "^f" $1 > "$2/words_f.txt"
grep -P "^g" $1 > "$2/words_g.txt"
grep -P "^h" $1 > "$2/words_h.txt"
grep -P "^i" $1 > "$2/words_i.txt"
grep -P "^j" $1 > "$2/words_j.txt"
grep -P "^k" $1 > "$2/words_k.txt"
grep -P "^l" $1 > "$2/words_l.txt"
grep -P "^m" $1 > "$2/words_m.txt"
grep -P "^n" $1 > "$2/words_n.txt"
grep -P "^o" $1 > "$2/words_o.txt"
grep -P "^p" $1 > "$2/words_p.txt"
grep -P "^q" $1 > "$2/words_q.txt"
grep -P "^r" $1 > "$2/words_r.txt"
grep -P "^s" $1 > "$2/words_s.txt"
grep -P "^t" $1 > "$2/words_t.txt"
grep -P "^u" $1 > "$2/words_u.txt"
grep -P "^v" $1 > "$2/words_v.txt"
grep -P "^w" $1 > "$2/words_w.txt"
grep -P "^x" $1 > "$2/words_x.txt"
grep -P "^y" $1 > "$2/words_y.txt"
grep -P "^z" $1 > "$2/words_z.txt"
rg "(^a[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_a.txt"
rg "(^b[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_b.txt"
rg "(^c[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_c.txt"
rg "(^d[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_d.txt"
rg "(^e[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_e.txt"
rg "(^f[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_f.txt"
rg "(^g[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_g.txt"
rg "(^h[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_h.txt"
rg "(^i[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_i.txt"
rg "(^j[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_j.txt"
rg "(^k[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_k.txt"
rg "(^l[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_l.txt"
rg "(^m[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_m.txt"
rg "(^n[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_n.txt"
rg "(^o[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_o.txt"
rg "(^p[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_p.txt"
rg "(^q[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_q.txt"
rg "(^r[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_r.txt"
rg "(^s[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_s.txt"
rg "(^t[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_t.txt"
rg "(^u[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_u.txt"
rg "(^v[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_v.txt"
rg "(^w[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_w.txt"
rg "(^x[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_x.txt"
rg "(^y[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_y.txt"
rg "(^z[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_z.txt"
touch "$2/words__.txt"
exit 0
fi
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff