From d601777e9d68c0e4b81aca6423262f520931c8f7 Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Sat, 16 May 2026 11:34:25 -0700 Subject: [PATCH] wild wild --- src/klondike.rs | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/klondike.rs b/src/klondike.rs index 1c76502..351054c 100644 --- a/src/klondike.rs +++ b/src/klondike.rs @@ -179,6 +179,10 @@ pub struct DstFoundation { foundation: Foundation, } impl DstFoundation { + const ITER_BEGIN: Self = Self { + src: KlondikePile::ITER_BEGIN, + foundation: Foundation::ITER_BEGIN, + }; const fn next(self) -> Option { let DstFoundation { src, foundation } = self; if let Some(src) = src.next() { @@ -222,6 +226,7 @@ pub enum KlondikeInstruction { RotateStock, } impl KlondikeInstruction { + const ITER_BEGIN: Self = Self::DstFoundation(DstFoundation::ITER_BEGIN); const fn next(self) -> Option { Some(match self { Self::DstFoundation(dst_foundation) => match dst_foundation.next() { @@ -387,33 +392,16 @@ impl KlondikeState { fn is_instruction_valid(&self, instruction: KlondikeInstruction) -> bool { match instruction { // Stock -> Stock draws a card or resets the stock - KlondikeInstruction { - src: InstructionSrc::STOCK, - dst: KlondikePileId::Stock, - } => { + KlondikeInstruction::RotateStock => { // cannot move stock when stock is empty !self.stock.is_empty() } - // cannot move cards to stock - KlondikeInstruction { - src: _, - dst: KlondikePileId::Stock, - } => false, - // moving to foundation has special rules - KlondikeInstruction { src, dst } - if matches!( - dst, - KlondikePileId::Foundation1 - | KlondikePileId::Foundation2 - | KlondikePileId::Foundation3 - | KlondikePileId::Foundation4 - ) => - { + KlondikeInstruction::DstFoundation(dst_foundation) => { // get the top cards - if let Some(src_card) = self.src_card(src) { - match self.dst_card(dst) { + if let Some(src_card) = self.src_card(dst_foundation.src) { + match self.dst_card(dst_foundation.foundation) { // destination card exists Some(dst_card) => { // suit matches? @@ -429,10 +417,10 @@ impl KlondikeState { } } // other = move to tableau - KlondikeInstruction { src, dst } => { + KlondikeInstruction::DstTableau(dst_tableau) => { // get the top cards - if let Some(src_card) = self.src_card(src) { - match self.dst_card(dst) { + if let Some(src_card) = self.src_card(dst_tableau.src) { + match self.dst_card(dst_tableau.tableau) { // destination card exists Some(dst_card) => { // red-ness is opposite? @@ -457,10 +445,7 @@ pub struct KlondikeIter { impl KlondikeIter { const fn new() -> Self { Self { - instruction: Some(KlondikeInstruction { - src: InstructionSrc::new(KlondikePileStack::Tableau1(SkipCards::Skip0)), - dst: KlondikePileId::Tableau2, - }), + instruction: Some(KlondikeInstruction::ITER_BEGIN), } } }