mirror of
https://codeberg.org/cblanken/boggler.git
synced 2026-07-26 11:35:10 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a80111072f | ||
|
|
fa01d442a5 | ||
|
|
733c1474b0 | ||
|
|
54f79c0afe | ||
|
|
9f364ee90e | ||
|
|
e219954ba6 | ||
|
|
f4accfe959 |
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "boggler"
|
name = "boggler"
|
||||||
version = "2.0.0"
|
version = "2.0.1"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
|
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'''Module to generate random Boggle boards for testing'''
|
'''Module to generate random Boggle boards for testing'''
|
||||||
from sys import argv, stderr
|
from sys import argv, stderr
|
||||||
from random import randint, shuffle
|
from random import randint, shuffle
|
||||||
from math import sqrt
|
from math import sqrt, floor
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
def read_dice_file(dice_path: str):
|
def read_dice_file(dice_path: str):
|
||||||
@@ -22,7 +22,7 @@ def get_random_board(dice: list[str]):
|
|||||||
rolls = roll_dice(dice)
|
rolls = roll_dice(dice)
|
||||||
|
|
||||||
# Format dice rolls for boards file
|
# Format dice rolls for boards file
|
||||||
board_size = int(sqrt(len(rolls)))
|
board_size = int(floor(sqrt(len(rolls))))
|
||||||
board = []
|
board = []
|
||||||
for i in range(0, len(dice), 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])
|
||||||
@@ -40,8 +40,8 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
dice = read_dice_file(path.abspath(argv[1]))
|
dice = read_dice_file(path.abspath(argv[1]))
|
||||||
board = get_random_board_csv(dice)
|
board = get_random_board_csv(dice)
|
||||||
for row in board:
|
for r in range(0, int(floor(sqrt(len(dice))))):
|
||||||
print(row)
|
print(board[r])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Argument must be a valid file path!", file=stderr)
|
print("Argument must be a valid file path!", file=stderr)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from os import path
|
from os import path
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
|
import functools
|
||||||
|
import operator
|
||||||
|
|
||||||
class BoardCell:
|
class BoardCell:
|
||||||
'''Boggle Board cell'''
|
'''Boggle Board cell'''
|
||||||
@@ -418,3 +420,10 @@ def read_boggle_file(file):
|
|||||||
'''Return list of rows from Boggle board csv file'''
|
'''Return list of rows from Boggle board csv file'''
|
||||||
with open(file, 'r', encoding='utf-8') as file:
|
with open(file, 'r', encoding='utf-8') as file:
|
||||||
return [x.rstrip().split(',') for x in file.readlines()]
|
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
|
||||||
@@ -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
|
||||||
|
@@ -4,32 +4,32 @@ if [ -z $1 ] || [ -z $2 ]; then
|
|||||||
echo "Usage: WORDLIST OUT_DIR"
|
echo "Usage: WORDLIST OUT_DIR"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
grep -ioP "^a[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_a.txt"
|
rg "(^a[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_a.txt"
|
||||||
grep -ioP "^b[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_b.txt"
|
rg "(^b[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_b.txt"
|
||||||
grep -ioP "^c[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_c.txt"
|
rg "(^c[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_c.txt"
|
||||||
grep -ioP "^d[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_d.txt"
|
rg "(^d[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_d.txt"
|
||||||
grep -ioP "^e[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_e.txt"
|
rg "(^e[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_e.txt"
|
||||||
grep -ioP "^f[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_f.txt"
|
rg "(^f[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_f.txt"
|
||||||
grep -ioP "^g[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_g.txt"
|
rg "(^g[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_g.txt"
|
||||||
grep -ioP "^h[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_h.txt"
|
rg "(^h[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_h.txt"
|
||||||
grep -ioP "^i[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_i.txt"
|
rg "(^i[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_i.txt"
|
||||||
grep -ioP "^j[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_j.txt"
|
rg "(^j[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_j.txt"
|
||||||
grep -ioP "^k[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_k.txt"
|
rg "(^k[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_k.txt"
|
||||||
grep -ioP "^l[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_l.txt"
|
rg "(^l[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_l.txt"
|
||||||
grep -ioP "^m[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_m.txt"
|
rg "(^m[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_m.txt"
|
||||||
grep -ioP "^n[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_n.txt"
|
rg "(^n[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_n.txt"
|
||||||
grep -ioP "^o[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_o.txt"
|
rg "(^o[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_o.txt"
|
||||||
grep -ioP "^p[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_p.txt"
|
rg "(^p[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_p.txt"
|
||||||
grep -ioP "^q[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_q.txt"
|
rg "(^q[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_q.txt"
|
||||||
grep -ioP "^r[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_r.txt"
|
rg "(^r[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_r.txt"
|
||||||
grep -ioP "^s[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_s.txt"
|
rg "(^s[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_s.txt"
|
||||||
grep -ioP "^t[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_t.txt"
|
rg "(^t[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_t.txt"
|
||||||
grep -ioP "^u[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_u.txt"
|
rg "(^u[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_u.txt"
|
||||||
grep -ioP "^v[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_v.txt"
|
rg "(^v[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_v.txt"
|
||||||
grep -ioP "^w[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_w.txt"
|
rg "(^w[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_w.txt"
|
||||||
grep -ioP "^x[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_x.txt"
|
rg "(^x[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_x.txt"
|
||||||
grep -ioP "^y[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_y.txt"
|
rg "(^y[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_y.txt"
|
||||||
grep -ioP "^z[a-z]+" $1 | tr [A-Z] [a-z] | sort | uniq > "$2/words_z.txt"
|
rg "(^z[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_z.txt"
|
||||||
touch "$2/words__.txt"
|
touch "$2/words__.txt"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
Reference in New Issue
Block a user