Giter Club home page Giter Club logo

Comments (5)

joshbduncan avatar joshbduncan commented on June 20, 2024

Sure, that would be pretty easy to do. I'll get an update out today or tomorrow.

from word-search-generator.

joshbduncan avatar joshbduncan commented on June 20, 2024

Ok, in version 3.5.0 that was just released, the save() method now honors the solution=True argument for CSV and JSON file types. Previously, it only honored that argument for PDF files. When called with a CSV or JSON file, the saved file will only include the characters from the placed puzzle words. Example output below... Let me know if this helps. Cheers!

So using your example above...

p = WordSearch("cat, bat, rat")
p.save(path="puzzle-solution.csv", format="csv", solution=True))

...would output a CSV file like:

WORD SEARCH
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , , , , , , ,C, , , 
 , , , , , , , , , , ,A, , 
 , , , , , , , , , , , ,T, 
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , ,B,A,T, , , ,R,A,T
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
 , , , , , , , , , , , , , 
""
Word List:
BAT,CAT,RAT
"* Words can go S, NE, SE, and, E."
""
Answer Key: 
"BAT E @ (6, 9)","CAT SE @ (11, 4)","RAT E @ (12, 9)"

...and...

p.save(path="puzzle-solution.json", format="json", solution=True))

...would output as JSON file like:

{
   "puzzle": [
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "C", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "A", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "T", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", "B", "A", "T", " ", " ", " ", "R", "A", "T"],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
      [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]
   ],
   "words": ["CAT", "RAT", "BAT"],
   "key": {
      "CAT": {"start_row": 3, "start_col": 10, "direction": "SE", "secret": false},
      "RAT": {"start_row": 8, "start_col": 11, "direction": "E", "secret": false},
      "BAT": {"start_row": 8, "start_col": 5, "direction": "E", "secret": false}
   }
}

from word-search-generator.

nicolesimon13 avatar nicolesimon13 commented on June 20, 2024

Question - is there a variable / array to access that during the script run?
puzzle.puzzle has the filler letters in them.

from word-search-generator.

joshbduncan avatar joshbduncan commented on June 20, 2024

Not directly. The puzzle always has the filler characters in place as they are filled in every time the puzzle is populated with words. There is a function in _formatter.py in the word_search that does the work of removing the filler characters.

It is a pretty simple function that check to see if every puzzle spot is part of a word and if not, changes it to an empty space.

def hide_filler_characters(game: WordSearch) -> Puzzle:
    """Remove filler characters from a puzzle."""
    output: Puzzle = copy.deepcopy(game.puzzle)
    word_coords = {
        coord
        for coords in [word.coordinates for word in game.placed_words]
        for coord in coords
    }
    for row in range(game.size):
        for col in range(game.size):
            if (col, row) not in word_coords:
                output[col][row] = " "
    return output

from word-search-generator.

joshbduncan avatar joshbduncan commented on June 20, 2024

@nicolesimon13, the latest version (in the 'cli-pretty' branch) has the hide_fillers argument in the show method to allow printing the puzzle without the filler characters. This will be merged soon.

from word-search-generator.

Related Issues (20)

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.