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