Giter VIP home page Giter VIP logo

pysuchsel's Introduction

pysuchsel

pysuchsel is a program to create "Suchsel" word puzzles (i.e., a rectangular array of letters which have words hidden within that you need to find, aka "word search"). It can also create crossword puzzles. For both, from a given word list, grid size and filling rules, it creates an SVG image that can easily printed.

For Suchsels, it can fill all the void spaces with random letters that are uniformly distributed or it can choose a random distribution that satisfies a natural language (German and English are supported), making the Suchsel much more difficult. It also supports hiding words left-to-right, right-to-left, top-to-bottom, bottom-to-top, diagonally-to-top-right, diagonally-to-top-left, diagonally-to-bottom-right, diagonally-to-bottom-left or any combination of these placements.

For crossword puzzles, it takes care there is not adjacent cells filled, it enumerates the words and creates number fields in the resulting SVG.

Usage

You'll first have to create a file that contains all the words (e.g., using pluma or vim). We'll call it words.txt

$ cat words.txt
SUCHSEL
PADDELFISCH

Our file only contains two words. Then, you can already call pysuchsel to place them:

$ ./pysuchsel words.txt my_first_suchsel.svg

If you want to see where they were placed, specify "-v" as well:

$ ./pysuchsel -v words.txt my_first_suchsel.svg
+--------------------------------+
|                                |
|                                |
|                                |
|                                |
|       P A D D E L F I S C H    |
|                       U        |
|                       C        |
|                       H        |
|                       S        |
|                       E        |
|                       L        |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
+--------------------------------+

You can influence the size with the "-x" and "-y" options:

$ ./pysuchsel -x 11 -y 11 -v words.txt my_first_suchsel.svg
+------------------------+
| P                      |
| A                      |
| D                      |
| D                      |
| E                      |
| L                      |
| F                      |
| I       S U C H S E L  |
| S                      |
| C                      |
| H                      |
+------------------------+

You can also specify that you'd like words to share letters, which is then going to be the preference:

$ ./pysuchsel -c -x 11 -y 11 -v words.txt my_first_suchsel.svg
+------------------------+
|                   P    |
|                   A    |
|                   D    |
|                   D    |
|         S U C H S E L  |
|                   L    |
|                   F    |
|                   I    |
|                   S    |
|                   C    |
|                   H    |
+------------------------+

When you specify "--verbose" twice, it'll also show how the padded Suchsel looks like on the command line:

$ ./pysuchsel -c -x 11 -y 11 -vv words.txt my_first_suchsel.svg
+------------------------+
|                        |
|                        |
|                        |
|                        |
|         S              |
|         U              |
|         C              |
|         H              |
|         S              |
| P A D D E L F I S C H  |
|         L              |
+------------------------+
+------------------------+
| V C V P A B M O Z C K  |
| G I M S T X M U S P D  |
| T C P W H X W N E D L  |
| A S B L H T J U K V Q  |
| E L C M S U R T C W Z  |
| Z M J C U Y G K Y Q D  |
| J C Z E C B I X K J V  |
| U T Q E H K Y A F R P  |
| H R F A S K K N K V L  |
| P A D D E L F I S C H  |
| O N D N L E T A H T V  |
+------------------------+

To specify placement, use the "-p" command line option. For example, to only create diagonal placement to the bottom right, do:

$ ./pysuchsel -x 11 -y 11 -p dbr -v words.txt my_first_suchsel.svg
+------------------------+
| P     S                |
|   A     U              |
|     D     C            |
|       D     H          |
|         E     S        |
|           L     E      |
|             F     L    |
|               I        |
|                 S      |
|                   C    |
|                     H  |
+------------------------+

To allow more than one placement method, specify them all. For example, only allow top-to-bottom and bottom-to-top:

$ ./pysuchsel -x 11 -y 11 -p tb -p bt -v words.txt my_first_suchsel.svg
+------------------------+
|         S       H      |
|         U       C      |
|         C       S      |
|         H       I      |
|         S       F      |
|         E       L      |
|         L       E      |
|                 D      |
|                 D      |
|                 A      |
|                 P      |
+------------------------+

To influence the padding of letters, look at the "-d" option. By default, padded letters are uniformly distributed (i.e., each letter has the same probability of occurrence). That makes uncommon letters (e.g., Q and Y in the German language) rather frequent and stand out. For example:

$ ./pysuchsel -x 5 -y 11 -vv words.txt my_first_suchsel.svg
+------------+
| P          |
| A          |
| D          |
| D S        |
| E U        |
| L C        |
| F H        |
| I S        |
| S E        |
| C L        |
| H          |
+------------+
+------------+
| P L I B Q  |
| A H J E D  |
| D O H F Q  |
| D S L B G  |
| E U C K L  |
| L C J I I  |
| F H O K I  |
| I S S G A  |
| S E D X X  |
| C L K E K  |
| H S I L Q  |
+------------+

Compare that to:

$ ./pysuchsel -x 5 -y 11 -d natlang-de -vv words.txt my_first_suchsel.svg
+------------+
|   P        |
|   A        |
|   D        |
|   D        |
|   E   S    |
|   L   U    |
|   F   C    |
|   I   H    |
|   S   S    |
|   C   E    |
|   H   L    |
+------------+
+------------+
| D P C W D  |
| R A S L F  |
| S D T U E  |
| Z D V N C  |
| S E H S K  |
| I L N U N  |
| W F K C S  |
| G I N H H  |
| A S N S T  |
| G C T E N  |
| N H U L E  |
+------------+

This is how a PNG rendering then looks like:

Paddelfisch Suchsel

For crossword mode, you can specify the "--mode=crossword" option. Let's say we add a few more words to our list:

$ cat words.txt
SUCHSEL
PADDELFISCH
KREUZWORT
FLUGZEUG
XYLOPHON

Then, try to create a crossword:

$ ./pysuchsel -v --mode=crossword words.txt my_first_crossword.svg
Warning: could not place word "FLUGZEUG".
Warning: could not place word "KREUZWORT".
 1: PADDELFISCH
 2: SUCHSEL
 3: XYLOPHON
+--------------------------------+
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|             v                  |
|             P                  |
|             A                  |
|             D     v            |
|             D     X            |
|             E     Y            |
|             L     L            |
|             F     O            |
|             I     P            |
|           > S U C H S E L .    |
|             C     O            |
|             H     N            |
|             .     .            |
|                                |
+--------------------------------+

You'll notice that it was not possible to place all words. You can ask pysuchsel to re-attempt until it finds a solution that places all words by specifying the "-a" (or --creation-attempts) parameter:

$ ./pysuchsel -v --mode=crossword -a 50 words.txt my_first_crossword.svg
 1: KREUZWORT
 2: XYLOPHON
 3: PADDELFISCH
 4: SUCHSEL
 5: FLUGZEUG
+--------------------------------+
|                                |
|                                |
|                                |
|                                |
|                         v      |
|               v         S      |
|               X         U      |
|               Y         C      |
|   > P A D D E L F I S C H .    |
|         v     O         S      |
|         F     P         E      |
|         L     H         L      |
| > K R E U Z W O R T .   .      |
|         G     N                |
|         Z     .                |
|         E                      |
|         U                      |
|         G                      |
|         .                      |
|                                |
+--------------------------------+

Create a puzzle using all placement rules

./pysuchsel -x 18 -y 18 --placement={lr,tb,rl,bt,dbr,dtr,dbl,dtl} dictio.txt out.svg

The rendering of this now looks like this:

Paddelfisch Crossword

Note that you can also specify the "--empty" parameter if you don't want the letters to be filled into the SVG.

License

GNU-GPL 3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.