generate-puzzle
Generate jigsaw puzzles via generate_puzzle() or geom_puzzle_*() with parameter validation against inst/config.yml. Supports rectangular, hexagonal, concentric, voronoi, and snic puzzle types with configurable grid, size, seed, offset, and layout parameters. Use when creating puzzle SVG files for a specific type and configuration, testing generation with different parameters, generating sample output for documentation or demos, or creating ggplot2 puzzle visualizations.
Best use case
generate-puzzle is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Generate jigsaw puzzles via generate_puzzle() or geom_puzzle_*() with parameter validation against inst/config.yml. Supports rectangular, hexagonal, concentric, voronoi, and snic puzzle types with configurable grid, size, seed, offset, and layout parameters. Use when creating puzzle SVG files for a specific type and configuration, testing generation with different parameters, generating sample output for documentation or demos, or creating ggplot2 puzzle visualizations.
Teams using generate-puzzle should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/generate-puzzle/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How generate-puzzle Compares
| Feature / Agent | generate-puzzle | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Generate jigsaw puzzles via generate_puzzle() or geom_puzzle_*() with parameter validation against inst/config.yml. Supports rectangular, hexagonal, concentric, voronoi, and snic puzzle types with configurable grid, size, seed, offset, and layout parameters. Use when creating puzzle SVG files for a specific type and configuration, testing generation with different parameters, generating sample output for documentation or demos, or creating ggplot2 puzzle visualizations.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Generate Puzzle
Generate jigsaw puzzles using the jigsawR package's unified API.
## When to Use
- Creating puzzle SVG files for a specific type and configuration
- Testing puzzle generation with different parameters
- Generating sample output for documentation or demos
- Creating ggplot2 puzzle visualizations with geom_puzzle_*()
## Inputs
- **Required**: Puzzle type (`"rectangular"`, `"hexagonal"`, `"concentric"`, `"voronoi"`, `"random"`, `"snic"`)
- **Required**: Grid dimensions (type-dependent: `c(cols, rows)` or `c(rings)`)
- **Optional**: Size in mm (default varies by type)
- **Optional**: Seed for reproducibility (default: 42)
- **Optional**: Offset (0 = interlocked, >0 = separated pieces)
- **Optional**: Layout (`"grid"` or `"repel"` for rectangular)
- **Optional**: Fusion groups (PILES notation string)
## Procedure
### Step 1: Read Config Constraints
```bash
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` directly to check valid ranges for the chosen type.
**Got:** The min/max values for grid, size, tabsize, and other parameters are known for the chosen puzzle type.
**If fail:** If `config.yml` is missing or the type key doesn't exist, check that you are in the jigsawR project root and the package has been built at least once.
### Step 2: Determine Type and Parameters
Map the user's request to valid `generate_puzzle()` arguments:
| Type | grid | size | Extra params |
|------|------|------|-------------|
| rectangular | `c(cols, rows)` | `c(width, height)` mm | `offset`, `layout`, `tabsize` |
| hexagonal | `c(rings)` | `c(diameter)` mm | `do_warp`, `do_trunc`, `tabsize` |
| concentric | `c(rings)` | `c(diameter)` mm | `center_shape`, `tabsize` |
| voronoi | `c(cols, rows)` | `c(width, height)` mm | `n_interior`, `tabsize` |
| random | `c(cols, rows)` | `c(width, height)` mm | `n_interior`, `tabsize` |
| snic | `c(cols, rows)` | `c(width, height)` mm | `n_interior`, `compactness`, `tabsize` |
**Got:** User request mapped to valid `generate_puzzle()` arguments with correct `type`, `grid` dimensions, and `size` values within the ranges from config.yml.
**If fail:** If unsure which parameter format to use, refer to the table above. Rectangular and voronoi types use `c(cols, rows)` for grid; hexagonal and concentric use `c(rings)`.
### Step 3: Create R Script
Write a script file (preferred over `-e` for complex commands):
```r
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 a temporary script file.
**Got:** An R script file saved to a temporary location containing `library(jigsawR)`, a `generate_puzzle()` call with all parameters, and diagnostic output lines.
**If fail:** If the script has syntax errors, verify that all string arguments are quoted and numeric vectors use `c()`. Avoid complex shell escaping by always using script files.
### Step 4: Execute via WSL R
```bash
R_EXE="/mnt/c/Program Files/R/R-4.5.0/bin/Rscript.exe"
"$R_EXE" /path/to/script.R
```
**Got:** Script completes without errors. SVG file(s) written to `output/`.
**If fail:** Check that renv is restored (`renv::restore()`). Verify package is loaded (`devtools::load_all()`). Do NOT use `--vanilla` flag (renv needs .Rprofile).
### Step 5: Verify Output
- SVG file exists in `output/` directory
- SVG content starts with `<?xml` or `<svg`
- Piece count matches expected: cols * rows (rectangular), ring formula (hex/concentric)
- For ggplot2 approach, verify the plot object renders without error
**Got:** SVG file exists in `output/`, content starts with `<?xml` or `<svg`, and piece count matches the grid specification (cols * rows for rectangular, ring formula for hex/concentric).
**If fail:** If SVG file is missing, check the `output/` directory exists. If piece count is wrong, verify grid dimensions match the puzzle type's expected formula. For ggplot2 output, check that the plot renders without error by wrapping in `tryCatch()`.
### Step 6: Save Output
Generated files are saved to `output/` by default. The `result` object contains:
- `$svg_content` — raw SVG string
- `$pieces` — list of piece data
- `$canvas_size` — dimensions
- `$files` — paths to written files
**Got:** The `result` object contains `$svg_content`, `$pieces`, `$canvas_size`, and `$files` fields. Files listed in `$files` exist on disk.
**If fail:** If `$files` is empty, the puzzle may have generated in-memory only. Explicitly save with `writeLines(result$svg_content, "output/puzzle.svg")`.
## Validation
- [ ] Script executes without errors
- [ ] SVG file is well-formed XML
- [ ] Piece count matches grid specification
- [ ] Same seed produces identical output (reproducibility)
- [ ] Parameters are within config.yml constraints
## Pitfalls
- **Using `--vanilla` flag**: Breaks renv activation. Never use it.
- **Complex `-e` commands**: Use script files instead; shell escaping causes Exit code 5.
- **Grid vs size confusion**: Grid is piece count, size is physical dimensions in mm.
- **Offset semantics**: 0 = assembled puzzle, positive = exploded/separated pieces.
- **SNIC without package**: snic type requires the `snic` package installed.
## Related Skills
- `add-puzzle-type` — scaffold a new puzzle type end-to-end
- `validate-piles-notation` — validate fusion group strings before passing to generate_puzzle()
- `run-puzzle-tests` — run the test suite after generation changes
- `write-testthat-tests` — add tests for new generation scenariosRelated Skills
run-puzzle-tests
Run jigsawR test suite via WSL R. Supports full suite, filtered by pattern, or single file. Interprets pass/fail/skip counts and identifies failing tests. Never use `--vanilla` (renv needs `.Rprofile` to activate). Use after R source changes, after adding a puzzle type or feature, before commits, or when debugging a specific failure.
generate-workflow-diagram
Generate themed Mermaid flowchart diagrams from putior workflow data. Covers theme selection (9 themes including 4 colorblind-safe), output modes (console, file, clipboard, raw), interactive features (clickable nodes, source info), and embedding in README, Quarto, and R Markdown. Use after annotating source files and ready to produce a visual diagram, when regenerating a diagram after workflow changes, or when switching themes or output formats for different audiences.
generate-tour-report
Generate a Quarto-based tour report with embedded maps, daily itineraries, logistics tables, and accommodation/transport details. Produces a self-contained HTML or PDF document suitable for offline use during travel. Use when compiling a planned tour into a shareable document, creating an offline-accessible travel guide, documenting a completed trip with photos and statistics, or producing a professional tour proposal for a group or client.
generate-status-report
Generate a project status report by reading existing artifacts (charter, backlog, sprint plan, WBS), calculating metrics, identifying blockers, and summarizing progress with RAG indicators for schedule, scope, budget, and quality. Use at the end of a sprint or reporting period, when stakeholders request a health update, before steering committee or governance meetings, or when a new blocker or risk materializes mid-project.
generate-statistical-tables
Generate publication-ready statistical tables using gt, kableExtra, or flextable. Covers descriptive statistics, regression results, ANOVA tables, correlation matrices, and APA formatting. Use when creating descriptive statistics tables, formatting regression or ANOVA output, building correlation matrices, producing APA-style tables for academic papers, or generating tables for Quarto and R Markdown documents.
add-puzzle-type
Scaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely new puzzle type to the package or following the 10-point integration checklist to ensure nothing is missed end-to-end.
skill-name-here
One to three sentences describing what this skill accomplishes, followed by key activation triggers. This field is the primary mechanism agents use to decide whether to activate the skill — it is read during discovery before the full body is loaded. Start with a verb. Include the most important "when to use" conditions inline. Max 1024 characters.
write-vignette
Create R package vignettes using R Markdown or Quarto. Covers vignette setup, YAML configuration, code chunk options, building and testing, and CRAN requirements for vignettes. Use when adding a Getting Started tutorial, documenting complex workflows spanning multiple functions, creating domain-specific guides, or when CRAN submission requires user-facing documentation beyond function help pages.
write-validation-documentation
Write IQ/OQ/PQ validation documentation for computerized systems in regulated environments. Covers protocols, reports, test scripts, deviation handling, and approval workflows. Use when validating R or other software for regulated use, preparing for a regulatory audit, documenting qualification of computing environments, or creating and updating validation protocols and reports for new or re-qualified systems.
write-testthat-tests
Write comprehensive testthat (edition 3) tests for R package functions. Covers test organization, expectations, fixtures, mocking, snapshot tests, parameterized tests, and achieving high coverage. Use when adding tests for new package functions, increasing test coverage for existing code, writing regression tests for bug fixes, or setting up test infrastructure for a package that lacks it.
write-standard-operating-procedure
Write a GxP-compliant Standard Operating Procedure (SOP). Covers regulatory SOP template structure (purpose, scope, definitions, responsibilities, procedure, references, revision history), approval workflow design, periodic review scheduling, and operational procedures for system use. Use when a new validated system requires operational procedures, when existing informal procedures need formalisation, when an audit finding cites missing procedures, when a change control triggers SOP updates, or when periodic review identifies outdated procedural content.
write-roxygen-docs
Write roxygen2 documentation for R package functions, datasets, and classes. Covers all standard tags, cross-references, examples, and generating NAMESPACE entries. Follows tidyverse documentation style. Use when adding documentation to new exported functions, documenting internal helpers or datasets, documenting S3/S4/R6 classes and methods, or fixing documentation-related R CMD check notes.