29 lines
996 B
Rust
Raw Normal View History

//! Constraint trait, and some common constraints.
//!
//! Note that all puzzle states visited during the solution search
//! share the same set of constraints. This means that you cannot
//! store additional information about the state (e.g. caches) in the
//! constraint to reuse later.
use ::{PuzzleSearch,Val,VarToken};
/// Constraint trait.
pub trait Constraint {
/// Applied after a variable has been assigned.
///
/// Returns true if the search should continue with these variable
/// assignments, or false if the constraint found a contradiction.
fn on_assigned(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val)
-> bool {
true
}
/// Applied after a variable's candidates has been modified.
///
/// Returns true if the search should continue with these variable
/// assignments, or false if the constraint found a contradiction.
fn on_updated(&self, _search: &mut PuzzleSearch) -> bool {
true
}
}