Title: | Generate Wordsearch and Crossword Puzzles |
---|---|
Description: | Generate wordsearch and crossword puzzles using custom lists of words (and clues). Make them easy or hard, and print them to solve offline with paper and pencil! |
Authors: | Anthony Pileggi [aut, cre, cph], Shannon Pileggi [aut] |
Maintainer: | Anthony Pileggi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-10-29 04:01:41 UTC |
Source: | https://github.com/anthonypileggi/worrrd |
Add a word to a word matrix
add_word(x, word = "finding", must_intersect = FALSE, shape_matrix = NULL)
add_word(x, word = "finding", must_intersect = FALSE, shape_matrix = NULL)
x |
word matrix |
word |
the word to add (character/scalar) |
must_intersect |
force the added word to intersect with >1 word (logical/scalar) |
shape_matrix |
a binary matrix generated from a call to |
word matrix with word added (if possible)
Assign an object to the 'crossword' class
as_crossword(x)
as_crossword(x)
x |
an object containing crossword data |
crossword object: a matrix reprepresentation of the crossword, with attributes: positions: tibble representation of crossword clues: tibble representation of clue start (i.e., clue number locations)
Assign an object to the 'wordsearch' class
as_wordsearch(x)
as_wordsearch(x)
x |
an object containing wordsearch data |
wordsearch object: a list with the following elements:
search: a matrix representation of the wordsearch with 'positions' attribute a tibble representation of the solution words: (character/vector) clues: (character/vector) solution: a matrix representation of the wordsearch solution with 'positions' attribute a tibble representation of the solution image: image for shaping wordsearch (NULL if not provided) shape_matrix: binary matrix representation of shape (NULL if no image)
Create a puzzle book
book( input_file = system.file("book.yml", package = "worrrd"), output_file = "book.pdf", solutions = TRUE )
book( input_file = system.file("book.yml", package = "worrrd"), output_file = "book.pdf", solutions = TRUE )
input_file |
yaml file containing book details/contents |
output_file |
full path to output file (with .pdf extension) |
solutions |
include solutions (logical/scalar) |
full path to the created puzzle book
# Create demo book included with package book(output_file = "demo.pdf") unlink("demo.pdf")
# Create demo book included with package book(output_file = "demo.pdf") unlink("demo.pdf")
Create a crossword puzzle
crossword(words, clues, r = 50, c = 50, method = c("optimal", "random"))
crossword(words, clues, r = 50, c = 50, method = c("optimal", "random"))
words |
a vector of words (character/vector) |
clues |
a vector a clues (character/vector) |
r |
number of rows (numeric/scalar) |
c |
number of columns (numeric/scalar) |
method |
generate puzzle using 'optimal' or 'random' word order, where the optimal order will place words with the most overlap first |
crossword object
# Example 1 ---- words <- c("apple", "pear", "banana") clues <- c("red fruit", "bartlett", "green then yellow") x <- crossword(words, clues) plot(x, solution = TRUE) # Example 2 --- dat <- dplyr::tribble( ~word, ~clue, "dog", "Bark. Bark. Bark.", "cat", "Purrr", "horse", "Neighhhhh", "frog", "Ribbit Ribbit", "cow", "Moooooooo", "fox", "Nee Nee Nee (What does the ____ say?)", "sheep", "Bleat", "snake", "Hissss", "duck", "Quack", "bird", "Chirp" ) ex2 <- crossword(words = dat$word, clues = dat$clue, r = 40, c = 40) plot(ex2, solution = TRUE, clues = TRUE)
# Example 1 ---- words <- c("apple", "pear", "banana") clues <- c("red fruit", "bartlett", "green then yellow") x <- crossword(words, clues) plot(x, solution = TRUE) # Example 2 --- dat <- dplyr::tribble( ~word, ~clue, "dog", "Bark. Bark. Bark.", "cat", "Purrr", "horse", "Neighhhhh", "frog", "Ribbit Ribbit", "cow", "Moooooooo", "fox", "Nee Nee Nee (What does the ____ say?)", "sheep", "Bleat", "snake", "Hissss", "duck", "Quack", "bird", "Chirp" ) ex2 <- crossword(words = dat$word, clues = dat$clue, r = 40, c = 40) plot(ex2, solution = TRUE, clues = TRUE)
Convert an image to a 0/1 matrix
image_matrix( img = "https://upload.wikimedia.org/wikipedia/commons/9/96/Tux_Paint_banana.svg", rows = 10, columns = 10 )
image_matrix( img = "https://upload.wikimedia.org/wikipedia/commons/9/96/Tux_Paint_banana.svg", rows = 10, columns = 10 )
img |
full path to image (character/scalar) |
rows |
number of rows (numeric/scalar) |
columns |
number of columns (numeric/scalar) |
Check if an object is of the 'crossword' class
is_crossword(x)
is_crossword(x)
x |
an R object to check |
logical/scalar
Check if an object is of the 'wordsearch' class
is_wordsearch(x)
is_wordsearch(x)
x |
an R object to check |
logical/scalar
Compute maximum word size, based on the current word matrix
max_word_size(x, shape_matrix = NULL)
max_word_size(x, shape_matrix = NULL)
x |
word_search matrix |
shape_matrix |
shape matrix (logical) of identical size to 'x' |
Plot a crossword puzzle
## S3 method for class 'crossword' plot( x, solution = FALSE, clues = FALSE, title = "Crossword Puzzle", legend_size = 4, ... )
## S3 method for class 'crossword' plot( x, solution = FALSE, clues = FALSE, title = "Crossword Puzzle", legend_size = 4, ... )
x |
a crossword object (see |
solution |
show solution? (logical/scalar) |
clues |
show clues? (logical/scalar) |
title |
puzzle title (character/scalar) |
legend_size |
letter size of word list; set to NULL to auto-size (numeric/scalar) |
... |
additional printing args |
ggplot2 object
Draw a wordsearch puzzle
## S3 method for class 'wordsearch' plot( x, solution = FALSE, clues = TRUE, title = "", puzzle_size = NULL, legend_size = NULL, ... )
## S3 method for class 'wordsearch' plot( x, solution = FALSE, clues = TRUE, title = "", puzzle_size = NULL, legend_size = NULL, ... )
x |
wordsearch object (class: wordsearch) |
solution |
show solution? (logical/scalar) |
clues |
show clues? (logical/scalar) |
title |
puzzle title (character/scalar) |
puzzle_size |
letter size of puzzle; ignore to auto-size (numeric/scalar) |
legend_size |
letter size of word list; set to NULL to auto-size (numeric/scalar) |
... |
additional plotting args |
ggplot object
Prepare a word(s)
prepare_words(x)
prepare_words(x)
x |
word list (character/vector) |
Print a crossword puzzle
## S3 method for class 'crossword' print(x, ...)
## S3 method for class 'crossword' print(x, ...)
x |
a crossword object (see |
... |
additional printing args |
crossword object
Print details for a wordsearch puzzle
## S3 method for class 'wordsearch' print(x, ...)
## S3 method for class 'wordsearch' print(x, ...)
x |
wordsearch object (class: wordsearch) |
... |
additional printing args |
wordsearch object
Prepare a worrrd object for printing
printable(x, filename = "plot.pdf")
printable(x, filename = "plot.pdf")
x |
ggplot object |
filename |
name of file |
filename of pdf puzzle
words <- c("dog", "cat", "horse", "frog", "cow", "fox") ex1 <- wordsearch(words, r = 10, c = 10) my_puzzle <- plot(ex1, solution = FALSE) printable(my_puzzle, "my_wordsearch.pdf") unlink("my_wordsearch.pdf")
words <- c("dog", "cat", "horse", "frog", "cow", "fox") ex1 <- wordsearch(words, r = 10, c = 10) my_puzzle <- plot(ex1, solution = FALSE) printable(my_puzzle, "my_wordsearch.pdf") unlink("my_wordsearch.pdf")
Get possible intersection points based on the current board and a provided word
word_intersections(x, word = "needles")
word_intersections(x, word = "needles")
x |
word matrix |
word |
the word to add (character/scalar) |
for each direction, a matrix of crossing-point counts
Compute overlap score for a vector of words
word_overlap(words)
word_overlap(words)
words |
vector of words (character/vector) |
Create a wordsearch puzzle
wordsearch( words = c("finding", "needles", "inside", "haystacks"), clues = words, r = 10, c = 10, image = NULL )
wordsearch( words = c("finding", "needles", "inside", "haystacks"), clues = words, r = 10, c = 10, image = NULL )
words |
a vector of hidden words (character/vector) |
clues |
a vector of word clues (optional; character/vector) |
r |
number of rows |
c |
number of columns |
image |
path to an image that the resulting grid should look like.NULL for no shape |
wordsearch object
# Example 1 ---- words <- c("dog", "cat", "horse", "frog", "cow", "fox") ex1 <- wordsearch(words, r = 10, c = 10) plot(ex1, solution = TRUE) # Example 2 ---- clues <- c("Bark", "Meow", "Neigh", "Ribbit", "Moo", "Nee Nee Nee") ex2 <- wordsearch(words = words, clues = clues) plot(ex2, solution = TRUE, title = "Animal Sounds", legend_size = 4) # Example 3 ---- math <- dplyr::tribble( ~problem, ~solution, "2 + 2", "four", "5 + 3", "eight", "9 - 4", "five", "1 + 0", "one", "2 + 1", "three", "5 + 5", "ten", "6 - 6", "zero" ) ex3 <- wordsearch(words = math$solution, clues = math$problem) plot(ex3, solution = TRUE, title = "Math is Fun")
# Example 1 ---- words <- c("dog", "cat", "horse", "frog", "cow", "fox") ex1 <- wordsearch(words, r = 10, c = 10) plot(ex1, solution = TRUE) # Example 2 ---- clues <- c("Bark", "Meow", "Neigh", "Ribbit", "Moo", "Nee Nee Nee") ex2 <- wordsearch(words = words, clues = clues) plot(ex2, solution = TRUE, title = "Animal Sounds", legend_size = 4) # Example 3 ---- math <- dplyr::tribble( ~problem, ~solution, "2 + 2", "four", "5 + 3", "eight", "9 - 4", "five", "1 + 0", "one", "2 + 1", "three", "5 + 5", "ten", "6 - 6", "zero" ) ex3 <- wordsearch(words = math$solution, clues = math$problem) plot(ex3, solution = TRUE, title = "Math is Fun")