2 Commits

Author SHA1 Message Date
Quaternions 3f68ce545d skip some tableau moves for autoplay 2026-05-16 12:41:02 -07:00
Quaternions a3e405b4bc tweaks 2026-05-16 12:37:32 -07:00
2 changed files with 25 additions and 11 deletions
+10 -10
View File
@@ -256,11 +256,11 @@ const TABLEAUS: usize = 7;
const fn sum(n: usize) -> usize {
n * (n + 1) / 2
}
const MAX_STACK: usize = 52 - sum(TABLEAUS);
const STOCK: usize = 52 - sum(TABLEAUS);
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct KlondikeState {
stock: Pile<MAX_STACK, MAX_STACK>,
stock: Pile<STOCK, STOCK>,
foundations: [Stack<13>; 4],
tableau1: Pile<0, 13>,
tableau2: Pile<1, 13>,
@@ -271,20 +271,20 @@ pub struct KlondikeState {
tableau7: Pile<6, 13>,
}
impl KlondikeState {
pub const fn stock(&self) -> &Pile<MAX_STACK, MAX_STACK> {
pub const fn stock(&self) -> &Pile<STOCK, STOCK> {
&self.stock
}
pub const fn foundation1(&self) -> &Stack<13> {
&self.foundations[1 - 1]
&self.foundations[Foundation::Foundation1 as usize]
}
pub const fn foundation2(&self) -> &Stack<13> {
&self.foundations[2 - 1]
&self.foundations[Foundation::Foundation2 as usize]
}
pub const fn foundation3(&self) -> &Stack<13> {
&self.foundations[3 - 1]
&self.foundations[Foundation::Foundation3 as usize]
}
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> {
&self.tableau1
@@ -307,7 +307,7 @@ impl KlondikeState {
pub const fn tableau7(&self) -> &Pile<6, 13> {
&self.tableau7
}
fn card(&self, src: KlondikePileStack) -> Option<&Card> {
pub fn card(&self, src: KlondikePileStack) -> Option<&Card> {
match src {
KlondikePileStack::Tableau(TableauStack {
tableau,
@@ -327,7 +327,7 @@ impl KlondikeState {
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 {
KlondikePile::Tableau(tableau) => match tableau {
Tableau::Tableau1 => self.tableau1.face_up().last(),
@@ -394,7 +394,7 @@ impl KlondikeState {
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 {
// Stock -> Stock draws a card or resets the stock
KlondikeInstruction::RotateStock => {
+15 -1
View File
@@ -225,13 +225,27 @@ fn main() -> Result<(), std::io::Error> {
}
SessionInstruction::Auto => {
fn useless_moves(instruction: &KlondikeInstruction) -> bool {
// foundation -> foundation is a useless move
!matches!(
instruction,
// foundation -> foundation is a useless move
KlondikeInstruction::DstFoundation(DstFoundation {
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) =