detect impossible puzzle
This commit is contained in:
parent
855472e42a
commit
2f3555b303
|
@ -47,6 +47,8 @@ fn main() {
|
||||||
|
|
||||||
if let Err(reason) = solver.solve(args.limit) {
|
if let Err(reason) = solver.solve(args.limit) {
|
||||||
println!("{}", reason);
|
println!("{}", reason);
|
||||||
|
if args.debug {
|
||||||
solver.display(solver::ui::DisplayMode::Full);
|
solver.display(solver::ui::DisplayMode::Full);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,10 @@ impl Cell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_state(&self) -> Option<usize> {
|
||||||
|
self.state
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_allowed(&self) -> Vec<usize> {
|
pub fn get_allowed(&self) -> Vec<usize> {
|
||||||
self.blocking_states
|
self.blocking_states
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -107,16 +111,19 @@ impl Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_allowed(&mut self, blocking_cells: &Vec<BlockingCell>) -> Result<RemoveResult, CellError> {
|
pub fn remove_allowed(&mut self, blocking_cells: &Vec<BlockingCell>) -> Result<RemoveResult, CellError> {
|
||||||
if !self.state.is_none() {
|
|
||||||
return Ok(RemoveResult::Filled)
|
|
||||||
}
|
|
||||||
|
|
||||||
for blocking_cell in blocking_cells {
|
for blocking_cell in blocking_cells {
|
||||||
if let Some(blocking) = self.blocking_states.get_mut(&blocking_cell.state) {
|
if let Some(blocking) = self.blocking_states.get_mut(&blocking_cell.state) {
|
||||||
blocking.push(blocking_cell.position);
|
blocking.push(blocking_cell.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(state) = self.state {
|
||||||
|
if self.blocking_states[&state].len() > 0 {
|
||||||
|
return Err(CellError::StateNotAllowed)
|
||||||
|
}
|
||||||
|
return Ok(RemoveResult::Filled)
|
||||||
|
}
|
||||||
|
|
||||||
let allowed_states = self.get_allowed();
|
let allowed_states = self.get_allowed();
|
||||||
|
|
||||||
match allowed_states.len() {
|
match allowed_states.len() {
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl fmt::Display for WaveError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
WaveError::Contradiction => write!(f, "Error: The puzzle contradicts itself."),
|
WaveError::Contradiction => write!(f, "Error: The puzzle contradicts itself."),
|
||||||
WaveError::NoHistory => write!(f, "Error: Tried to backtrack but the History is empty."),
|
WaveError::NoHistory => write!(f, "Error: The puzzle is impossible (backtracked to start)."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue