Update Square::Options to Marks and index at 1.
This commit is contained in:
parent
322011306a
commit
64189981f2
13
src/board.rs
13
src/board.rs
|
@ -27,7 +27,7 @@ impl Board {
|
|||
pub fn restrict_marks(&mut self) {
|
||||
let self_copy = self.clone();
|
||||
for (index, ref mut square) in self.squares.iter_mut().enumerate() {
|
||||
if let Square::Options(ref mut opt) = square {
|
||||
if let Square::Marks(ref mut marks) = square {
|
||||
self_copy
|
||||
.row_from_index(index)
|
||||
.filter_map(|sq| match sq {
|
||||
|
@ -35,7 +35,7 @@ impl Board {
|
|||
_ => None,
|
||||
})
|
||||
.for_each(|value| {
|
||||
opt.set((value - 1) as usize, false);
|
||||
marks.set(value as usize, false);
|
||||
});
|
||||
self_copy
|
||||
.col_from_index(index)
|
||||
|
@ -44,7 +44,7 @@ impl Board {
|
|||
_ => None,
|
||||
})
|
||||
.for_each(|value| {
|
||||
opt.set((value - 1) as usize, false);
|
||||
marks.set(value as usize, false);
|
||||
});
|
||||
self_copy
|
||||
.box_from_index(index)
|
||||
|
@ -53,7 +53,7 @@ impl Board {
|
|||
_ => None,
|
||||
})
|
||||
.for_each(|value| {
|
||||
opt.set((value - 1) as usize, false);
|
||||
marks.set(value as usize, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +99,9 @@ impl Board {
|
|||
self.squares
|
||||
.iter()
|
||||
.map(|sq| match sq {
|
||||
Square::Options(opts) => {
|
||||
opts.into_iter()
|
||||
Square::Marks(marks) => {
|
||||
marks
|
||||
.into_iter()
|
||||
.map(|a| a + 1)
|
||||
.fold(String::new(), |mut a, b| {
|
||||
a.push_str(&b.to_string());
|
||||
|
|
|
@ -3,7 +3,7 @@ use bitmaps::Bitmap;
|
|||
#[derive(Clone, Debug)]
|
||||
pub enum Square {
|
||||
Value(u8),
|
||||
Options(Bitmap<9>),
|
||||
Marks(Bitmap<10>),
|
||||
}
|
||||
|
||||
impl Square {
|
||||
|
@ -18,14 +18,18 @@ impl Square {
|
|||
'7' => Square::Value(7),
|
||||
'8' => Square::Value(8),
|
||||
'9' => Square::Value(9),
|
||||
'.' => Square::Options(Bitmap::mask(9)),
|
||||
'.' => {
|
||||
let mut bm = Bitmap::mask(10);
|
||||
bm.set(0, false);
|
||||
Square::Marks(bm)
|
||||
}
|
||||
_ => panic!("Unexpected character in input: {}", c),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_str(&self) -> String {
|
||||
match self {
|
||||
Square::Options(_) => " ".to_string(),
|
||||
Square::Marks(_) => " ".to_string(),
|
||||
Square::Value(v) => v.to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ impl Strategy for NakedSingle {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, square)| match square {
|
||||
Square::Options(marks) => Some((index, marks)),
|
||||
Square::Marks(marks) => Some((index, marks)),
|
||||
_ => None,
|
||||
})
|
||||
.find(|(_index, marks)| marks.len() == 1)
|
||||
.map(|(index, marks)| NakedSingle {
|
||||
index,
|
||||
value: marks.first_index().unwrap() as u8 + 1,
|
||||
value: marks.first_index().unwrap() as u8,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn validate_board(board: &Board) -> BoardState {
|
|||
}
|
||||
|
||||
if board.squares.iter().any(|sq| match sq {
|
||||
Square::Options(_) => true,
|
||||
Square::Marks(_) => true,
|
||||
_ => false,
|
||||
}) {
|
||||
BoardState::InProgress
|
||||
|
|
Loading…
Reference in New Issue