Skip to contents

read_puzzles() reads puzzle definitions from a YAML file, defaulting to the puzzles bundled with this package.

Usage

read_puzzles(
  file = system.file("puzzles.yaml", package = "figurenumbers", mustWork = TRUE)
)

Arguments

file

Path to a YAML file of puzzle definitions.

Value

A list of puzzles named by their labels (each puzzle a list with at least label, segments, and hash elements).

Details

Each puzzle is a list with a label (human-readable name, which may spoil the picture; restricted to ASCII alphanumerics plus _ and . starting with a letter, since it is also used as the puzzle's name in the returned list where such names are convenient to use), segments (a list of point sequences suitable for passing straight to puzzleGrob(): the first is the hidden picture the math problems are generated from and any later ones are pre-drawn in the number grid), and credits (image source attribution, if any). More fields may be added later.

read_puzzles() additionally adds a hash element to each puzzle (a short digest::digest() of its entire YAML entry, not stored in the file) which can be used to annotate a puzzle without spoiling the picture, e.g. to match a puzzle page to a solution/credits page.

Examples

puzzles <- read_puzzles()
names(puzzles)
#> [1] "letter_x" "rook"     "pawn"     "queen"    "club"    
if (require("grid", quietly = TRUE)) {
    puzzle <- puzzles$letter_x
    grid.newpage()
    grid.draw(puzzleGrob(puzzle$segments, seed = 42, hash = puzzle$hash))
}