Back to Skills

generate-puzzle

pjt222
Updated 2 days ago
2 views
17
2
17
View on GitHub
Metawordaitestingdesign

About

This skill generates jigsaw puzzle SVGs in R via `generate_puzzle()` or `geom_puzzle_*()` functions, supporting multiple puzzle types like rectangular, hexagonal, and voronoi. It validates parameters against a config file and is useful for creating SVG files, testing configurations, or building ggplot2 visualizations. Developers can use it to programmatically produce puzzles with controlled grid, size, seed, and layout settings.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/generate-puzzle

Copy and paste this command in Claude Code to install this skill

Documentation

Generate Puzzle

jigsawR unified API → generate puzzle.

Use When

  • Create puzzle SVG w/ type + config
  • Test generation w/ diff params
  • Sample out for docs/demos
  • ggplot2 puzzle viz w/ geom_puzzle_*()

In

  • Required: type ("rectangular", "hexagonal", "concentric", "voronoi", "random", "snic")
  • Required: grid (type-dep: c(cols, rows) or c(rings))
  • Optional: size mm (default varies)
  • Optional: seed (default 42)
  • Optional: offset (0=interlocked, >0=separated)
  • Optional: layout ("grid" or "repel" rect)
  • Optional: fusion groups (PILES string)

Do

Step 1: Read config constraints

R_EXE="/mnt/c/Program Files/R/R-4.5.0/bin/Rscript.exe"
"$R_EXE" -e "cat(yaml::yaml.load_file('inst/config.yml')[['{TYPE}']]$grid$max)"

Or read inst/config.yml direct → valid ranges for type.

→ min/max for grid, size, tabsize known for type.

If err: config.yml missing or type key missing → in jigsawR root? pkg built once?

Step 2: Determine type + params

TypegridsizeExtra params
rectangularc(cols, rows)c(width, height) mmoffset, layout, tabsize
hexagonalc(rings)c(diameter) mmdo_warp, do_trunc, tabsize
concentricc(rings)c(diameter) mmcenter_shape, tabsize
voronoic(cols, rows)c(width, height) mmn_interior, tabsize
randomc(cols, rows)c(width, height) mmn_interior, tabsize
snicc(cols, rows)c(width, height) mmn_interior, compactness, tabsize

→ Req mapped to generate_puzzle() args, values in config.yml range.

If err: unsure format → see table. Rect + voronoi → c(cols, rows); hex + concentric → c(rings).

Step 3: Create R script

Script file preferred over -e for complex cmds.

library(jigsawR)

result <- generate_puzzle(
  type = "rectangular",
  seed = 42,
  grid = c(3, 4),
  size = c(400, 300),
  offset = 0,
  layout = "grid"
)

cat("Pieces:", length(result$pieces), "\n")
cat("SVG length:", nchar(result$svg_content), "\n")
cat("Files:", paste(result$files, collapse = ", "), "\n")

Save to tmp script file.

→ R script saved w/ library(jigsawR) + call + diag output.

If err: syntax → verify string quoting + c() for num vectors. Use script files, avoid shell escape.

Step 4: Execute via WSL R

R_EXE="/mnt/c/Program Files/R/R-4.5.0/bin/Rscript.exe"
"$R_EXE" /path/to/script.R

→ Completes no errors. SVG → output/.

If err: check renv restored (renv::restore()). Pkg loaded (devtools::load_all()). NO --vanilla (renv needs .Rprofile).

Step 5: Verify out

  • SVG in output/
  • Starts <?xml or <svg
  • Piece count matches: cols × rows (rect), ring formula (hex/concentric)
  • ggplot2 → plot renders no err

→ SVG exists, content valid, piece count matches.

If err: SVG missing → check output/ exists. Count wrong → verify grid for type. ggplot2 → wrap tryCatch().

Step 6: Save out

Default → output/. result contains:

  • $svg_content — raw SVG string
  • $pieces — piece data list
  • $canvas_size — dims
  • $files — paths

result has $svg_content, $pieces, $canvas_size, $files. Files on disk.

If err: $files empty → in-memory only. Explicitly: writeLines(result$svg_content, "output/puzzle.svg").

Check

  • Script no err
  • SVG well-formed XML
  • Piece count matches grid
  • Same seed → identical out
  • Params in config.yml range

Traps

  • --vanilla: breaks renv. Never.
  • Complex -e: script files → shell escape → Exit 5.
  • Grid vs size: grid=piece count, size=physical mm.
  • Offset: 0=assembled, >0=exploded.
  • SNIC: needs snic pkg installed.

  • add-puzzle-type — scaffold new type E2E
  • validate-piles-notation — validate fusion strings pre-call
  • run-puzzle-tests — test suite after gen changes
  • write-testthat-tests — tests for new scenarios

GitHub Repository

pjt222/agent-almanac
Path: i18n/caveman-ultra/skills/generate-puzzle
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill