Revert "temporarily remove is_winnable because it doesn't work"

This reverts commit 5a52f2ab7a.
This commit is contained in:
2026-05-19 07:10:38 -07:00
parent 90f8fe2e77
commit 576489c226
2 changed files with 36 additions and 2 deletions
+34
View File
@@ -389,6 +389,40 @@ where
pub fn is_win(&self) -> bool {
self.state.is_win()
}
pub fn is_winnable(&self) -> Option<Vec<G::Instruction>> {
let mut observed = std::collections::HashSet::new();
struct StateMachine<G, P, I> {
state: G,
possible_instructions_iter: P,
instruction: I,
}
let mut dummy_stats = self.stats.inner_stats.clone();
let mut state = self.state.state.clone();
let mut it = state.possible_instructions();
let mut path = Vec::new();
'outer: while !state.is_win() {
observed.insert(state.clone());
for instruction in &mut it {
let mut next_state = state.clone();
next_state.process_instruction(&mut dummy_stats, &self.config, instruction.clone());
if !observed.contains(&next_state) {
let possible_instructions_iter =
core::mem::replace(&mut it, next_state.possible_instructions());
let state = core::mem::replace(&mut state, next_state);
path.push(StateMachine {
state,
possible_instructions_iter,
instruction,
});
continue 'outer;
}
}
let last_state = path.pop()?;
state = last_state.state;
it = last_state.possible_instructions_iter;
}
Some(path.into_iter().map(|state| state.instruction).collect())
}
}
impl<G: Game> Game for SessionState<G>
where
+2 -2
View File
@@ -4,8 +4,8 @@ use klondike::{
KlondikePile, KlondikePileStack, KlondikeStats, SkipCards, Tableau, TableauStack,
};
// #[cfg(test)]
// mod test;
#[cfg(test)]
mod test;
use std::fmt::Display;
struct Displayed<T>(T);