-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsquaredle
executable file
·87 lines (62 loc) · 2.29 KB
/
squaredle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""Solve Squaredle puzzles, main entry point.
Solve a Squaredle puzzle and output solution to terminal or via
a GUI. Examples:
./squaredle # solve today's puzzle on terminal
./squaredle --gui # also display a gui
./squaredle ABCDEFGHI # solve a 3x3 grid "ABC", "DEF", "GHI"
./squaredle --help # program options
(c) Robert Rainthorpe 2023
"""
import importlib
import platform
from pysquaredle.console import console
from pysquaredle.helpers import parse_args, puzzle_letters, shuffle
from pysquaredle.puzzle import Puzzle
from pysquaredle.results import output_formatted_results
from pysquaredle.solver import Solver
ARM = "aarch64"
NO_ARM_QT_EXCEPTION = "GUI not supported on ARM processor"
def main() -> int:
"""Main entry point for pysquaredle. Solves or sets Squaredle-type puzzles.
If the --gui flag is set, the GUI is launched.
"""
args = parse_args()
letters = puzzle_letters(args)
if args.random:
letters = shuffle(letters)
puzzle = Puzzle(letters)
if args.slow_mode:
def report(word: str, chain: list[int], hit_count: int) -> None:
console.print(f"Checking {word} at {chain}. Hits: {hit_count}")
solver = Solver(puzzle, args.file, report)
else:
solver = Solver(puzzle, args.file)
if args.debug:
console.print(puzzle.list_neighbours)
if args.gui:
if platform.processor() != ARM:
# dynamic load if we're not on ARM
module = importlib.import_module("pysquaredle.ui.application")
app_class = module.Application
app = app_class(
puzzle, solver, alpha_sort=args.sort, multiple=args.multiple
)
app.exec()
return 0
raise NotImplementedError(NO_ARM_QT_EXCEPTION)
if args.grid or args.random or args.square or args.auto_extend:
console.print(puzzle.grid)
ordered_solutions = solver.raw_solution_words(sort=args.sort, length=args.length)
if solver.has_unacceptable_words():
console.print("BAD WORDS!")
output_formatted_results(
ordered_solutions,
length_group=args.length,
headers=args.headers,
single_column=args.single_column,
)
# be nice to pipelines
return 0
if __name__ == "__main__":
main()