fix stock reset
This commit is contained in:
+2
-2
@@ -138,8 +138,8 @@ impl Pile {
|
||||
face_up: Stack::new(),
|
||||
}
|
||||
}
|
||||
pub fn make_face_down(&mut self) {
|
||||
self.face_down.extend(self.face_up.drain(..));
|
||||
pub fn swap_up_down(&mut self) {
|
||||
core::mem::swap(&mut self.face_up, &mut self.face_down);
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.face_down.is_empty() && self.face_up.is_empty()
|
||||
|
||||
+13
-2
@@ -215,8 +215,19 @@ impl Game for Klondike {
|
||||
self.state.is_instruction_valid(instruction)
|
||||
}
|
||||
fn process_instruction(&mut self, instruction: Self::Instruction) {
|
||||
let card = self.pile_mut(instruction.src).pop().unwrap();
|
||||
self.pile_mut(instruction.dst).push(card);
|
||||
match instruction {
|
||||
// Reset the stock if it's empty
|
||||
KlondikeInstruction {
|
||||
src: KlondikePileId::Stock,
|
||||
dst: KlondikePileId::Stock,
|
||||
} if self.pile(KlondikePileId::Stock).is_empty() => {
|
||||
self.pile_mut(KlondikePileId::Stock).swap_up_down();
|
||||
}
|
||||
KlondikeInstruction { src, dst } => {
|
||||
let card = self.pile_mut(src).pop().unwrap();
|
||||
self.pile_mut(dst).push(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn is_win(&self) -> bool {
|
||||
// assuming only valid moves, tableau empty and stock empty means win
|
||||
|
||||
Reference in New Issue
Block a user