协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
validate-piles-notation【开发与工程】Parse and validate PILES (Puzzle Input Line Entry System) notation for specifying piece fusion groups in jigsawR. Covers syntax validation, parsing into group lists, plain-language explanation, adjacency verification against puzzle results, and round-trip serialization. Use when validating user-supplied PILES strings before passing to generate_puzzle…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Parse + validate PILES strings → puzzle piece fusion groups.
generate_puzzle()"1-2-3,4-5")"center", "ring1", "R1")library(jigsawR)
result <- validate_piles_syntax("1-2-3,4-5")
# Returns TRUE if valid, error message if invalid
Common syntax errs:
"1-2(-3)-4" w/ mismatched ()-, ,, :, (, ) + keywords"1-2,,3-4" (double comma)Got: TRUE for valid syntax, descriptive err for invalid.
If err: Print exact PILES string + valid err msg.
groups <- parse_piles("1-2-3,4-5")
# Returns: list(c(1, 2, 3), c(4, 5))
W/ ranges:
groups <- parse_piles("1:6,7-8")
# Returns: list(c(1, 2, 3, 4, 5, 6), c(7, 8))
Got: List of int vectors, one per fusion group, correct piece IDs + boundaries.
If err: Check syntax valid passed Step 1. Unexpected groups → verify - separates pieces in group, , separates groups, : expands inclusive endpoints.
Per group:
"1-2-3,4-5" → "Group 1: fuse pieces 1, 2, 3. Group 2: fuse 4, 5.""1:6" → "Group 1: fuse pieces 1 through 6 (6 pieces).""center,ring1" → "Group 1: center piece. Group 2: all pieces ring 1."Got: Each group described plain w/ piece counts + IDs → understandable to non-tech.
If err: Keywords can't be explained ("ring1" no clear meaning) → notation needs puzzle result for ctx. Advise user provide puzzle type or numeric IDs.
If puzzle result available, verify:
# Generate the puzzle first
puzzle <- generate_puzzle(type = "hexagonal", grid = c(3), size = c(200))
# Parse with puzzle context (resolves keywords)
groups <- parse_fusion("center,ring1", puzzle)
Check:
Got: All piece IDs valid. Adjacent pieces fuse cleanly.
If err: List invalid piece IDs or non-adjacent pairs.
Verify parse/serialize fidelity:
original <- "1-2-3,4-5"
groups <- parse_piles(original)
roundtrip <- to_piles(groups)
# roundtrip should equal original (or canonical equivalent)
groups2 <- parse_piles(roundtrip)
identical(groups, groups2) # Must be TRUE
Got: Round-trip → identical group lists, confirming parse_piles() + to_piles() are inverses.
If err: Round-trip differs → check serializer normalization (sorting IDs, ranges → explicit lists). Canonical diffs OK if identical(groups, groups2) returns TRUE.
# Basic syntax
"1-2" # Fuse pieces 1 and 2
"1-2-3,4-5" # Two groups: (1,2,3) and (4,5)
"1:6" # Range: pieces 1 through 6
# Keywords (require puzzle_result)
"center" # Center piece (hex/concentric)
"ring1" # All pieces in ring 1
"R1" # Row 1 (rectangular)
"boundary" # All boundary pieces
# Functions
parse_piles("1-2-3,4-5") # Parse PILES string
parse_fusion("1-2-3", puzzle) # Auto-detect format
to_piles(list(c(1,2), c(3,4))) # Convert to PILES
validate_piles_syntax("1-2(-3)-4") # Validate syntax
validate_piles_syntax() returns TRUE for valid stringsparse_piles() returns correct group lists"center" requires puzzle result. Pass to parse_fusion(), not parse_piles()."1:6" includes both endpoints (1, 2, 3, 4, 5, 6).generate-puzzle — generate puzzles w/ fusion groupsadd-puzzle-type — new types need PILES/fusion supportrun-puzzle-tests — test PILES parsing w/ full suite