pub(crate) mod prelude;
pub(crate) mod almost_locked_sets;
pub(crate) mod avoidable_rectangles;
pub(crate) mod basic_fish;
pub(crate) mod hidden_singles;
pub(crate) mod hidden_subsets;
pub(crate) mod locked_candidates;
pub(crate) mod mutant_fish;
pub(crate) mod naked_singles;
pub(crate) mod naked_subsets;
pub(crate) mod xy_wing;
pub(crate) mod xyz_wing;
use super::StrategySolver;
use crate::helper::Unsolvable;
#[non_exhaustive]
#[derive(Debug, Clone)]
#[allow(missing_docs)]
pub enum Strategy {
NakedSingles,
HiddenSingles,
LockedCandidates,
NakedPairs,
NakedTriples,
NakedQuads,
HiddenPairs,
HiddenTriples,
HiddenQuads,
XWing,
Swordfish,
Jellyfish,
XyWing,
XyzWing,
MutantSwordfish,
MutantJellyfish,
AvoidableRectangles,
}
impl Strategy {
#[allow(unused)]
#[rustfmt::skip]
pub(crate) const ALL: &'static [Strategy] = &[
Strategy::NakedSingles, Strategy::HiddenSingles, Strategy::LockedCandidates, Strategy::NakedPairs, Strategy::XWing, Strategy::HiddenPairs, Strategy::NakedTriples, Strategy::Swordfish, Strategy::HiddenTriples, Strategy::XyWing, Strategy::XyzWing, Strategy::NakedQuads, Strategy::Jellyfish, Strategy::HiddenQuads, ];
pub(crate) fn deduce(
&self,
state: &mut StrategySolver,
stop_after_first: bool,
is_first_strategy: bool,
) -> Result<(), Unsolvable> {
use self::Strategy::*;
match *self {
NakedSingles if !stop_after_first && is_first_strategy => {
state._update_cell_poss_house_solved(true, true)
}
NakedSingles => state.find_naked_singles(stop_after_first),
HiddenSingles => state.find_hidden_singles(stop_after_first),
LockedCandidates => state.find_locked_candidates(stop_after_first),
NakedPairs => state.find_naked_subsets(2, stop_after_first),
NakedTriples => state.find_naked_subsets(3, stop_after_first),
NakedQuads => state.find_naked_subsets(4, stop_after_first),
HiddenPairs => state.find_hidden_subsets(2, stop_after_first),
HiddenTriples => state.find_hidden_subsets(3, stop_after_first),
HiddenQuads => state.find_hidden_subsets(4, stop_after_first),
XWing => state.find_xwings(stop_after_first),
Swordfish => state.find_swordfish(stop_after_first),
Jellyfish => state.find_jellyfish(stop_after_first),
XyWing => state.find_xy_wing(stop_after_first),
XyzWing => state.find_xyz_wing(stop_after_first),
MutantSwordfish => state.find_mutant_fish(3, stop_after_first),
MutantJellyfish => state.find_mutant_fish(4, stop_after_first),
_ => unimplemented!(),
}
}
pub(crate) fn deduce_one(&self, state: &mut StrategySolver) -> Result<(), Unsolvable> {
self.deduce(state, true, false)
}
pub(crate) fn deduce_all(
&self,
state: &mut StrategySolver,
is_first_strategy: bool,
) -> Result<(), Unsolvable> {
self.deduce(state, false, is_first_strategy)
}
}