-
Notifications
You must be signed in to change notification settings - Fork 3
Fix #135: Add Minesweeper model #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
isPANN
wants to merge
6
commits into
main
Choose a base branch
from
issue-135-minesweeper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f1165f
Add plan for #135: [Model] Minesweeper
isPANN 943e2a7
Implement #135: Add Minesweeper Consistency model
isPANN 03d79cc
Fix review findings: config length guard, example integration test
isPANN 680c803
Strengthen constructor validation: overlap, count, duplicate checks
isPANN b303968
chore: remove plan file after implementation
isPANN da96540
fix: address Copilot review comments for Minesweeper model
GiggleLiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // # Minesweeper Consistency Check | ||
| // | ||
| // ## This Example | ||
| // - Instance: 3x3 grid with a classic pattern | ||
| // - Revealed cells: (0,0)=1, (1,0)=1, (1,1)=2, (2,0)=0, (2,1)=1 | ||
| // - Unrevealed cells: (0,1), (0,2), (1,2), (2,2) | ||
| // - Solution: mines at (0,1) and (1,2) | ||
|
|
||
| use problemreductions::models::misc::Minesweeper; | ||
| use problemreductions::solvers::{BruteForce, Solver}; | ||
| use problemreductions::traits::Problem; | ||
|
|
||
| pub fn run() { | ||
| println!("=== Minesweeper Consistency ===\n"); | ||
|
|
||
| // Grid layout: | ||
| // 1 ? ? | ||
| // 1 2 ? | ||
| // 0 1 ? | ||
| let problem = Minesweeper::new( | ||
| 3, | ||
| 3, | ||
| vec![(0, 0, 1), (1, 0, 1), (1, 1, 2), (2, 0, 0), (2, 1, 1)], | ||
| vec![(0, 1), (0, 2), (1, 2), (2, 2)], | ||
| ); | ||
|
|
||
| println!("Grid: {}x{}", problem.rows(), problem.cols()); | ||
| println!("Revealed cells: {:?}", problem.revealed()); | ||
| println!("Unrevealed cells: {:?}", problem.unrevealed()); | ||
| println!("Variables: {}\n", problem.num_variables()); | ||
|
|
||
| let solver = BruteForce::new(); | ||
| match solver.find_satisfying(&problem) { | ||
| Some(solution) => { | ||
| println!("Satisfying assignment found!"); | ||
| println!("Config: {:?}", solution); | ||
| println!("Verified: {}", problem.evaluate(&solution)); | ||
|
|
||
| // Show mine placement | ||
| println!("\nMine placement:"); | ||
| for (i, &(r, c)) in problem.unrevealed().iter().enumerate() { | ||
| if solution[i] == 1 { | ||
| println!(" Mine at ({}, {})", r, c); | ||
| } | ||
| } | ||
| } | ||
| None => { | ||
| println!("No satisfying assignment exists (inconsistent grid)."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| run() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI
createpath relies onMinesweeper::new()assertions for validation (bounds, duplicates, overlaps, count<=8). If a user passes invalid--revealedcoordinates or duplicates, the CLI will panic instead of returning a structured error. Prefer validatingrevealedin the CLI (bounds check againstrows/cols, duplicate positions) and returning abail!(...)/anyhow!(...)error before callingMinesweeper::new().