Compare commits
2 Commits
35299309e0
...
3f68ce545d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f68ce545d | |||
| a3e405b4bc |
+10
-10
@@ -256,11 +256,11 @@ const TABLEAUS: usize = 7;
|
|||||||
const fn sum(n: usize) -> usize {
|
const fn sum(n: usize) -> usize {
|
||||||
n * (n + 1) / 2
|
n * (n + 1) / 2
|
||||||
}
|
}
|
||||||
const MAX_STACK: usize = 52 - sum(TABLEAUS);
|
const STOCK: usize = 52 - sum(TABLEAUS);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
pub struct KlondikeState {
|
pub struct KlondikeState {
|
||||||
stock: Pile<MAX_STACK, MAX_STACK>,
|
stock: Pile<STOCK, STOCK>,
|
||||||
foundations: [Stack<13>; 4],
|
foundations: [Stack<13>; 4],
|
||||||
tableau1: Pile<0, 13>,
|
tableau1: Pile<0, 13>,
|
||||||
tableau2: Pile<1, 13>,
|
tableau2: Pile<1, 13>,
|
||||||
@@ -271,20 +271,20 @@ pub struct KlondikeState {
|
|||||||
tableau7: Pile<6, 13>,
|
tableau7: Pile<6, 13>,
|
||||||
}
|
}
|
||||||
impl KlondikeState {
|
impl KlondikeState {
|
||||||
pub const fn stock(&self) -> &Pile<MAX_STACK, MAX_STACK> {
|
pub const fn stock(&self) -> &Pile<STOCK, STOCK> {
|
||||||
&self.stock
|
&self.stock
|
||||||
}
|
}
|
||||||
pub const fn foundation1(&self) -> &Stack<13> {
|
pub const fn foundation1(&self) -> &Stack<13> {
|
||||||
&self.foundations[1 - 1]
|
&self.foundations[Foundation::Foundation1 as usize]
|
||||||
}
|
}
|
||||||
pub const fn foundation2(&self) -> &Stack<13> {
|
pub const fn foundation2(&self) -> &Stack<13> {
|
||||||
&self.foundations[2 - 1]
|
&self.foundations[Foundation::Foundation2 as usize]
|
||||||
}
|
}
|
||||||
pub const fn foundation3(&self) -> &Stack<13> {
|
pub const fn foundation3(&self) -> &Stack<13> {
|
||||||
&self.foundations[3 - 1]
|
&self.foundations[Foundation::Foundation3 as usize]
|
||||||
}
|
}
|
||||||
pub const fn foundation4(&self) -> &Stack<13> {
|
pub const fn foundation4(&self) -> &Stack<13> {
|
||||||
&self.foundations[4 - 1]
|
&self.foundations[Foundation::Foundation4 as usize]
|
||||||
}
|
}
|
||||||
pub const fn tableau1(&self) -> &Pile<0, 13> {
|
pub const fn tableau1(&self) -> &Pile<0, 13> {
|
||||||
&self.tableau1
|
&self.tableau1
|
||||||
@@ -307,7 +307,7 @@ impl KlondikeState {
|
|||||||
pub const fn tableau7(&self) -> &Pile<6, 13> {
|
pub const fn tableau7(&self) -> &Pile<6, 13> {
|
||||||
&self.tableau7
|
&self.tableau7
|
||||||
}
|
}
|
||||||
fn card(&self, src: KlondikePileStack) -> Option<&Card> {
|
pub fn card(&self, src: KlondikePileStack) -> Option<&Card> {
|
||||||
match src {
|
match src {
|
||||||
KlondikePileStack::Tableau(TableauStack {
|
KlondikePileStack::Tableau(TableauStack {
|
||||||
tableau,
|
tableau,
|
||||||
@@ -327,7 +327,7 @@ impl KlondikeState {
|
|||||||
KlondikePileStack::Stock => self.stock.face_up().last(),
|
KlondikePileStack::Stock => self.stock.face_up().last(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn top_card(&self, src: KlondikePile) -> Option<&Card> {
|
pub fn top_card(&self, src: KlondikePile) -> Option<&Card> {
|
||||||
match src {
|
match src {
|
||||||
KlondikePile::Tableau(tableau) => match tableau {
|
KlondikePile::Tableau(tableau) => match tableau {
|
||||||
Tableau::Tableau1 => self.tableau1.face_up().last(),
|
Tableau::Tableau1 => self.tableau1.face_up().last(),
|
||||||
@@ -394,7 +394,7 @@ impl KlondikeState {
|
|||||||
KlondikePile::Stock => self.stock.extend(cards),
|
KlondikePile::Stock => self.stock.extend(cards),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn is_instruction_valid(&self, instruction: KlondikeInstruction) -> bool {
|
pub fn is_instruction_valid(&self, instruction: KlondikeInstruction) -> bool {
|
||||||
match instruction {
|
match instruction {
|
||||||
// Stock -> Stock draws a card or resets the stock
|
// Stock -> Stock draws a card or resets the stock
|
||||||
KlondikeInstruction::RotateStock => {
|
KlondikeInstruction::RotateStock => {
|
||||||
|
|||||||
+15
-1
@@ -225,13 +225,27 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
}
|
}
|
||||||
SessionInstruction::Auto => {
|
SessionInstruction::Auto => {
|
||||||
fn useless_moves(instruction: &KlondikeInstruction) -> bool {
|
fn useless_moves(instruction: &KlondikeInstruction) -> bool {
|
||||||
// foundation -> foundation is a useless move
|
|
||||||
!matches!(
|
!matches!(
|
||||||
instruction,
|
instruction,
|
||||||
|
// foundation -> foundation is a useless move
|
||||||
KlondikeInstruction::DstFoundation(DstFoundation {
|
KlondikeInstruction::DstFoundation(DstFoundation {
|
||||||
src: KlondikePile::Foundation(_),
|
src: KlondikePile::Foundation(_),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
|
// Tableau -> Tableau when not revealing a new card is _usually_ a useless move
|
||||||
|
| KlondikeInstruction::DstTableau(DstTableau {
|
||||||
|
src: KlondikePileStack::Tableau(TableauStack {
|
||||||
|
skip_cards: SkipCards::Skip1
|
||||||
|
| SkipCards::Skip2 | SkipCards::Skip3
|
||||||
|
| SkipCards::Skip4 | SkipCards::Skip5
|
||||||
|
| SkipCards::Skip6 | SkipCards::Skip7
|
||||||
|
| SkipCards::Skip8 | SkipCards::Skip9
|
||||||
|
| SkipCards::Skip10 | SkipCards::Skip11
|
||||||
|
| SkipCards::Skip12,
|
||||||
|
..
|
||||||
|
}),
|
||||||
|
..
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if let Some(instruction) =
|
if let Some(instruction) =
|
||||||
|
|||||||
Reference in New Issue
Block a user