Skip to content

Extract common rendering logic from puzzle solvers into helper functions - #188

Draft
semiexp with Copilot wants to merge 4 commits into
mainfrom
copilot/factor-out-common-logic
Draft

Extract common rendering logic from puzzle solvers into helper functions#188
semiexp with Copilot wants to merge 4 commits into
mainfrom
copilot/factor-out-common-logic

Conversation

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Identified and extracted two common rendering patterns (15+ lines, 5+ files) from puzzle solver implementations.

Changes

New helpers in board.rs:

  • add_grid_edges() - renders edge-based puzzles (Slitherlink, Litherslink, Crosswall)
  • add_block_dot_answer() - renders boolean answer grids (Norinori, LITS, Cocktail, etc.)

Refactored files: 16 total

  • 3 files using edge grid pattern (24 lines → 1 line each)
  • 13 files using block/dot pattern (16 lines → 1 line each)

Example

Before:

if let Some(is_black) = &ans {
    for y in 0..height {
        for x in 0..width {
            if let Some(b) = is_black[y][x] {
                board.push(Item::cell(
                    y, x, "green",
                    if b { ItemKind::Block } else { ItemKind::Dot },
                ));
            }
        }
    }
}

After:

if let Some(is_black) = &ans {
    board.add_block_dot_answer(is_black, "green");
}

Net: -264 lines of duplicated code

Original prompt

In cspuz_solver_backend/src/puzzle, several files may share a common logic. Identify such logics and factor out them into a helper function.
Criteria: 15 lines or more of common logic, used in 5 or more files
Do not modify test expectations.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 30, 2026 11:08
Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com>
Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com>
Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor common logic into helper function Extract common rendering logic from puzzle solvers into helper functions Jan 30, 2026
Copilot AI requested a review from semiexp January 30, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants