rename state to session
This commit is contained in:
@@ -498,9 +498,9 @@ where
|
|||||||
/// Attempt to produce a solution.
|
/// Attempt to produce a solution.
|
||||||
pub fn solve(&self) -> Result<Option<Solution<G>>, SolveError> {
|
pub fn solve(&self) -> Result<Option<Solution<G>>, SolveError> {
|
||||||
let mut state_moves = std::collections::HashMap::new();
|
let mut state_moves = std::collections::HashMap::new();
|
||||||
let mut state = self.clone();
|
let mut session = self.clone();
|
||||||
let mut moves = 0;
|
let mut moves = 0;
|
||||||
while !state.is_win() {
|
while !session.is_win() {
|
||||||
moves += 1;
|
moves += 1;
|
||||||
if self.config.solve_moves_budget < moves {
|
if self.config.solve_moves_budget < moves {
|
||||||
return Err(SolveError::MovesBudgetExceeded);
|
return Err(SolveError::MovesBudgetExceeded);
|
||||||
@@ -510,9 +510,9 @@ where
|
|||||||
}
|
}
|
||||||
// Continue existing iterator if it exists
|
// Continue existing iterator if it exists
|
||||||
let it = state_moves
|
let it = state_moves
|
||||||
.entry(state.state().state().clone())
|
.entry(session.state().state().clone())
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
state
|
session
|
||||||
.state()
|
.state()
|
||||||
.state()
|
.state()
|
||||||
.possible_instructions(&self.config().inner)
|
.possible_instructions(&self.config().inner)
|
||||||
@@ -520,19 +520,19 @@ where
|
|||||||
|
|
||||||
// Run one possible move
|
// Run one possible move
|
||||||
if let Some(instruction) = it.next() {
|
if let Some(instruction) = it.next() {
|
||||||
state.process_instruction(instruction);
|
session.process_instruction(instruction);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No more moves. If we can't undo we're done
|
// No more moves. If we can't undo we're done
|
||||||
if state.history().is_empty() {
|
if session.history().is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else {
|
} else {
|
||||||
state.undo();
|
session.undo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Some(Solution {
|
Ok(Some(Solution {
|
||||||
solution: state.state.history,
|
solution: session.state.history,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user