mirror of
https://codeberg.org/cblanken/boggler.git
synced 2026-07-26 03:29:26 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a80111072f | ||
|
|
fa01d442a5 | ||
|
|
733c1474b0 | ||
|
|
54f79c0afe | ||
|
|
9f364ee90e | ||
|
|
e219954ba6 | ||
|
|
f4accfe959 | ||
|
|
bc70b88bf7 | ||
|
|
21aab46b96 | ||
|
|
f18c30cb60 | ||
|
|
da915b723c | ||
|
|
d5a102713d |
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "boggler"
|
name = "boggler"
|
||||||
version = "1.0.2"
|
version = "2.0.1"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
|
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
'''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(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(floor(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,9 +38,10 @@ 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]))
|
||||||
for row in board:
|
board = get_random_board_csv(dice)
|
||||||
print(row)
|
for r in range(0, int(floor(sqrt(len(dice))))):
|
||||||
|
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
|
||||||
@@ -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
|
||||||
|
@@ -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,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"
|
rg "(^a[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_a.txt"
|
||||||
grep -P "^b" $1 > "$2/words_b.txt"
|
rg "(^b[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_b.txt"
|
||||||
grep -P "^c" $1 > "$2/words_c.txt"
|
rg "(^c[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_c.txt"
|
||||||
grep -P "^d" $1 > "$2/words_d.txt"
|
rg "(^d[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_d.txt"
|
||||||
grep -P "^e" $1 > "$2/words_e.txt"
|
rg "(^e[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_e.txt"
|
||||||
grep -P "^f" $1 > "$2/words_f.txt"
|
rg "(^f[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_f.txt"
|
||||||
grep -P "^g" $1 > "$2/words_g.txt"
|
rg "(^g[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_g.txt"
|
||||||
grep -P "^h" $1 > "$2/words_h.txt"
|
rg "(^h[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_h.txt"
|
||||||
grep -P "^i" $1 > "$2/words_i.txt"
|
rg "(^i[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_i.txt"
|
||||||
grep -P "^j" $1 > "$2/words_j.txt"
|
rg "(^j[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_j.txt"
|
||||||
grep -P "^k" $1 > "$2/words_k.txt"
|
rg "(^k[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_k.txt"
|
||||||
grep -P "^l" $1 > "$2/words_l.txt"
|
rg "(^l[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_l.txt"
|
||||||
grep -P "^m" $1 > "$2/words_m.txt"
|
rg "(^m[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_m.txt"
|
||||||
grep -P "^n" $1 > "$2/words_n.txt"
|
rg "(^n[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_n.txt"
|
||||||
grep -P "^o" $1 > "$2/words_o.txt"
|
rg "(^o[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_o.txt"
|
||||||
grep -P "^p" $1 > "$2/words_p.txt"
|
rg "(^p[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_p.txt"
|
||||||
grep -P "^q" $1 > "$2/words_q.txt"
|
rg "(^q[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_q.txt"
|
||||||
grep -P "^r" $1 > "$2/words_r.txt"
|
rg "(^r[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_r.txt"
|
||||||
grep -P "^s" $1 > "$2/words_s.txt"
|
rg "(^s[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_s.txt"
|
||||||
grep -P "^t" $1 > "$2/words_t.txt"
|
rg "(^t[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_t.txt"
|
||||||
grep -P "^u" $1 > "$2/words_u.txt"
|
rg "(^u[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_u.txt"
|
||||||
grep -P "^v" $1 > "$2/words_v.txt"
|
rg "(^v[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_v.txt"
|
||||||
grep -P "^w" $1 > "$2/words_w.txt"
|
rg "(^w[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_w.txt"
|
||||||
grep -P "^x" $1 > "$2/words_x.txt"
|
rg "(^x[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_x.txt"
|
||||||
grep -P "^y" $1 > "$2/words_y.txt"
|
rg "(^y[a-z]+).*$" -or '$1' $1 | sort | uniq > "$2/words_y.txt"
|
||||||
grep -P "^z" $1 > "$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