sudoku_solver/solver/fish/
mod.rs

1mod fish_utils;
2mod franken_fish;
3mod mutant_fish;
4mod simple_fish;
5
6use crate::solver::return_if_some;
7use crate::sudoku::StepRule;
8use crate::{Step, SudokuSolver};
9
10// 鱼需要选取一个数字和两个集合:base set 和 cover set。集合中的元素都是 House,且集合内部的 House 不相互重叠。
11// 要形成鱼,base set 和 cover set 的大小需要相同。且 candidate 在 base set 中的出现位置必须被 cover set 覆盖。
12// 而基本的鱼是指 House 不包含 Block 的鱼,因此基本的鱼由 n 个 Row 和 n 个 Column 组成,且基础集所覆盖的单元格数量正好等于 n。
13pub fn solve_basic_fish(sudoku: &SudokuSolver) -> Option<Step> {
14    for size in 2..=4 {
15        for value in 1..=9 {
16            return_if_some!(simple_fish::search_simple_fish(
17                sudoku,
18                size,
19                value,
20                StepRule::BasicFish
21            ));
22        }
23    }
24    None
25}
26
27pub fn solve_finned_fish(sudoku: &SudokuSolver) -> Option<Step> {
28    for size in 2..=4 {
29        for value in 1..=9 {
30            return_if_some!(simple_fish::search_simple_fish(
31                sudoku,
32                size,
33                value,
34                StepRule::FinnedFish
35            ));
36        }
37    }
38    None
39}
40
41pub fn solve_franken_fish(sudoku: &SudokuSolver) -> Option<Step> {
42    // Every Franken X-Wing is degenerate to a finned X-Wing.
43    for size in 3..=4 {
44        for value in 1..=9 {
45            return_if_some!(franken_fish::search_franken_fish(sudoku, size, value));
46        }
47    }
48    None
49}
50
51pub fn solve_mutant_fish(sudoku: &SudokuSolver) -> Option<Step> {
52    for size in 3..=4 {
53        for value in 1..=9 {
54            return_if_some!(mutant_fish::search_mutant_fish(sudoku, size, value));
55        }
56    }
57    None
58}