Add puzzle variable tokens.
We have chosen to return a variable token for every variable created, instead of referencing puzzle variables by string or something else. Puzzle variables should only be used in the puzzle that created it, though this is neither checked nor enforced. Eventually, we would also like to overload the standard arithmetic symbols to ergonomically build constraint expressions.
This commit is contained in:
parent
242dd19fca
commit
dbd4a9b5c8
@ -5,4 +5,8 @@ extern crate bit_set;
|
||||
|
||||
pub use puzzle::Puzzle;
|
||||
|
||||
/// A puzzle variable token.
|
||||
#[derive(Copy,Clone,Debug,Eq,PartialEq)]
|
||||
pub struct VarToken(usize);
|
||||
|
||||
mod puzzle;
|
||||
|
@ -1,7 +1,8 @@
|
||||
//! The puzzle's state and rules.
|
||||
|
||||
use ::VarToken;
|
||||
|
||||
/// The puzzle to be solved.
|
||||
#[allow(dead_code)]
|
||||
pub struct Puzzle {
|
||||
// The number of variables in the puzzle.
|
||||
num_vars: usize,
|
||||
@ -20,4 +21,19 @@ impl Puzzle {
|
||||
num_vars: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocate a new puzzle variable, without inserting any
|
||||
/// candidates.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut puzzle = puzzle_solver::Puzzle::new();
|
||||
/// puzzle.new_var();
|
||||
/// ```
|
||||
pub fn new_var(&mut self) -> VarToken {
|
||||
let var = VarToken(self.num_vars);
|
||||
self.num_vars = self.num_vars + 1;
|
||||
var
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user