2 Commits

Author SHA1 Message Date
Quaternions a1572a3971 allow king to move to empty tableau 2026-05-15 11:03:57 -07:00
Quaternions dd557d2fcf format 2026-05-15 11:03:45 -07:00
+15 -10
View File
@@ -125,14 +125,18 @@ impl KlondikeState {
// other = move to tableau // other = move to tableau
KlondikeInstruction { src, dst } => { KlondikeInstruction { src, dst } => {
// get the top cards // get the top cards
if let Some(src_card) = self.pile(src).face_up().last() if let Some(src_card) = self.pile(src).face_up().last() {
&& let Some(dst_card) = self.pile(dst).face_up().last() match self.pile(dst).face_up().last() {
// red-ness is opposite? // destination card exists
&& src_card.is_red() != dst_card.is_red() Some(dst_card) => {
// value is -1? // red-ness is opposite?
&& dst_card.value().checked_sub(1) == Some(src_card.value()) src_card.is_red() != dst_card.is_red()
{ // value is -1?
true && dst_card.value().checked_sub(1) == Some(src_card.value())
}
// only king is allowed to go onto empty tableau
None => src_card.value() == CardValue::KING,
}
} else { } else {
false false
} }
@@ -236,8 +240,9 @@ impl Game for Klondike {
dst: KlondikePileId::Stock, dst: KlondikePileId::Stock,
} => { } => {
if self.pile(KlondikePileId::Stock).face_down().is_empty() { if self.pile(KlondikePileId::Stock).face_down().is_empty() {
self.pile_mut(KlondikePileId::Stock).flip_it_and_reverse_it(); self.pile_mut(KlondikePileId::Stock)
}else{ .flip_it_and_reverse_it();
} else {
self.pile_mut(KlondikePileId::Stock).flip_up(); self.pile_mut(KlondikePileId::Stock).flip_up();
} }
} }