Compare commits
2 Commits
8269c7e87f
...
bb558c7983
| Author | SHA1 | Date | |
|---|---|---|---|
| bb558c7983 | |||
| 6fec71ea0a |
@@ -222,7 +222,7 @@ fn get_good_move(state: &Klondike) -> Option<KlondikeInstruction> {
|
|||||||
}) if !state.state().is_tableau_face_down_empty(tableau)
|
}) if !state.state().is_tableau_face_down_empty(tableau)
|
||||||
|| state
|
|| state
|
||||||
.state()
|
.state()
|
||||||
.card(dst_tableau.src)
|
.stack_bottom_card(dst_tableau.src)
|
||||||
.is_some_and(|card| card.value() != CardValue::KING) =>
|
.is_some_and(|card| card.value() != CardValue::KING) =>
|
||||||
{
|
{
|
||||||
2
|
2
|
||||||
|
|||||||
+13
-13
@@ -327,7 +327,7 @@ impl KlondikeState {
|
|||||||
Tableau::Tableau7 => self.tableau7.face_down().is_empty(),
|
Tableau::Tableau7 => self.tableau7.face_down().is_empty(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn card(&self, src: KlondikePileStack) -> Option<&Card> {
|
pub fn stack_bottom_card(&self, src: KlondikePileStack) -> Option<&Card> {
|
||||||
match src {
|
match src {
|
||||||
KlondikePileStack::Tableau(TableauStack {
|
KlondikePileStack::Tableau(TableauStack {
|
||||||
tableau,
|
tableau,
|
||||||
@@ -347,8 +347,8 @@ impl KlondikeState {
|
|||||||
KlondikePileStack::Stock => self.stock.face_up().last(),
|
KlondikePileStack::Stock => self.stock.face_up().last(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn top_card(&self, src: KlondikePile) -> Option<&Card> {
|
pub fn top_card<S: Into<KlondikePile>>(&self, src: S) -> Option<&Card> {
|
||||||
match src {
|
match src.into() {
|
||||||
KlondikePile::Tableau(tableau) => match tableau {
|
KlondikePile::Tableau(tableau) => match tableau {
|
||||||
Tableau::Tableau1 => self.tableau1.face_up().last(),
|
Tableau::Tableau1 => self.tableau1.face_up().last(),
|
||||||
Tableau::Tableau2 => self.tableau2.face_up().last(),
|
Tableau::Tableau2 => self.tableau2.face_up().last(),
|
||||||
@@ -382,8 +382,8 @@ impl KlondikeState {
|
|||||||
KlondikePileStack::Stock => Stack::from_iter(self.stock.pop()),
|
KlondikePileStack::Stock => Stack::from_iter(self.stock.pop()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn take_top_card(&mut self, src: KlondikePile) -> Option<Card> {
|
fn take_top_card<S: Into<KlondikePile>>(&mut self, src: S) -> Option<Card> {
|
||||||
match src {
|
match src.into() {
|
||||||
KlondikePile::Tableau(tableau) => match tableau {
|
KlondikePile::Tableau(tableau) => match tableau {
|
||||||
Tableau::Tableau1 => self.tableau1.pop_flip_up(),
|
Tableau::Tableau1 => self.tableau1.pop_flip_up(),
|
||||||
Tableau::Tableau2 => self.tableau2.pop_flip_up(),
|
Tableau::Tableau2 => self.tableau2.pop_flip_up(),
|
||||||
@@ -397,8 +397,8 @@ impl KlondikeState {
|
|||||||
KlondikePile::Stock => self.stock.pop_flip_up(),
|
KlondikePile::Stock => self.stock.pop_flip_up(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn extend<I: IntoIterator<Item = Card>>(&mut self, dst: KlondikePile, cards: I) {
|
fn extend<D: Into<KlondikePile>, I: IntoIterator<Item = Card>>(&mut self, dst: D, cards: I) {
|
||||||
match dst {
|
match dst.into() {
|
||||||
KlondikePile::Tableau(tableau) => match tableau {
|
KlondikePile::Tableau(tableau) => match tableau {
|
||||||
Tableau::Tableau1 => self.tableau1.extend(cards),
|
Tableau::Tableau1 => self.tableau1.extend(cards),
|
||||||
Tableau::Tableau2 => self.tableau2.extend(cards),
|
Tableau::Tableau2 => self.tableau2.extend(cards),
|
||||||
@@ -426,7 +426,7 @@ impl KlondikeState {
|
|||||||
KlondikeInstruction::DstFoundation(dst_foundation) => {
|
KlondikeInstruction::DstFoundation(dst_foundation) => {
|
||||||
// get the top cards
|
// get the top cards
|
||||||
if let Some(src_card) = self.top_card(dst_foundation.src) {
|
if let Some(src_card) = self.top_card(dst_foundation.src) {
|
||||||
match self.top_card(dst_foundation.foundation.into()) {
|
match self.top_card(dst_foundation.foundation) {
|
||||||
// destination card exists
|
// destination card exists
|
||||||
Some(dst_card) => {
|
Some(dst_card) => {
|
||||||
// suit matches?
|
// suit matches?
|
||||||
@@ -444,8 +444,8 @@ impl KlondikeState {
|
|||||||
// other = move to tableau
|
// other = move to tableau
|
||||||
KlondikeInstruction::DstTableau(dst_tableau) => {
|
KlondikeInstruction::DstTableau(dst_tableau) => {
|
||||||
// get the cards
|
// get the cards
|
||||||
if let Some(src_card) = self.card(dst_tableau.src) {
|
if let Some(src_card) = self.stack_bottom_card(dst_tableau.src) {
|
||||||
match self.top_card(dst_tableau.tableau.into()) {
|
match self.top_card(dst_tableau.tableau) {
|
||||||
// destination card exists
|
// destination card exists
|
||||||
Some(dst_card) => {
|
Some(dst_card) => {
|
||||||
// red-ness is opposite?
|
// red-ness is opposite?
|
||||||
@@ -555,12 +555,12 @@ impl Game for Klondike {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KlondikeInstruction::DstFoundation(DstFoundation { src, foundation }) => {
|
KlondikeInstruction::DstFoundation(DstFoundation { src, foundation }) => {
|
||||||
let cards = self.state.take_top_card(src);
|
let card = self.state.take_top_card(src);
|
||||||
self.state.extend(foundation.into(), cards);
|
self.state.extend(foundation, card);
|
||||||
}
|
}
|
||||||
KlondikeInstruction::DstTableau(DstTableau { src, tableau }) => {
|
KlondikeInstruction::DstTableau(DstTableau { src, tableau }) => {
|
||||||
let cards = self.state.take_stack(src);
|
let cards = self.state.take_stack(src);
|
||||||
self.state.extend(tableau.into(), cards);
|
self.state.extend(tableau, cards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user