mirror of
https://codeberg.org/cblanken/boggler.git
synced 2026-07-26 11:35:10 -04:00
Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6e14ac5d6 | ||
|
|
ac97a0795e | ||
|
|
0dddcc6da8 | ||
|
|
806f35dfef | ||
|
|
6e52619a28 | ||
|
|
3653d784a3 | ||
|
|
21a63f432a | ||
|
|
f00baa5ac2 | ||
|
|
5da33cf02c | ||
|
|
600efc19c2 | ||
|
|
cdb1542184 | ||
|
|
795f1540b4 | ||
|
|
91390ea425 | ||
|
|
2a6a27b0b8 | ||
|
|
b445071ccc | ||
|
|
9c8e94964c | ||
|
|
2fd5b05717 | ||
|
|
0cdd3895ee | ||
|
|
50d4625b84 | ||
|
|
c88f657113 | ||
|
|
14a813ed74 | ||
|
|
46dd069cfd | ||
|
|
31a307e83d | ||
|
|
bc4922dc55 | ||
|
|
5f9a0d1990 | ||
|
|
dc532c1fdd | ||
|
|
0f5e5af5ae | ||
|
|
28b3d56880 | ||
|
|
79486d4217 | ||
|
|
6d6d56d1cb | ||
|
|
88b43d0679 |
@@ -1 +1,9 @@
|
|||||||
|
# Byte-compiled / optimized
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Env
|
||||||
.vscode
|
.vscode
|
||||||
|
|||||||
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
# Boggler
|
||||||
|
A solver for the popular word game Boggle.
|
||||||
|
|
||||||
|
# Install
|
||||||
|
```console
|
||||||
|
pip install boggler
|
||||||
|
```
|
||||||
|
OR
|
||||||
|
```console
|
||||||
|
git clone https://github.com/cblanken/boggler.git
|
||||||
|
```
|
||||||
|
|
||||||
|
To use the script to solve a particular Boggle board configuration, you'll need to do a few things
|
||||||
|
1. Create `.csv` of the board state like so:
|
||||||
|
|
||||||
|
Here is an example `board.csv`. Note the orientation of the board does not matter.
|
||||||
|
```console
|
||||||
|
$ cat board.csv
|
||||||
|
y,e,o,s
|
||||||
|
r,e,o,v
|
||||||
|
d,f,e,y
|
||||||
|
n,m,e,qu
|
||||||
|
```
|
||||||
|
2. Find a dictionary wordlist file or create your own
|
||||||
|
|
||||||
|
The dictionary wordlist should have each word on a single line like so
|
||||||
|
```console
|
||||||
|
$ cat wordlists/wordlist.txt
|
||||||
|
a
|
||||||
|
aa
|
||||||
|
aaa
|
||||||
|
aah
|
||||||
|
aahed
|
||||||
|
aahing
|
||||||
|
aahs
|
||||||
|
aal
|
||||||
|
...
|
||||||
|
zwiebacks
|
||||||
|
zwieselite
|
||||||
|
zwinglian
|
||||||
|
zwinglianism
|
||||||
|
zwinglianist
|
||||||
|
zwitter
|
||||||
|
zwitterion
|
||||||
|
zwitterionic
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Split the dictionary wordlist into separate files based on the first letter of each word.
|
||||||
|
|
||||||
|
To split an English wordlist the `split_wordlist_alpha.sh` script can be used like so:
|
||||||
|
```console
|
||||||
|
$ split_wordlist_alpha.sh my_wordlist.txt .
|
||||||
|
```
|
||||||
|
This will generate a series of sub-dictionaries for each letter in the alphabet in the current directory.
|
||||||
|
```console
|
||||||
|
$ ls
|
||||||
|
my_wordlist.txt words_d.txt words_h.txt words_l.txt words_p.txt words_t.txt words_x.txt
|
||||||
|
words_a.txt words_e.txt words_i.txt words_m.txt words_q.txt words_u.txt words_y.txt
|
||||||
|
words_b.txt words_f.txt words_j.txt words_n.txt words_r.txt words_v.txt words_z.txt
|
||||||
|
words_c.txt words_g.txt words_k.txt words_o.txt words_s.txt words_w.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
```console
|
||||||
|
$ python boggler.py
|
||||||
|
Usage: python3 boggler.py <BOARD_FILE> <WORDLISTS_DIR> [MAX_WORD_LENGTH]
|
||||||
|
$ python boggler.py board.csv wordlists/ 15
|
||||||
|
Reading in wordlists...
|
||||||
|
>> d: words_d.txt
|
||||||
|
>> e: words_e.txt
|
||||||
|
>> f: words_f.txt
|
||||||
|
>> m: words_m.txt
|
||||||
|
>> n: words_n.txt
|
||||||
|
>> o: words_o.txt
|
||||||
|
>> qu: words_q.txt
|
||||||
|
>> r: words_r.txt
|
||||||
|
>> s: words_s.txt
|
||||||
|
>> v: words_v.txt
|
||||||
|
>> y: words_y.txt
|
||||||
|
Generating WordTrees...
|
||||||
|
>> (0, 0): y
|
||||||
|
>> (0, 1): e
|
||||||
|
>> (0, 2): o
|
||||||
|
>> (0, 3): s
|
||||||
|
>> (1, 0): r
|
||||||
|
>> (1, 1): e
|
||||||
|
>> (1, 2): o
|
||||||
|
>> (1, 3): v
|
||||||
|
>> (2, 0): d
|
||||||
|
>> (2, 1): f
|
||||||
|
>> (2, 2): e
|
||||||
|
>> (2, 3): y
|
||||||
|
>> (3, 0): n
|
||||||
|
>> (3, 1): m
|
||||||
|
>> (3, 2): e
|
||||||
|
>> (3, 3): qu
|
||||||
|
|
||||||
|
BOARD
|
||||||
|
+---------------+
|
||||||
|
| Y | E | O | S |
|
||||||
|
+---------------+
|
||||||
|
| R | E | O | V |
|
||||||
|
+---------------+
|
||||||
|
| D | F | E | Y |
|
||||||
|
+---------------+
|
||||||
|
| N | M | E |QU |
|
||||||
|
+---------------+
|
||||||
|
|
||||||
|
|
||||||
|
Starting @ (0, 0)...
|
||||||
|
y : [(0, 0)]
|
||||||
|
yr : [(0, 0), (1, 0)]
|
||||||
|
ye : [(0, 0), (1, 1)]
|
||||||
|
yee : [(0, 0), (1, 1), (0, 1)]
|
||||||
|
yeo : [(0, 0), (1, 1), (0, 2)]
|
||||||
|
yed : [(0, 0), (1, 1), (2, 0)]
|
||||||
|
yee : [(0, 0), (1, 1), (2, 2)]
|
||||||
|
yer : [(0, 0), (1, 1), (1, 0)]
|
||||||
|
yere : [(0, 0), (1, 1), (1, 0), (0, 1)]
|
||||||
|
yerd : [(0, 0), (1, 1), (1, 0), (2, 0)]
|
||||||
|
yeo : [(0, 0), (1, 1), (1, 2)]
|
||||||
|
ye : [(0, 0), (0, 1)]
|
||||||
|
yee : [(0, 0), (0, 1), (1, 1)]
|
||||||
|
yer : [(0, 0), (0, 1), (1, 0)]
|
||||||
|
yerd : [(0, 0), (0, 1), (1, 0), (2, 0)]
|
||||||
|
yere : [(0, 0), (0, 1), (1, 0), (1, 1)]
|
||||||
|
yeo : [(0, 0), (0, 1), (1, 2)]
|
||||||
|
yeo : [(0, 0), (0, 1), (0, 2)]
|
||||||
|
|
||||||
|
Starting @ (0, 1)...
|
||||||
|
e : [(0, 1)]
|
||||||
|
ee : [(0, 1), (1, 1)]
|
||||||
|
eer : [(0, 1), (1, 1), (1, 0)]
|
||||||
|
eery : [(0, 1), (1, 1), (1, 0), (0, 0)]
|
||||||
|
er : [(0, 1), (1, 0)]
|
||||||
|
erd : [(0, 1), (1, 0), (2, 0)]
|
||||||
|
erf : [(0, 1), (1, 0), (2, 1)]
|
||||||
|
ere : [(0, 1), (1, 0), (1, 1)]
|
||||||
|
eo : [(0, 1), (1, 2)]
|
||||||
|
eos : [(0, 1), (1, 2), (0, 3)]
|
||||||
|
eof : [(0, 1), (1, 2), (2, 1)]
|
||||||
|
ey : [(0, 1), (0, 0)]
|
||||||
|
eyr : [(0, 1), (0, 0), (1, 0)]
|
||||||
|
eyre : [(0, 1), (0, 0), (1, 0), (1, 1)]
|
||||||
|
eye : [(0, 1), (0, 0), (1, 1)]
|
||||||
|
eyed : [(0, 1), (0, 0), (1, 1), (2, 0)]
|
||||||
|
eyer : [(0, 1), (0, 0), (1, 1), (1, 0)]
|
||||||
|
eo : [(0, 1), (0, 2)]
|
||||||
|
eos : [(0, 1), (0, 2), (0, 3)]
|
||||||
|
|
||||||
|
Starting @ (0, 2)...
|
||||||
|
o : [(0, 2)]
|
||||||
|
oos : [(0, 2), (1, 2), (0, 3)]
|
||||||
|
oof : [(0, 2), (1, 2), (2, 1)]
|
||||||
|
oe : [(0, 2), (1, 1)]
|
||||||
|
oer : [(0, 2), (1, 1), (1, 0)]
|
||||||
|
ovey : [(0, 2), (1, 3), (2, 2), (2, 3)]
|
||||||
|
oe : [(0, 2), (0, 1)]
|
||||||
|
oer : [(0, 2), (0, 1), (1, 0)]
|
||||||
|
os : [(0, 2), (0, 3)]
|
||||||
|
|
||||||
|
Starting @ (0, 3)...
|
||||||
|
s : [(0, 3)]
|
||||||
|
sv : [(0, 3), (1, 3)]
|
||||||
|
so : [(0, 3), (1, 2)]
|
||||||
|
sooey : [(0, 3), (1, 2), (0, 2), (1, 1), (0, 0)]
|
||||||
|
sooey : [(0, 3), (1, 2), (0, 2), (0, 1), (0, 0)]
|
||||||
|
soe : [(0, 3), (1, 2), (0, 1)]
|
||||||
|
soe : [(0, 3), (1, 2), (2, 2)]
|
||||||
|
sofer : [(0, 3), (1, 2), (2, 1), (1, 1), (1, 0)]
|
||||||
|
soy : [(0, 3), (1, 2), (2, 3)]
|
||||||
|
soe : [(0, 3), (1, 2), (1, 1)]
|
||||||
|
sov : [(0, 3), (1, 2), (1, 3)]
|
||||||
|
so : [(0, 3), (0, 2)]
|
||||||
|
sooey : [(0, 3), (0, 2), (1, 2), (0, 1), (0, 0)]
|
||||||
|
sooey : [(0, 3), (0, 2), (1, 2), (2, 2), (2, 3)]
|
||||||
|
sooey : [(0, 3), (0, 2), (1, 2), (1, 1), (0, 0)]
|
||||||
|
soe : [(0, 3), (0, 2), (1, 1)]
|
||||||
|
sov : [(0, 3), (0, 2), (1, 3)]
|
||||||
|
soe : [(0, 3), (0, 2), (0, 1)]
|
||||||
|
|
||||||
|
Starting @ (1, 0)...
|
||||||
|
r : [(1, 0)]
|
||||||
|
rye : [(1, 0), (0, 0), (1, 1)]
|
||||||
|
rye : [(1, 0), (0, 0), (0, 1)]
|
||||||
|
re : [(1, 0), (0, 1)]
|
||||||
|
ree : [(1, 0), (0, 1), (1, 1)]
|
||||||
|
reef : [(1, 0), (0, 1), (1, 1), (2, 1)]
|
||||||
|
reed : [(1, 0), (0, 1), (1, 1), (2, 0)]
|
||||||
|
rd : [(1, 0), (2, 0)]
|
||||||
|
rf : [(1, 0), (2, 1)]
|
||||||
|
re : [(1, 0), (1, 1)]
|
||||||
|
ree : [(1, 0), (1, 1), (0, 1)]
|
||||||
|
ref : [(1, 0), (1, 1), (2, 1)]
|
||||||
|
red : [(1, 0), (1, 1), (2, 0)]
|
||||||
|
ree : [(1, 0), (1, 1), (2, 2)]
|
||||||
|
reem : [(1, 0), (1, 1), (2, 2), (3, 1)]
|
||||||
|
reef : [(1, 0), (1, 1), (2, 2), (2, 1)]
|
||||||
|
|
||||||
|
Starting @ (1, 1)...
|
||||||
|
e : [(1, 1)]
|
||||||
|
ee : [(1, 1), (0, 1)]
|
||||||
|
eer : [(1, 1), (0, 1), (1, 0)]
|
||||||
|
eery : [(1, 1), (0, 1), (1, 0), (0, 0)]
|
||||||
|
ey : [(1, 1), (0, 0)]
|
||||||
|
eyr : [(1, 1), (0, 0), (1, 0)]
|
||||||
|
eyre : [(1, 1), (0, 0), (1, 0), (0, 1)]
|
||||||
|
eye : [(1, 1), (0, 0), (0, 1)]
|
||||||
|
eyer : [(1, 1), (0, 0), (0, 1), (1, 0)]
|
||||||
|
eo : [(1, 1), (0, 2)]
|
||||||
|
eos : [(1, 1), (0, 2), (0, 3)]
|
||||||
|
ef : [(1, 1), (2, 1)]
|
||||||
|
ed : [(1, 1), (2, 0)]
|
||||||
|
ee : [(1, 1), (2, 2)]
|
||||||
|
er : [(1, 1), (1, 0)]
|
||||||
|
ere : [(1, 1), (1, 0), (0, 1)]
|
||||||
|
erd : [(1, 1), (1, 0), (2, 0)]
|
||||||
|
erf : [(1, 1), (1, 0), (2, 1)]
|
||||||
|
eo : [(1, 1), (1, 2)]
|
||||||
|
eos : [(1, 1), (1, 2), (0, 3)]
|
||||||
|
eof : [(1, 1), (1, 2), (2, 1)]
|
||||||
|
|
||||||
|
Starting @ (1, 2)...
|
||||||
|
o : [(1, 2)]
|
||||||
|
oos : [(1, 2), (0, 2), (0, 3)]
|
||||||
|
oe : [(1, 2), (0, 1)]
|
||||||
|
oer : [(1, 2), (0, 1), (1, 0)]
|
||||||
|
os : [(1, 2), (0, 3)]
|
||||||
|
oe : [(1, 2), (2, 2)]
|
||||||
|
of : [(1, 2), (2, 1)]
|
||||||
|
ofer : [(1, 2), (2, 1), (1, 1), (1, 0)]
|
||||||
|
oy : [(1, 2), (2, 3)]
|
||||||
|
oe : [(1, 2), (1, 1)]
|
||||||
|
oer : [(1, 2), (1, 1), (1, 0)]
|
||||||
|
ovey : [(1, 2), (1, 3), (2, 2), (2, 3)]
|
||||||
|
|
||||||
|
Starting @ (1, 3)...
|
||||||
|
v : [(1, 3)]
|
||||||
|
vs : [(1, 3), (0, 3)]
|
||||||
|
vo : [(1, 3), (0, 2)]
|
||||||
|
voe : [(1, 3), (0, 2), (1, 1)]
|
||||||
|
voe : [(1, 3), (0, 2), (0, 1)]
|
||||||
|
vee : [(1, 3), (2, 2), (1, 1)]
|
||||||
|
veer : [(1, 3), (2, 2), (1, 1), (1, 0)]
|
||||||
|
veery : [(1, 3), (2, 2), (1, 1), (1, 0), (0, 0)]
|
||||||
|
vee : [(1, 3), (2, 2), (3, 2)]
|
||||||
|
vefry : [(1, 3), (2, 2), (2, 1), (1, 0), (0, 0)]
|
||||||
|
vo : [(1, 3), (1, 2)]
|
||||||
|
voe : [(1, 3), (1, 2), (0, 1)]
|
||||||
|
voe : [(1, 3), (1, 2), (2, 2)]
|
||||||
|
voe : [(1, 3), (1, 2), (1, 1)]
|
||||||
|
|
||||||
|
Starting @ (2, 0)...
|
||||||
|
d : [(2, 0)]
|
||||||
|
dr : [(2, 0), (1, 0)]
|
||||||
|
dry : [(2, 0), (1, 0), (0, 0)]
|
||||||
|
dree : [(2, 0), (1, 0), (0, 1), (1, 1)]
|
||||||
|
drey : [(2, 0), (1, 0), (0, 1), (0, 0)]
|
||||||
|
dree : [(2, 0), (1, 0), (1, 1), (0, 1)]
|
||||||
|
drey : [(2, 0), (1, 0), (1, 1), (0, 0)]
|
||||||
|
dree : [(2, 0), (1, 0), (1, 1), (2, 2)]
|
||||||
|
de : [(2, 0), (1, 1)]
|
||||||
|
dee : [(2, 0), (1, 1), (0, 1)]
|
||||||
|
deer : [(2, 0), (1, 1), (0, 1), (1, 0)]
|
||||||
|
dey : [(2, 0), (1, 1), (0, 0)]
|
||||||
|
def : [(2, 0), (1, 1), (2, 1)]
|
||||||
|
dee : [(2, 0), (1, 1), (2, 2)]
|
||||||
|
deem : [(2, 0), (1, 1), (2, 2), (3, 1)]
|
||||||
|
der : [(2, 0), (1, 1), (1, 0)]
|
||||||
|
dere : [(2, 0), (1, 1), (1, 0), (0, 1)]
|
||||||
|
derf : [(2, 0), (1, 1), (1, 0), (2, 1)]
|
||||||
|
dn : [(2, 0), (3, 0)]
|
||||||
|
dm : [(2, 0), (3, 1)]
|
||||||
|
|
||||||
|
Starting @ (2, 1)...
|
||||||
|
f : [(2, 1)]
|
||||||
|
fe : [(2, 1), (1, 1)]
|
||||||
|
fee : [(2, 1), (1, 1), (0, 1)]
|
||||||
|
feer : [(2, 1), (1, 1), (0, 1), (1, 0)]
|
||||||
|
fey : [(2, 1), (1, 1), (0, 0)]
|
||||||
|
feyer : [(2, 1), (1, 1), (0, 0), (0, 1), (1, 0)]
|
||||||
|
fed : [(2, 1), (1, 1), (2, 0)]
|
||||||
|
fedn : [(2, 1), (1, 1), (2, 0), (3, 0)]
|
||||||
|
fee : [(2, 1), (1, 1), (2, 2)]
|
||||||
|
fer : [(2, 1), (1, 1), (1, 0)]
|
||||||
|
fere : [(2, 1), (1, 1), (1, 0), (0, 1)]
|
||||||
|
ferd : [(2, 1), (1, 1), (1, 0), (2, 0)]
|
||||||
|
fr : [(2, 1), (1, 0)]
|
||||||
|
fry : [(2, 1), (1, 0), (0, 0)]
|
||||||
|
free : [(2, 1), (1, 0), (0, 1), (1, 1)]
|
||||||
|
freed : [(2, 1), (1, 0), (0, 1), (1, 1), (2, 0)]
|
||||||
|
frey : [(2, 1), (1, 0), (0, 1), (0, 0)]
|
||||||
|
free : [(2, 1), (1, 0), (1, 1), (0, 1)]
|
||||||
|
frey : [(2, 1), (1, 0), (1, 1), (0, 0)]
|
||||||
|
fred : [(2, 1), (1, 0), (1, 1), (2, 0)]
|
||||||
|
free : [(2, 1), (1, 0), (1, 1), (2, 2)]
|
||||||
|
fo : [(2, 1), (1, 2)]
|
||||||
|
foo : [(2, 1), (1, 2), (0, 2)]
|
||||||
|
foe : [(2, 1), (1, 2), (0, 1)]
|
||||||
|
foe : [(2, 1), (1, 2), (2, 2)]
|
||||||
|
foy : [(2, 1), (1, 2), (2, 3)]
|
||||||
|
foe : [(2, 1), (1, 2), (1, 1)]
|
||||||
|
fm : [(2, 1), (3, 1)]
|
||||||
|
fn : [(2, 1), (3, 0)]
|
||||||
|
fe : [(2, 1), (3, 2)]
|
||||||
|
fee : [(2, 1), (3, 2), (2, 2)]
|
||||||
|
fey : [(2, 1), (3, 2), (2, 3)]
|
||||||
|
fem : [(2, 1), (3, 2), (3, 1)]
|
||||||
|
feme : [(2, 1), (3, 2), (3, 1), (2, 2)]
|
||||||
|
fe : [(2, 1), (2, 2)]
|
||||||
|
fee : [(2, 1), (2, 2), (1, 1)]
|
||||||
|
feed : [(2, 1), (2, 2), (1, 1), (2, 0)]
|
||||||
|
feer : [(2, 1), (2, 2), (1, 1), (1, 0)]
|
||||||
|
feere : [(2, 1), (2, 2), (1, 1), (1, 0), (0, 1)]
|
||||||
|
fee : [(2, 1), (2, 2), (3, 2)]
|
||||||
|
fem : [(2, 1), (2, 2), (3, 1)]
|
||||||
|
feme : [(2, 1), (2, 2), (3, 1), (3, 2)]
|
||||||
|
fey : [(2, 1), (2, 2), (2, 3)]
|
||||||
|
|
||||||
|
Starting @ (2, 2)...
|
||||||
|
e : [(2, 2)]
|
||||||
|
eo : [(2, 2), (1, 2)]
|
||||||
|
eos : [(2, 2), (1, 2), (0, 3)]
|
||||||
|
eof : [(2, 2), (1, 2), (2, 1)]
|
||||||
|
ee : [(2, 2), (1, 1)]
|
||||||
|
eer : [(2, 2), (1, 1), (1, 0)]
|
||||||
|
eery : [(2, 2), (1, 1), (1, 0), (0, 0)]
|
||||||
|
evoe : [(2, 2), (1, 3), (0, 2), (1, 1)]
|
||||||
|
evoe : [(2, 2), (1, 3), (0, 2), (0, 1)]
|
||||||
|
evoe : [(2, 2), (1, 3), (1, 2), (0, 1)]
|
||||||
|
evoe : [(2, 2), (1, 3), (1, 2), (1, 1)]
|
||||||
|
ee : [(2, 2), (3, 2)]
|
||||||
|
em : [(2, 2), (3, 1)]
|
||||||
|
emf : [(2, 2), (3, 1), (2, 1)]
|
||||||
|
eme : [(2, 2), (3, 1), (3, 2)]
|
||||||
|
ef : [(2, 2), (2, 1)]
|
||||||
|
ey : [(2, 2), (2, 3)]
|
||||||
|
eye : [(2, 2), (2, 3), (3, 2)]
|
||||||
|
|
||||||
|
Starting @ (2, 3)...
|
||||||
|
y : [(2, 3)]
|
||||||
|
yo : [(2, 3), (1, 2)]
|
||||||
|
yoe : [(2, 3), (1, 2), (0, 1)]
|
||||||
|
yoe : [(2, 3), (1, 2), (2, 2)]
|
||||||
|
yoe : [(2, 3), (1, 2), (1, 1)]
|
||||||
|
yquem : [(2, 3), (3, 3), (2, 2), (3, 1)]
|
||||||
|
yquem : [(2, 3), (3, 3), (3, 2), (3, 1)]
|
||||||
|
ye : [(2, 3), (3, 2)]
|
||||||
|
yee : [(2, 3), (3, 2), (2, 2)]
|
||||||
|
ye : [(2, 3), (2, 2)]
|
||||||
|
yeo : [(2, 3), (2, 2), (1, 2)]
|
||||||
|
yee : [(2, 3), (2, 2), (1, 1)]
|
||||||
|
yee : [(2, 3), (2, 2), (3, 2)]
|
||||||
|
|
||||||
|
Starting @ (3, 0)...
|
||||||
|
n : [(3, 0)]
|
||||||
|
nd : [(3, 0), (2, 0)]
|
||||||
|
nm : [(3, 0), (3, 1)]
|
||||||
|
|
||||||
|
Starting @ (3, 1)...
|
||||||
|
m : [(3, 1)]
|
||||||
|
mf : [(3, 1), (2, 1)]
|
||||||
|
mfr : [(3, 1), (2, 1), (1, 0)]
|
||||||
|
mfd : [(3, 1), (2, 1), (2, 0)]
|
||||||
|
md : [(3, 1), (2, 0)]
|
||||||
|
me : [(3, 1), (2, 2)]
|
||||||
|
meo : [(3, 1), (2, 2), (1, 2)]
|
||||||
|
mee : [(3, 1), (2, 2), (1, 1)]
|
||||||
|
meed : [(3, 1), (2, 2), (1, 1), (2, 0)]
|
||||||
|
meer : [(3, 1), (2, 2), (1, 1), (1, 0)]
|
||||||
|
mev : [(3, 1), (2, 2), (1, 3)]
|
||||||
|
mee : [(3, 1), (2, 2), (3, 2)]
|
||||||
|
mn : [(3, 1), (3, 0)]
|
||||||
|
me : [(3, 1), (3, 2)]
|
||||||
|
mee : [(3, 1), (3, 2), (2, 2)]
|
||||||
|
|
||||||
|
Starting @ (3, 2)...
|
||||||
|
e : [(3, 2)]
|
||||||
|
ee : [(3, 2), (2, 2)]
|
||||||
|
ef : [(3, 2), (2, 1)]
|
||||||
|
ey : [(3, 2), (2, 3)]
|
||||||
|
eye : [(3, 2), (2, 3), (2, 2)]
|
||||||
|
em : [(3, 2), (3, 1)]
|
||||||
|
emf : [(3, 2), (3, 1), (2, 1)]
|
||||||
|
eme : [(3, 2), (3, 1), (2, 2)]
|
||||||
|
emeer : [(3, 2), (3, 1), (2, 2), (1, 1), (1, 0)]
|
||||||
|
|
||||||
|
Starting @ (3, 3)...
|
||||||
|
qu : [(3, 3)]
|
||||||
|
que : [(3, 3), (2, 2)]
|
||||||
|
queer : [(3, 3), (2, 2), (1, 1), (1, 0)]
|
||||||
|
queery : [(3, 3), (2, 2), (1, 1), (1, 0), (0, 0)]
|
||||||
|
quem : [(3, 3), (2, 2), (3, 1)]
|
||||||
|
queme : [(3, 3), (2, 2), (3, 1), (3, 2)]
|
||||||
|
quey : [(3, 3), (2, 2), (2, 3)]
|
||||||
|
que : [(3, 3), (3, 2)]
|
||||||
|
quey : [(3, 3), (3, 2), (2, 3)]
|
||||||
|
quem : [(3, 3), (3, 2), (3, 1)]
|
||||||
|
queme : [(3, 3), (3, 2), (3, 1), (2, 2)]
|
||||||
|
```
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
aucd
|
|
||||||
eegh
|
|
||||||
hios
|
|
||||||
trea
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
vdau
|
|
||||||
ptuo
|
|
||||||
ohxr
|
|
||||||
wlhn
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
nxaa
|
|
||||||
vatr
|
|
||||||
ieba
|
|
||||||
iurn
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
vdat
|
|
||||||
pteo
|
|
||||||
ohnr
|
|
||||||
wlan
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
nbapi
|
|
||||||
satrk
|
|
||||||
iebae
|
|
||||||
turnl
|
|
||||||
icqme
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
nbapir
|
|
||||||
satrkp
|
|
||||||
iebaez
|
|
||||||
turnls
|
|
||||||
icqmet
|
|
||||||
nynjro
|
|
||||||
-111
@@ -1,111 +0,0 @@
|
|||||||
import sys
|
|
||||||
from dictionary_utils import WordTree
|
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
def read_boggle_file(file):
|
|
||||||
'''Return list of rows from Boggle board file'''
|
|
||||||
with open(file, 'r', encoding='utf-8') as file:
|
|
||||||
return [x.rstrip() for x in file.readlines()]
|
|
||||||
|
|
||||||
def read_wordlist(file):
|
|
||||||
'''Return dictionary of words with associated word count (1 by default)'''
|
|
||||||
with open(file, 'r', encoding='utf-8') as file:
|
|
||||||
return {k:1 for k in file.read().split()}
|
|
||||||
|
|
||||||
def get_adjacent_indexes(board, row, col):
|
|
||||||
'''Return adjecency list for matrix (Boggle board) of size `row x col`'''
|
|
||||||
max_height = len(board) - 1
|
|
||||||
max_width = len(board[0]) - 1
|
|
||||||
indexes = []
|
|
||||||
if row > 0:
|
|
||||||
indexes.append((row-1, col)) # up
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row-1, col-1)) # up-left
|
|
||||||
if col < max_width:
|
|
||||||
indexes.append((row-1, col+1)) # up-right
|
|
||||||
if row < max_height:
|
|
||||||
indexes.append((row+1, col)) # down
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row+1, col-1)) # down-left
|
|
||||||
if col < max_width:
|
|
||||||
indexes.append((row+1, col+1)) # down-right
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row, col-1)) # left
|
|
||||||
if col < max_width:
|
|
||||||
indexes.append((row, col+1)) # right
|
|
||||||
|
|
||||||
return indexes
|
|
||||||
|
|
||||||
def find_words_by_index(board, wordlist, row, col, depth, adjacent_indexes, prefix = '', path = [], found_words = {}, prefixes = None, max_depth = 5, prefix_len = 0):
|
|
||||||
if depth == max_depth:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
if prefixes != None and depth == prefix_len and prefix not in prefixes:
|
|
||||||
return {}
|
|
||||||
prefix = prefix + board[row][col]
|
|
||||||
|
|
||||||
found_words = deepcopy(found_words)
|
|
||||||
path = deepcopy(path)
|
|
||||||
|
|
||||||
path.append((row, col))
|
|
||||||
if prefix in wordlist:
|
|
||||||
found_words[prefix] = 1
|
|
||||||
|
|
||||||
adjacents = [x for x in adjacent_indexes[(row, col)] if x not in path]
|
|
||||||
for adj in adjacents:
|
|
||||||
new_words = find_words_by_index(board,
|
|
||||||
wordlist,
|
|
||||||
adj[0],
|
|
||||||
adj[1],
|
|
||||||
depth+1,
|
|
||||||
adjacent_indexes,
|
|
||||||
prefix,
|
|
||||||
path,
|
|
||||||
found_words,
|
|
||||||
prefixes,
|
|
||||||
max_depth,
|
|
||||||
prefix_len)
|
|
||||||
for k, v in new_words.items():
|
|
||||||
if k in wordlist and k in found_words:
|
|
||||||
# Add and increment word counts
|
|
||||||
#foundWords[k] = foundWords[k] + v
|
|
||||||
found_words[k] = found_words[k]
|
|
||||||
elif k in wordlist.keys():
|
|
||||||
found_words[k] = v
|
|
||||||
|
|
||||||
return found_words
|
|
||||||
|
|
||||||
def find_words(board, adjacent_indexes, wordlist_path, max_depth = 5, prefixes = None, prefix_len = 0):
|
|
||||||
words = {}
|
|
||||||
for row in range(len(board)):
|
|
||||||
for col in range(len(board[0])):
|
|
||||||
# Find words for each row/col starting points
|
|
||||||
wordlist = read_wordlist(wordlist_path + 'words_' + board[row][col] + '.txt')
|
|
||||||
newWords = find_words_by_index(board, wordlist, row, col, 0, adjacent_indexes, prefixes = prefixes, max_depth = max_depth, prefix_len = prefix_len)
|
|
||||||
for w,v in newWords.items():
|
|
||||||
# Add and increment word counts
|
|
||||||
words[w] = words[w] + v if w in words.keys() else v
|
|
||||||
|
|
||||||
return words
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
if len(sys.argv) != 5:
|
|
||||||
print('Usage: python3 blogger.py <BOARD_FILE> <MAX_WORD_LENGTH> <PREFIX_FILE> <WORDLISTS>')
|
|
||||||
else:
|
|
||||||
board = read_boggle_file(sys.argv[1])
|
|
||||||
print(board)
|
|
||||||
adjacentIndexes = {}
|
|
||||||
for r in range(len(board)):
|
|
||||||
for c in range(len(board)):
|
|
||||||
adjacentIndexes[(r,c)] = get_adjacent_indexes(board, r, c)
|
|
||||||
|
|
||||||
adjacentLetters = {
|
|
||||||
k:[board[pos[0]][pos[1]] for pos in v] for (k,v) in adjacentIndexes.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
maxSize = int(sys.argv[2], 10)
|
|
||||||
prefixes = read_wordlist(sys.argv[3])
|
|
||||||
words = find_words(board, adjacentIndexes, sys.argv[4], maxSize, prefixes, 4)
|
|
||||||
for w in words:
|
|
||||||
print(w)
|
|
||||||
@@ -1,308 +0,0 @@
|
|||||||
'''Boggler Utils'''
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
from multiprocessing import Pool
|
|
||||||
|
|
||||||
class BoardCell:
|
|
||||||
'''Boggle Board cell'''
|
|
||||||
def __init__(self, row: int, col: int, letter: str, adjacent_cells: list[BoardCell] = None) -> BoardCell:
|
|
||||||
self.__row: int = row
|
|
||||||
self.__col: int = col
|
|
||||||
self.__pos: (int, int) = (self.__row, self.__col)
|
|
||||||
self.__letter: str = letter
|
|
||||||
self.__adjacent_cells: list[BoardCell] = adjacent_cells
|
|
||||||
|
|
||||||
@property
|
|
||||||
def row(self) -> int:
|
|
||||||
'''Getter for row property'''
|
|
||||||
return self.__row
|
|
||||||
|
|
||||||
@property
|
|
||||||
def col(self) -> int:
|
|
||||||
'''Getter for col property'''
|
|
||||||
return self.__col
|
|
||||||
|
|
||||||
@property
|
|
||||||
def pos(self) -> (int, int):
|
|
||||||
'''Getter for pos property'''
|
|
||||||
return self.__pos
|
|
||||||
|
|
||||||
@property
|
|
||||||
def letter(self) -> str:
|
|
||||||
'''Getter for letter property'''
|
|
||||||
return self.__letter
|
|
||||||
|
|
||||||
@property
|
|
||||||
def adjacent_cells(self) -> list[BoardCell]:
|
|
||||||
'''Getter for adjacent_cells property'''
|
|
||||||
return self.__adjacent_cells
|
|
||||||
|
|
||||||
@adjacent_cells.setter
|
|
||||||
def adjacent_cells(self, value):
|
|
||||||
self.__adjacent_cells = value
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"({self.__row}, {self.__col}: {self.__letter} | {self.__adjacent_cells})"
|
|
||||||
|
|
||||||
class BoggleBoard:
|
|
||||||
'''Boggle board structure'''
|
|
||||||
def __init__(self, board: list[list[str]], max_word_len: int = 14) -> BoggleBoard:
|
|
||||||
self.__height: int = len(board)
|
|
||||||
self.__width: int = len(board[0]) if self.__height > 0 else 0
|
|
||||||
self.__board: dict[(int, int), BoardCell] = {}
|
|
||||||
|
|
||||||
# max word length is limited by size of the board
|
|
||||||
self.__max_word_len = min(max_word_len, self.__width * self.__height)
|
|
||||||
|
|
||||||
# Generate BoardCell for each position on the board
|
|
||||||
for row in range(0, self.__height):
|
|
||||||
for col in range(0, self.__width):
|
|
||||||
#self.adjacency_dict[(row, col)] = self.__get_adjacent_indexes(row, col)
|
|
||||||
self.__board[(row, col)] = BoardCell(row, col, board[row][col])
|
|
||||||
|
|
||||||
# Update adjacent cell references for each BoardCell
|
|
||||||
for cell in self.__board.values():
|
|
||||||
adjacent_indexes = self.__get_adjacent_indexes(cell.row, cell.col)
|
|
||||||
#print(cell)
|
|
||||||
#print(adjacent_indexes)
|
|
||||||
cell.adjacent_cells = [self.__board[(x[0], x[1])] for x in adjacent_indexes]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def height(self) -> int:
|
|
||||||
'''Getter for height property'''
|
|
||||||
return self.__height
|
|
||||||
|
|
||||||
@property
|
|
||||||
def width(self) -> int:
|
|
||||||
'''Getter for width property'''
|
|
||||||
return self.__width
|
|
||||||
@property
|
|
||||||
def max_word_len(self) -> int:
|
|
||||||
'''Getter for maximum word length property'''
|
|
||||||
return self.__max_word_len
|
|
||||||
@property
|
|
||||||
def board(self) -> dict((int, int), BoardCell):
|
|
||||||
'''Getter for board property'''
|
|
||||||
return self.__board
|
|
||||||
|
|
||||||
def __get_adjacent_indexes(self, row, col):
|
|
||||||
'''Return adjecency list for board of size `row x col`'''
|
|
||||||
indexes = []
|
|
||||||
if row > 0:
|
|
||||||
indexes.append((row-1, col)) # up
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row-1, col-1)) # up-left
|
|
||||||
if col < self.width - 1:
|
|
||||||
indexes.append((row-1, col+1)) # up-right
|
|
||||||
if row < self.height - 1:
|
|
||||||
indexes.append((row+1, col)) # down
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row+1, col-1)) # down-left
|
|
||||||
if col < self.width - 1:
|
|
||||||
indexes.append((row+1, col+1)) # down-right
|
|
||||||
if col > 0:
|
|
||||||
indexes.append((row, col-1)) # left
|
|
||||||
if col < self.width - 1:
|
|
||||||
indexes.append((row, col+1)) # right
|
|
||||||
return indexes
|
|
||||||
|
|
||||||
def get_cell(self, row: int, col: int) -> str:
|
|
||||||
'''Return the value at the specified row x column'''
|
|
||||||
return self.__board[(row, col)]
|
|
||||||
|
|
||||||
class WordNode:
|
|
||||||
'''A node describing a single letter in a WordTree.'''
|
|
||||||
def __init__(self, char: str, is_word: bool, parent: WordNode = None, children: dict[WordNode] = None, board_pos = None) -> WordNode:
|
|
||||||
self.char = char
|
|
||||||
self.is_word = is_word
|
|
||||||
self.children = children if children is not None else {}
|
|
||||||
self.parent = parent
|
|
||||||
self.board_pos = board_pos
|
|
||||||
|
|
||||||
def add_child_node(self, node):
|
|
||||||
'''Add child node to `children` dictionary, indexed by the nodes' `char`'''
|
|
||||||
self.children[node.char] = node
|
|
||||||
|
|
||||||
@property
|
|
||||||
def path(self) -> list[WordNode]:
|
|
||||||
'''Return list of nodes from current node to the root'''
|
|
||||||
curr_node = self
|
|
||||||
path = []
|
|
||||||
path.append(curr_node.board_pos)
|
|
||||||
while curr_node.parent is not None:
|
|
||||||
path.append(curr_node.parent.board_pos)
|
|
||||||
curr_node = curr_node.parent
|
|
||||||
|
|
||||||
return path
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
# return f"WordNode: {self.char}, {self.is_word}, {self.children}"
|
|
||||||
return f"WordNode: {self.char}, {self.is_word}"
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__str__()
|
|
||||||
|
|
||||||
class WordTree:
|
|
||||||
'''A tree populated by WordNode(s) to complete words from a given root letter and wordlist'''
|
|
||||||
def __init__(self, alphabet: str, root: str, words: list[str] = None, max_word_len = 16) -> WordTree:
|
|
||||||
self.alphabet = alphabet
|
|
||||||
self.wordlist = words
|
|
||||||
self.root = root
|
|
||||||
self.max_word_len = max_word_len
|
|
||||||
self.tree = {}
|
|
||||||
|
|
||||||
# Generate root node
|
|
||||||
self.tree[root] = WordNode(root, False)
|
|
||||||
self.active_node: WordNode = self.tree[root]
|
|
||||||
|
|
||||||
# Populate tree from wordlist
|
|
||||||
if words is not None:
|
|
||||||
for word in words:
|
|
||||||
self.__insert_word(word)
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return ", ".join(self.wordlist)
|
|
||||||
|
|
||||||
def insert_letter(self, letter: str, parent: WordNode, is_word: bool = False, children: dict[WordNode] = None, board_pos = None):
|
|
||||||
'''Create WordNode for `letter` and into WordTree under `parent`'''
|
|
||||||
node = WordNode(letter, is_word, parent, children, board_pos)
|
|
||||||
parent.add_child_node(node)
|
|
||||||
|
|
||||||
def __insert_word(self, word: str) -> bool:
|
|
||||||
'''Returns True if word was inserted into the tree, otherwise False'''
|
|
||||||
if word is None or word[0] != self.root:
|
|
||||||
return False
|
|
||||||
curr_node = self.tree[word[0]]
|
|
||||||
# print(word[0])
|
|
||||||
for letter in word[1:self.max_word_len]:
|
|
||||||
# Insert new WordNode for each letter that doesen't already exist in the tree
|
|
||||||
if letter not in curr_node.children:
|
|
||||||
self.insert_letter(letter, curr_node)
|
|
||||||
# print(letter)
|
|
||||||
curr_node = curr_node.children[letter]
|
|
||||||
# Mark the last node of the word
|
|
||||||
curr_node.is_word = len(word) <= self.max_word_len
|
|
||||||
print(f"Added: {word[:self.max_word_len]}")
|
|
||||||
return True
|
|
||||||
|
|
||||||
def search(self, word: str) -> WordNode:
|
|
||||||
'''Return True if a given word is in the tree otherwise return False'''
|
|
||||||
if len(word) == 0 or word is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
curr_node = self.tree[word[0]]
|
|
||||||
for char in word[1:]:
|
|
||||||
if char not in curr_node.children:
|
|
||||||
return None
|
|
||||||
|
|
||||||
curr_node = curr_node.children[char]
|
|
||||||
|
|
||||||
return curr_node
|
|
||||||
|
|
||||||
def build_boggle_tree(self, board: BoggleBoard, board_cell: BoardCell, subtree: WordTree, depth: int = 0) -> WordTree:
|
|
||||||
'''Return subtree of board given a particular root (first letter).
|
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
board -- the board the new tree is based on
|
|
||||||
board_node -- a pointer on the board where new branch nodes can be inserted into the tree
|
|
||||||
dict_node -- a pointer on the dictionary where nodes are read from for validation
|
|
||||||
subtree -- the partial tree passed to the next recursive step for generating branches
|
|
||||||
'''
|
|
||||||
|
|
||||||
# TODO rework active_node refs for recursion so don't have to be reset to parent at every point of return
|
|
||||||
if self.active_node.is_word and len(self.active_node.children) == 0:
|
|
||||||
word_path = subtree.active_node.path[::-1]
|
|
||||||
print("WORD FOUND:", "".join([board.board[x].letter for x in word_path]), word_path)
|
|
||||||
self.active_node = self.active_node.parent
|
|
||||||
subtree.active_node = subtree.active_node.parent
|
|
||||||
return
|
|
||||||
elif self.active_node.is_word:
|
|
||||||
word_path = subtree.active_node.path[::-1]
|
|
||||||
print("WORD FOUND:", "".join([board.board[x].letter for x in word_path]), word_path)
|
|
||||||
elif depth > self.max_word_len:
|
|
||||||
print(f"MAX DEPTH REACHED! Depth = {depth}")
|
|
||||||
self.active_node = self.active_node.parent
|
|
||||||
subtree.active_node = subtree.active_node.parent
|
|
||||||
return
|
|
||||||
|
|
||||||
# Branch for each adjacent board cell
|
|
||||||
for cell in board_cell.adjacent_cells:
|
|
||||||
# Check dictionary and exclude nodes already in path
|
|
||||||
print("Cell:", cell.letter, cell.pos, subtree.active_node.path)
|
|
||||||
if cell.letter in self.active_node.children and cell.pos not in subtree.active_node.path:
|
|
||||||
# print(cell)
|
|
||||||
print(self.active_node)
|
|
||||||
#subtree.insert_letter(cell.letter, subtree.active_node, self.active_node.is_word, board_pos=cell.pos)
|
|
||||||
new_node = WordNode(cell.letter, self.active_node.is_word, subtree.active_node, board_pos = cell.pos)
|
|
||||||
subtree.active_node.add_child_node(new_node)
|
|
||||||
subtree.active_node = subtree.active_node.children[cell.letter] # update subtree pointer
|
|
||||||
self.active_node = self.active_node.children[cell.letter] # update dictionary tree pointer
|
|
||||||
self.build_boggle_tree(board, board.board[cell.pos], subtree)
|
|
||||||
|
|
||||||
print(f"DONE SEARCHING at {subtree.active_node}")
|
|
||||||
|
|
||||||
self.active_node = self.active_node.parent
|
|
||||||
subtree.active_node = subtree.active_node.parent
|
|
||||||
return subtree
|
|
||||||
|
|
||||||
def read_wordlist(file):
|
|
||||||
'''Return dictionary of words with associated word count (1 by default)'''
|
|
||||||
with open(file, 'r', encoding='utf-8') as file:
|
|
||||||
return {k:1 for k in file.read().split()}
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# sample_dict = [
|
|
||||||
# 'aero',
|
|
||||||
# 'anger',
|
|
||||||
# 'ant',
|
|
||||||
# 'ape',
|
|
||||||
# 'argue',
|
|
||||||
# 'ash',
|
|
||||||
# 'assuage',
|
|
||||||
# 'aunt',
|
|
||||||
# 'auspice',
|
|
||||||
# 'bigger',
|
|
||||||
# 'bit',
|
|
||||||
# 'bite',
|
|
||||||
# 'biter',
|
|
||||||
# 'cart',
|
|
||||||
# 'cast',
|
|
||||||
# ]
|
|
||||||
|
|
||||||
sample_dict = read_wordlist("wordlists/dwyl/words_a.txt")
|
|
||||||
|
|
||||||
tree = WordTree("abcdefghijklmnopqrstuvwxyz", "a", sample_dict)
|
|
||||||
n1 = tree.search('anger')
|
|
||||||
#print(n1.path)
|
|
||||||
#print(tree.search('argues'))
|
|
||||||
print("=" * 50)
|
|
||||||
|
|
||||||
b1 = [
|
|
||||||
"aucd",
|
|
||||||
"eegh",
|
|
||||||
"hios",
|
|
||||||
"trea"
|
|
||||||
]
|
|
||||||
|
|
||||||
b2 = [
|
|
||||||
"iats",
|
|
||||||
"osep",
|
|
||||||
"tras",
|
|
||||||
"yegc"
|
|
||||||
]
|
|
||||||
|
|
||||||
b1_board = BoggleBoard(b1)
|
|
||||||
b2_board = BoggleBoard(b2)
|
|
||||||
|
|
||||||
b1_tree = WordTree("abcdefghijklmnopqrstuvwxyz", "a")
|
|
||||||
b1_tree.tree["a"].board_pos = (3,3)
|
|
||||||
|
|
||||||
b2_tree = WordTree("abcdefghijklmnopqrstuvwxyz", "a")
|
|
||||||
b2_tree.tree["a"].board_pos = (0,1)
|
|
||||||
|
|
||||||
#sub_tree = tree.build_boggle_tree(b1_board, b1_board.board[(0,0)], b1_tree)
|
|
||||||
sub_tree = tree.build_boggle_tree(b2_board, b2_board.board[(2,2)], b2_tree)
|
|
||||||
#sub_tree = tree.build_board_sub_tree(b1_board, b1_board.board[(3, 3)])
|
|
||||||
#print(sub_tree.search("anger"))
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
front,right,back,left,top,bottom (start with 'one of' the first alphabetical chars
|
|
||||||
-----------
|
|
||||||
a,h,s,p,o,c
|
|
||||||
e,r,l,i,x,d
|
|
||||||
a,g,a,e,e,a
|
|
||||||
e,y,t,l,r,t
|
|
||||||
e,o,t,s,s,i
|
|
||||||
d,r,y,v,l,e
|
|
||||||
h,n,l,n,z,r
|
|
||||||
e,r,w,t,v,h
|
|
||||||
h,i,u,n,m,qu
|
|
||||||
e,e,h,n,w,g
|
|
||||||
d,t,y,t,i,s
|
|
||||||
a,b,b,o,o,j
|
|
||||||
e,i,u,n,s,e
|
|
||||||
a,s,p,f,k,f
|
|
||||||
c,m,u,o,i,t
|
|
||||||
a,w,t,o,o,t
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "boggler"
|
||||||
|
version = "1.0.1"
|
||||||
|
authors = [
|
||||||
|
{ name="Cameron Blankenbuehler", email="cameron.blankenbuehler@gmail.com" },
|
||||||
|
]
|
||||||
|
description = "Utilities for solving the Boggle word game."
|
||||||
|
readme="README.md"
|
||||||
|
license = { file="LICENSE" }
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
||||||
|
"Operating System :: POSIX :: Linux",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
"Homepage" = "https://github.com/cblanken/boggler"
|
||||||
|
"Bug Tracker" = "https://github.com/cblanken/boggler/issues"
|
||||||
@@ -4,9 +4,10 @@ from random import randint, shuffle
|
|||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
def read_dice_file(path):
|
def read_dice_file(path):
|
||||||
|
# TODO: Factor in 'qu' die face
|
||||||
'''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, 'r+', encoding="utf-8") as file:
|
||||||
return [''.join(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):
|
||||||
'''Return a face of the given die string to simulate rolling a die'''
|
'''Return a face of the given die string to simulate rolling a die'''
|
||||||
@@ -27,4 +28,4 @@ if __name__ == '__main__':
|
|||||||
# Format dice rolls for boards file
|
# Format dice rolls for boards file
|
||||||
board_size = int(sqrt(len(rolls)))
|
board_size = int(sqrt(len(rolls)))
|
||||||
for i in range(0, len(dice_strings), board_size):
|
for i in range(0, len(dice_strings), board_size):
|
||||||
print("".join(rolls[i:i+board_size]))
|
print(",".join(rolls[i:i+board_size]))
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
s,a,i,p
|
||||||
|
l,qu,a,y
|
||||||
|
u,l,l,s
|
||||||
|
o,w,h,a
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
t,h,a,e
|
||||||
|
o,p,j,v
|
||||||
|
f,e,i,t
|
||||||
|
n,e,v,i
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
w,a,n,c
|
||||||
|
j,i,e,u
|
||||||
|
y,g,o,e
|
||||||
|
i,l,e,c
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
y,o,o,a
|
||||||
|
p,l,n,v
|
||||||
|
t,i,o,qu
|
||||||
|
n,f,u,t
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
o,d,r,s
|
||||||
|
a,h,e,s
|
||||||
|
e,t,i,h
|
||||||
|
u,r,e,o
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
e,t,p,a
|
||||||
|
b,m,v,g
|
||||||
|
c,s,e,n
|
||||||
|
x,g,d,t
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
c,e,s,o
|
||||||
|
e,j,d,h
|
||||||
|
s,n,r,h
|
||||||
|
w,c,r,y
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
l,e,e,e
|
||||||
|
b,k,p,o
|
||||||
|
h,u,u,i
|
||||||
|
y,t,t,s
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
y,e,o,s
|
||||||
|
r,e,o,v
|
||||||
|
d,f,e,y
|
||||||
|
n,m,e,qu
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
e,w,t,m
|
||||||
|
s,p,m,r
|
||||||
|
h,y,o,x
|
||||||
|
y,t,e,w
|
||||||
|
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
"""Boggler Demo"""
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from boggler_utils import BoggleBoard, build_full_boggle_tree, read_boggle_file
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) < 3 or len(sys.argv) > 4:
|
||||||
|
print('Usage: python3 boggler.py <BOARD_FILE> <WORDLISTS_DIR> [MAX_WORD_LENGTH]')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
board = read_boggle_file(Path(sys.argv[1]))
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
boggle_board = BoggleBoard(board)
|
||||||
|
print(boggle_board)
|
||||||
|
boggle_tree = build_full_boggle_tree(boggle_board, Path(sys.argv[2]))
|
||||||
|
elif len(sys.argv) == 4:
|
||||||
|
try :
|
||||||
|
boggle_board = BoggleBoard(board, int(sys.argv[3]))
|
||||||
|
boggle_tree = build_full_boggle_tree(boggle_board, Path(sys.argv[2]))
|
||||||
|
|
||||||
|
print("\nBOARD")
|
||||||
|
print(boggle_board)
|
||||||
|
|
||||||
|
for start_pos, tree in boggle_tree.items():
|
||||||
|
print(f"\nStarting @ {start_pos}...")
|
||||||
|
for word in tree.word_paths:
|
||||||
|
print(f"{word[0]: <{boggle_board.max_word_len}}: {word[1]}")
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
print("The [MAX_WORD_LENGTH] argument must be an integer.")
|
||||||
|
print("Please try again.")
|
||||||
|
sys.exit(1)
|
||||||
Executable
+412
@@ -0,0 +1,412 @@
|
|||||||
|
'''Boggler Utils'''
|
||||||
|
from __future__ import annotations
|
||||||
|
from os import path
|
||||||
|
from multiprocessing import Pool
|
||||||
|
|
||||||
|
class BoardCell:
|
||||||
|
'''Boggle Board cell'''
|
||||||
|
def __init__(self, row: int, col: int, letters: str,
|
||||||
|
adjacent_cells: list[BoardCell] = None) -> BoardCell:
|
||||||
|
self.__row: int = row
|
||||||
|
self.__col: int = col
|
||||||
|
self.__pos: (int, int) = (self.__row, self.__col)
|
||||||
|
self.__letters: str = letters
|
||||||
|
self.__adjacent_cells: list[BoardCell] = adjacent_cells
|
||||||
|
|
||||||
|
@property
|
||||||
|
def row(self) -> int:
|
||||||
|
'''Getter for row property'''
|
||||||
|
return self.__row
|
||||||
|
|
||||||
|
@property
|
||||||
|
def col(self) -> int:
|
||||||
|
'''Getter for col property'''
|
||||||
|
return self.__col
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pos(self) -> (int, int):
|
||||||
|
'''Getter for pos property'''
|
||||||
|
return self.__pos
|
||||||
|
|
||||||
|
@property
|
||||||
|
def letters(self) -> str:
|
||||||
|
'''Getter for letter property'''
|
||||||
|
return self.__letters
|
||||||
|
|
||||||
|
@property
|
||||||
|
def adjacent_cells(self) -> list[BoardCell]:
|
||||||
|
'''Getter for adjacent_cells property'''
|
||||||
|
return self.__adjacent_cells
|
||||||
|
|
||||||
|
@adjacent_cells.setter
|
||||||
|
def adjacent_cells(self, value):
|
||||||
|
self.__adjacent_cells = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"({self.__row}, {self.__col}): {self.__letters}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"(BoardCell({self.__row}, {self.__col}): {self.__letters}"
|
||||||
|
|
||||||
|
class BoggleBoard:
|
||||||
|
'''Boggle board structure'''
|
||||||
|
def __init__(self, board: list[list[str]], max_word_len: int = 14) -> BoggleBoard:
|
||||||
|
self.__height: int = len(board)
|
||||||
|
self.__width: int = len(board[0]) if self.__height > 0 else 0
|
||||||
|
self.__board_list = board
|
||||||
|
self.__board: dict[(int, int), BoardCell] = {}
|
||||||
|
|
||||||
|
# Max word length is limited by size of the board
|
||||||
|
self.__max_word_len = min(max_word_len, self.__width * self.__height)
|
||||||
|
|
||||||
|
# Generate BoardCell for each position on the board
|
||||||
|
for row in range(0, self.__height):
|
||||||
|
for col in range(0, self.__width):
|
||||||
|
self.__board[(row, col)] = BoardCell(row, col, board[row][col])
|
||||||
|
|
||||||
|
# Update adjacent cell references for each BoardCell
|
||||||
|
for cell in self.__board.values():
|
||||||
|
adjacent_indexes = self.__get_adjacent_indexes(cell.row, cell.col)
|
||||||
|
cell.adjacent_cells = [self.__board[(x[0], x[1])] for x in adjacent_indexes]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
flattened_board_list = [y for x in self.__board_list for y in x]
|
||||||
|
max_len = len(max(flattened_board_list, key=len))
|
||||||
|
max_len = max_len + 1 if max_len % 2 == 0 else max_len + 2 # keep header_len odd
|
||||||
|
header_len = self.__width * (max_len + 1) - 1
|
||||||
|
head = "-" * header_len
|
||||||
|
header = f"+{head}+\n"
|
||||||
|
body = ""
|
||||||
|
for row in self.__board_list:
|
||||||
|
body += "|"
|
||||||
|
for col in row:
|
||||||
|
body += f"{col.upper(): ^{max_len}}|"
|
||||||
|
body += "\n"
|
||||||
|
body += header
|
||||||
|
return f"{header}{body}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self) -> int:
|
||||||
|
'''Getter for height property'''
|
||||||
|
return self.__height
|
||||||
|
|
||||||
|
@property
|
||||||
|
def width(self) -> int:
|
||||||
|
'''Getter for width property'''
|
||||||
|
return self.__width
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_word_len(self) -> int:
|
||||||
|
'''Getter for maximum word length property'''
|
||||||
|
return self.__max_word_len
|
||||||
|
|
||||||
|
@property
|
||||||
|
def board(self) -> dict[(int, int), BoardCell]:
|
||||||
|
'''Getter for board property'''
|
||||||
|
return self.__board
|
||||||
|
|
||||||
|
def __get_adjacent_indexes(self, row, col):
|
||||||
|
'''Return adjecency list for board of size `row x col`'''
|
||||||
|
indexes = []
|
||||||
|
if row > 0:
|
||||||
|
indexes.append((row-1, col)) # up
|
||||||
|
if col > 0:
|
||||||
|
indexes.append((row-1, col-1)) # up-left
|
||||||
|
if col < self.width - 1:
|
||||||
|
indexes.append((row-1, col+1)) # up-right
|
||||||
|
if row < self.height - 1:
|
||||||
|
indexes.append((row+1, col)) # down
|
||||||
|
if col > 0:
|
||||||
|
indexes.append((row+1, col-1)) # down-left
|
||||||
|
if col < self.width - 1:
|
||||||
|
indexes.append((row+1, col+1)) # down-right
|
||||||
|
if col > 0:
|
||||||
|
indexes.append((row, col-1)) # left
|
||||||
|
if col < self.width - 1:
|
||||||
|
indexes.append((row, col+1)) # right
|
||||||
|
return indexes
|
||||||
|
|
||||||
|
def get_cell(self, row: int, col: int) -> str:
|
||||||
|
'''Return the value at the specified row x column'''
|
||||||
|
return self.__board[(row, col)]
|
||||||
|
|
||||||
|
class WordNode:
|
||||||
|
'''A node describing a single letter in a WordTree.'''
|
||||||
|
def __init__(self, letters: str, is_word: bool = False, parent: WordNode = None,
|
||||||
|
children: dict[str, WordNode] = None, board_pos = None) -> WordNode:
|
||||||
|
self.__letters = letters
|
||||||
|
self.__is_word = is_word
|
||||||
|
self.__children = children if children is not None else {}
|
||||||
|
self.__parent = parent
|
||||||
|
self.__board_pos = board_pos
|
||||||
|
|
||||||
|
@property
|
||||||
|
def letters(self) -> str:
|
||||||
|
'''Getter for letter property'''
|
||||||
|
return self.__letters
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_word(self) -> bool:
|
||||||
|
'''Getter for is_word property'''
|
||||||
|
return self.__is_word
|
||||||
|
|
||||||
|
@is_word.setter
|
||||||
|
def is_word(self, value):
|
||||||
|
self.__is_word = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def children(self) -> dict[str, WordNode]:
|
||||||
|
'''Getter for children property'''
|
||||||
|
return self.__children
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parent(self) -> WordNode:
|
||||||
|
'''Getter for parent property'''
|
||||||
|
return self.__parent
|
||||||
|
|
||||||
|
@property
|
||||||
|
def board_pos(self) -> (int, int):
|
||||||
|
'''Getter for board_pos property'''
|
||||||
|
return self.__board_pos
|
||||||
|
|
||||||
|
def add_child_node(self, node):
|
||||||
|
'''Add child node to `children` dictionary, indexed by the nodes' `letter`'''
|
||||||
|
self.children[node.letters] = node
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> list[WordNode]:
|
||||||
|
'''Return list of nodes from current node to the root'''
|
||||||
|
curr_node = self
|
||||||
|
path = []
|
||||||
|
path.append(curr_node.board_pos)
|
||||||
|
while curr_node.parent is not None:
|
||||||
|
path.append(curr_node.parent.board_pos)
|
||||||
|
curr_node = curr_node.parent
|
||||||
|
|
||||||
|
return path
|
||||||
|
|
||||||
|
def get_word(self, board: BoggleBoard) -> str:
|
||||||
|
'''Return word or word fragment based on the WordNode's path property'''
|
||||||
|
return "".join([board.board[x].letters for x in self.path[::-1]])
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"WordNode: {self.letters}, {self.is_word}, {self.board_pos}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"WordNode: {self.letters}, {self.is_word}, {self.children}"
|
||||||
|
|
||||||
|
class WordTree:
|
||||||
|
'''A tree populated by WordNode(s) to complete words from a given root letter and wordlist'''
|
||||||
|
def __init__(self, alphabet: str, root: WordNode, words: list[str] = None,
|
||||||
|
max_word_len = 16) -> WordTree:
|
||||||
|
self.__alphabet: str = alphabet
|
||||||
|
self.__wordlist: list[str] = words
|
||||||
|
self.__root: WordNode = root
|
||||||
|
self.__max_word_len: int = max_word_len
|
||||||
|
self.__tree: dict[str, WordNode] = {}
|
||||||
|
self.__word_paths: dict[str, list[WordNode]] = []
|
||||||
|
|
||||||
|
# Generate root node
|
||||||
|
self.__tree[root.letters] = root
|
||||||
|
self.active_node: WordNode = self.__tree[root.letters]
|
||||||
|
|
||||||
|
# Populate tree from wordlist
|
||||||
|
if words is not None:
|
||||||
|
for word in words:
|
||||||
|
self.__insert_word(word)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def alphabet(self) -> str:
|
||||||
|
'''Getter for alphabet property'''
|
||||||
|
return self.__alphabet
|
||||||
|
|
||||||
|
@property
|
||||||
|
def wordlist(self) -> list[str]:
|
||||||
|
'''Getter for wordlist property'''
|
||||||
|
return self.__wordlist
|
||||||
|
|
||||||
|
@property
|
||||||
|
def root(self) -> WordNode:
|
||||||
|
'''Getter for root property'''
|
||||||
|
return self.__root
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_word_len(self) -> int:
|
||||||
|
'''Getter for max_word_len property'''
|
||||||
|
return self.__max_word_len
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tree(self) -> dict[str, WordNode]:
|
||||||
|
'''Getter for tree property'''
|
||||||
|
return self.__tree
|
||||||
|
|
||||||
|
@property
|
||||||
|
def word_paths(self) -> dict[(int, int), WordNode]:
|
||||||
|
'''Getter for leaf_nodes property'''
|
||||||
|
return self.__word_paths
|
||||||
|
|
||||||
|
@word_paths.setter
|
||||||
|
def word_paths(self, value):
|
||||||
|
self.__word_paths = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return ", ".join(self.wordlist)
|
||||||
|
|
||||||
|
def insert_node(self, letters: str, parent: WordNode, is_word: bool = False,
|
||||||
|
children: dict[str, WordNode] = None, board_pos = None):
|
||||||
|
'''Create WordNode for `letters` and into WordTree under `parent`'''
|
||||||
|
node = WordNode(letters, is_word, parent, children, board_pos)
|
||||||
|
parent.add_child_node(node)
|
||||||
|
|
||||||
|
def __insert_word(self, word: str) -> bool:
|
||||||
|
'''Returns True if the word could be inserted into the tree with the given alphabet,
|
||||||
|
otherwise returns False'''
|
||||||
|
|
||||||
|
# Insert root node
|
||||||
|
prefix = word[0:len(self.root.letters)] # prefix = first letter block
|
||||||
|
if word is None or prefix != self.root.letters:
|
||||||
|
return False
|
||||||
|
curr_node = self.tree[prefix]
|
||||||
|
word_len = len(word)
|
||||||
|
|
||||||
|
# Insert remaining nodes as letter groups based on alphabet
|
||||||
|
skip_cnt = 0
|
||||||
|
for i, letter in enumerate(word[len(prefix):self.max_word_len]):
|
||||||
|
# Skip word letter iterations for length of a previously inserted letter group
|
||||||
|
if skip_cnt > 0:
|
||||||
|
skip_cnt -= 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
alpha_index = [x[0] for x in self.alphabet].index(letter)
|
||||||
|
except ValueError: # letters not in given alphabet
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Insert letter (single)
|
||||||
|
if letter == self.alphabet[alpha_index] and letter not in curr_node.children:
|
||||||
|
self.insert_node(letter, curr_node)
|
||||||
|
curr_node = curr_node.children[letter]
|
||||||
|
# Letter already exists
|
||||||
|
elif letter == self.alphabet[alpha_index]:
|
||||||
|
curr_node = curr_node.children[letter]
|
||||||
|
# Check for letter groups (like "Qu") starting with `letter` in alphabet
|
||||||
|
else:
|
||||||
|
alpha = self.alphabet[alpha_index]
|
||||||
|
# Check that letter group is shorter than and matches in the word remainder
|
||||||
|
if len(alpha) < word_len - i and alpha == word[i+1:i+1+len(alpha)]:
|
||||||
|
if alpha not in curr_node.children:
|
||||||
|
self.insert_node(alpha, curr_node)
|
||||||
|
curr_node = curr_node.children[alpha]
|
||||||
|
else: # node already exist
|
||||||
|
curr_node = curr_node.children[alpha]
|
||||||
|
|
||||||
|
skip_cnt = len(alpha) - 1
|
||||||
|
#print(f"LONG GROUP: {alpha}; {word}")
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Mark the last node as a word
|
||||||
|
curr_node.is_word = len(word) <= self.max_word_len
|
||||||
|
return True
|
||||||
|
|
||||||
|
def search(self, word: str, curr_node = None) -> WordNode:
|
||||||
|
'''Return leaf (WordNode) if a given word is in the tree otherwise return None'''
|
||||||
|
if len(word) == 0 or word is None:
|
||||||
|
return curr_node
|
||||||
|
|
||||||
|
if curr_node is None:
|
||||||
|
curr_node = self.root
|
||||||
|
for letters in curr_node.children:
|
||||||
|
if letters == word[len(curr_node.letters):len(curr_node.letters) + len(letters)]:
|
||||||
|
return self.search(word[len(curr_node.letters):], curr_node.children[letters])
|
||||||
|
|
||||||
|
# Currently only returns single path for word
|
||||||
|
# TODO: return all possible paths, maybe create minature WordTree? Or just of list of paths.
|
||||||
|
return curr_node
|
||||||
|
|
||||||
|
def build_boggle_tree(self, board: BoggleBoard, board_cell: BoardCell, subtree: WordTree, depth: int = 1) -> WordTree:
|
||||||
|
'''Return subtree of board given a particular root (first letter).
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
board -- the board the new tree is based on
|
||||||
|
board_node -- a pointer on the board where new branch nodes can be inserted into the tree
|
||||||
|
dict_node -- a pointer on the dictionary where nodes are read from for validation
|
||||||
|
subtree -- the partial tree passed to the next recursive step for generating branches
|
||||||
|
'''
|
||||||
|
|
||||||
|
# TODO rework active_node refs for recursion so don't have to be reset to parent at every point of return
|
||||||
|
if self.active_node.is_word and len(self.active_node.children) == 0:
|
||||||
|
word_path = subtree.active_node.path[::-1]
|
||||||
|
subtree.word_paths.append((subtree.active_node.get_word(board), word_path))
|
||||||
|
#print("1: WORD FOUND:", "".join([board.board[x].letters for x in word_path]), word_path)
|
||||||
|
self.active_node = self.active_node.parent
|
||||||
|
subtree.active_node = subtree.active_node.parent
|
||||||
|
return
|
||||||
|
elif self.active_node.is_word:
|
||||||
|
word_path = subtree.active_node.path[::-1]
|
||||||
|
subtree.word_paths.append((subtree.active_node.get_word(board), word_path))
|
||||||
|
#print("2: WORD FOUND:", "".join([board.board[x].letters for x in word_path]), word_path)
|
||||||
|
|
||||||
|
if depth >= self.max_word_len or depth >= board.max_word_len:
|
||||||
|
#print(f"MAX DEPTH REACHED! Depth = {depth}")
|
||||||
|
subtree.active_node = subtree.active_node.parent
|
||||||
|
self.active_node = self.active_node.parent
|
||||||
|
return
|
||||||
|
|
||||||
|
# Branch for each adjacent board cell
|
||||||
|
for cell in board_cell.adjacent_cells:
|
||||||
|
# Check dictionary and exclude nodes already in path
|
||||||
|
if cell.letters in self.active_node.children and cell.pos not in subtree.active_node.path:
|
||||||
|
new_node = WordNode(cell.letters, self.active_node.is_word, subtree.active_node, board_pos = cell.pos)
|
||||||
|
subtree.active_node.add_child_node(new_node)
|
||||||
|
subtree.active_node = subtree.active_node.children[cell.letters] # update subtree pointer
|
||||||
|
self.active_node = self.active_node.children[cell.letters] # update dictionary tree pointer
|
||||||
|
self.build_boggle_tree(board, board.board[cell.pos], subtree, depth=depth+1)
|
||||||
|
|
||||||
|
self.active_node = self.active_node.parent
|
||||||
|
subtree.active_node = subtree.active_node.parent
|
||||||
|
return subtree
|
||||||
|
|
||||||
|
def build_boggle_tree(args):
|
||||||
|
'''Build boggle tree from arguments for process Pool'''
|
||||||
|
(alphabet, board, cell, wordlist) = args
|
||||||
|
root_node = WordNode(cell.letters)
|
||||||
|
dict_tree = WordTree(alphabet, root_node, wordlist)
|
||||||
|
sub_tree = WordTree(alphabet, WordNode(cell.letters, False, board_pos=cell.pos))
|
||||||
|
return dict_tree.build_boggle_tree(board, cell, sub_tree)
|
||||||
|
|
||||||
|
def build_full_boggle_tree(board: BoggleBoard, wordlist_path: str) -> dict[str, WordTree]:
|
||||||
|
'''Return dictionary of WordTree(s) for every letter on a BoggleBoard'''
|
||||||
|
alphabet = sorted(set([cell.letters for cell in board.board.values()]))
|
||||||
|
board_tree = {}
|
||||||
|
index = {}
|
||||||
|
|
||||||
|
print("Reading in wordlists...")
|
||||||
|
for letters in alphabet:
|
||||||
|
if letters[0] in index:
|
||||||
|
index[letters] = index[letters[0]]
|
||||||
|
continue
|
||||||
|
|
||||||
|
filename = "words_" + letters[0] + ".txt"
|
||||||
|
print(f">> {letters}: {filename}")
|
||||||
|
wordlist = read_wordlist(path.join(path.abspath(wordlist_path), filename))
|
||||||
|
index[letters] = wordlist
|
||||||
|
|
||||||
|
print("Generating WordTrees...")
|
||||||
|
params = [ [alphabet, board, cell, index[cell.letters] ] for cell in board.board.values()]
|
||||||
|
with Pool(processes=len(board.board)) as pool:
|
||||||
|
for i, res in enumerate(pool.map(build_boggle_tree, params)):
|
||||||
|
print(f">> {params[i][2]}")
|
||||||
|
board_tree[params[i][2].pos] = res
|
||||||
|
|
||||||
|
return board_tree
|
||||||
|
|
||||||
|
def read_wordlist(file):
|
||||||
|
'''Return dictionary of words with associated word count (1 by default)'''
|
||||||
|
with open(file, 'r', encoding='utf-8') as file:
|
||||||
|
return {k:1 for k in file.read().split()}
|
||||||
|
|
||||||
|
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()]
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Listed alphabetically
|
||||||
|
a,a,a,e,e,g
|
||||||
|
a,b,b,j,o,o
|
||||||
|
a,c,h,o,p,s
|
||||||
|
a,f,f,k,p,s
|
||||||
|
a,o,o,t,t,w
|
||||||
|
c,i,m,o,t,u
|
||||||
|
d,e,i,l,r,x
|
||||||
|
d,e,l,r,v,y
|
||||||
|
d,i,s,t,t,y
|
||||||
|
e,e,g,h,n,w
|
||||||
|
e,e,i,n,s,u
|
||||||
|
e,h,r,t,v,w
|
||||||
|
e,i,o,s,s,t
|
||||||
|
e,l,r,t,t,y
|
||||||
|
h,i,m,n,qu,u
|
||||||
|
h,l,n,n,r,z
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
# Listed alphabetically
|
||||||
|
a,a,c,i,o,t
|
||||||
|
a,b,i,l,t,y
|
||||||
|
a,b,j,m,o,qu
|
||||||
|
a,c,d,e,m,p
|
||||||
|
a,c,e,l,r,s
|
||||||
|
a,d,e,n,v,z
|
||||||
|
a,h,m,o,r,s
|
||||||
|
b,i,f,o,r,x
|
||||||
|
d,e,n,o,s,w
|
||||||
|
d,k,n,o,t,u
|
||||||
|
e,e,f,h,i,y
|
||||||
|
e,g,k,l,u,y
|
||||||
|
e,g,i,n,t,v
|
||||||
|
e,h,i,n,p,s
|
||||||
|
e,l,p,s,t,u
|
||||||
|
g,i,l,r,u,w
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
# Listed alphabetically
|
||||||
|
_,_,_,e,i,o
|
||||||
|
a,a,a,f,r,s
|
||||||
|
a,a,e,e,e,e
|
||||||
|
a,a,e,e,o,o
|
||||||
|
a,a,f,i,r,s
|
||||||
|
a,b,d,e,i,o
|
||||||
|
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,e,i,l,m,n
|
||||||
|
a,e,i,n,o,u
|
||||||
|
a,f,i,r,s,y
|
||||||
|
an,er,he,in,qu,th
|
||||||
|
b,b,b,j,j,z
|
||||||
|
c,c,e,n,s,t
|
||||||
|
c,d,d,l,n,n
|
||||||
|
c,e,e,i,t,t
|
||||||
|
c,e,i,p,s,t
|
||||||
|
c,f,g,n,u,w
|
||||||
|
d,d,h,n,o,t
|
||||||
|
d,h,h,l,o,r
|
||||||
|
d,h,h,n,o,w
|
||||||
|
d,h,l,n,o,r
|
||||||
|
e,h,i,l,r,s
|
||||||
|
e,i,i,l,s,t
|
||||||
|
e,i,l,p,s,t
|
||||||
|
e,m,o,t,t,t
|
||||||
|
e,n,s,s,s,u
|
||||||
|
g,o,r,r,v,w
|
||||||
|
h,i,r,s,t,v
|
||||||
|
h,o,p,r,s,t
|
||||||
|
i,p,r,s,y,y
|
||||||
|
j,k,qu,w,x,z
|
||||||
|
n,o,o,t,u,w
|
||||||
|
o,o,o,t,t,u
|
||||||
|
@@ -30,5 +30,6 @@ else
|
|||||||
grep -P "^x" $1 > "$2/words_x.txt"
|
grep -P "^x" $1 > "$2/words_x.txt"
|
||||||
grep -P "^y" $1 > "$2/words_y.txt"
|
grep -P "^y" $1 > "$2/words_y.txt"
|
||||||
grep -P "^z" $1 > "$2/words_z.txt"
|
grep -P "^z" $1 > "$2/words_z.txt"
|
||||||
|
grep -P "^_" $1 > "$2/words__.txt"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user