-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add `as_single()` for all sets - Do not add empty `Action` to `Effects`
- Loading branch information
Showing
9 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,67 @@ | ||
use super::*; | ||
|
||
pub fn find_xyz_wings(board: &Board) -> Option<Effects> { | ||
let mut effects = Effects::new(); | ||
|
||
// for each tri-value cell | ||
// peers = bi-value cells & cell peers | ||
// for each pair of peers | ||
// if count of cells that see all three cells is not 2 | ||
// degenerate naked triple (continue) | ||
// if union of peer candidates is not cell candidates | ||
// continue | ||
// found xyz-wing | ||
|
||
let mut log = false; | ||
|
||
let tri_values = board.cells_with_n_candidates(3); | ||
if tri_values.is_empty() { | ||
return None; | ||
} | ||
let bi_values = board.cells_with_n_candidates(2); | ||
if bi_values.is_empty() { | ||
return None; | ||
} | ||
|
||
tri_values.iter().for_each(|cell| { | ||
// let (k1, k2) = board.candidates(cell).as_pair().unwrap(); | ||
(cell.peers() & bi_values) | ||
.iter() | ||
.combinations(2) | ||
.map(|pair| pair.iter().copied().union() as CellSet) | ||
.for_each(|pair| { | ||
let (c1, c2) = pair.as_pair().expect("cell pair"); | ||
let candidates = cell.peers() & c1.peers() & c2.peers(); | ||
if candidates.size() != 2 { | ||
// degenerate naked triple | ||
return; | ||
} | ||
|
||
let ks = board.candidates(cell); | ||
let ks1 = board.candidates(c1); | ||
let ks2 = board.candidates(c2); | ||
if ks1 | ks2 != ks { | ||
// degenerate naked pair or totally unrelated candidates | ||
return; | ||
} | ||
|
||
let k = (ks1 & ks2).as_single().expect("one candidate in common"); | ||
if log { | ||
println!( | ||
"{}-{}: {}-{} {}-{} - {}", | ||
cell, ks, c1, ks1, c2, ks2, candidates | ||
) | ||
} | ||
|
||
let mut action = Action::new(Strategy::XYZWing); | ||
action.erase_cells(candidates & board.candidate_cells(k), k); | ||
effects.add_action(action); | ||
}); | ||
}); | ||
|
||
if effects.has_actions() { | ||
Some(effects) | ||
} else { | ||
None | ||
} | ||
} |