Compare commits
2 Commits
59067ebfbf
...
64e32b1010
| Author | SHA1 | Date | |
|---|---|---|---|
| 64e32b1010 | |||
| 850bd0f8ee |
@@ -405,6 +405,7 @@ where
|
||||
pub fn is_winnable(&self) -> Option<Vec<StateSnapshot<G>>> {
|
||||
let mut state_moves = std::collections::HashMap::new();
|
||||
let mut state = self.clone();
|
||||
let mut i: u64 = 0;
|
||||
while !state.is_win() {
|
||||
// Continue existing iterator if it exists
|
||||
let it = state_moves
|
||||
|
||||
+7
-7
@@ -629,18 +629,19 @@ impl Klondike {
|
||||
KlondikeInstruction::RotateStock => 4,
|
||||
}
|
||||
}
|
||||
pub fn iter(&self) -> impl Iterator<Item = KlondikeInstruction> + use<> {
|
||||
let state = self.state.clone();
|
||||
KlondikeIter::new().filter(move |&instruction| state.is_instruction_valid(instruction))
|
||||
}
|
||||
/// A single move that usually makes progress towards a winning game
|
||||
pub fn get_auto_move(&self) -> Option<KlondikeInstruction> {
|
||||
self.possible_instructions()
|
||||
self.iter()
|
||||
.filter(|ins| !ins.is_useless())
|
||||
.min_by_key(|ins| self.instruction_priority(ins))
|
||||
}
|
||||
/// A list of possible moves with useless moves filtered out and sorted by a simple priority function
|
||||
pub fn get_sorted_moves(&self) -> Vec<KlondikeInstruction> {
|
||||
let mut useful_moves: Vec<_> = self
|
||||
.possible_instructions()
|
||||
.filter(|ins| !ins.is_useless())
|
||||
.collect();
|
||||
let mut useful_moves: Vec<_> = self.iter().filter(|ins| !ins.is_useless()).collect();
|
||||
useful_moves.sort_by_key(|ins| self.instruction_priority(ins));
|
||||
useful_moves
|
||||
}
|
||||
@@ -651,8 +652,7 @@ impl Game for Klondike {
|
||||
type Config = KlondikeConfig;
|
||||
type Instruction = KlondikeInstruction;
|
||||
fn possible_instructions(&self) -> impl Iterator<Item = Self::Instruction> + use<> {
|
||||
let state = self.state.clone();
|
||||
KlondikeIter::new().filter(move |&instruction| state.is_instruction_valid(instruction))
|
||||
self.get_sorted_moves().into_iter()
|
||||
}
|
||||
fn is_instruction_valid(&self, _config: &Self::Config, instruction: Self::Instruction) -> bool {
|
||||
self.state.is_instruction_valid(instruction)
|
||||
|
||||
Reference in New Issue
Block a user