fini
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use card_game::{Card, CardValue, Game, Pile, Session, Suit};
|
||||
use klondike::{
|
||||
DstFoundation, DstTableau, Foundation, Klondike, KlondikeInstruction, KlondikePile,
|
||||
KlondikePileStack, SkipCards, Tableau, TableauStack,
|
||||
DstFoundation, DstTableau, Foundation, Klondike, KlondikeConfig, KlondikeInstruction,
|
||||
KlondikePile, KlondikePileStack, SkipCards, Tableau, TableauStack,
|
||||
};
|
||||
|
||||
use std::fmt::Display;
|
||||
@@ -144,6 +144,7 @@ impl core::str::FromStr for SessionInstruction {
|
||||
}
|
||||
|
||||
fn find_valid_instruction(
|
||||
config: &KlondikeConfig,
|
||||
state: &Klondike,
|
||||
naive_instruction: NaiveInstruction,
|
||||
) -> Option<KlondikeInstruction> {
|
||||
@@ -173,7 +174,7 @@ fn find_valid_instruction(
|
||||
});
|
||||
let instruction =
|
||||
KlondikeInstruction::DstTableau(DstTableau { tableau, src });
|
||||
if state.is_instruction_valid(instruction) {
|
||||
if state.is_instruction_valid(config, instruction) {
|
||||
return Some(instruction);
|
||||
}
|
||||
}
|
||||
@@ -191,7 +192,7 @@ fn find_valid_instruction(
|
||||
_ => return None,
|
||||
};
|
||||
state
|
||||
.is_instruction_valid(instruction)
|
||||
.is_instruction_valid(config, instruction)
|
||||
.then_some(instruction)
|
||||
}
|
||||
|
||||
@@ -241,7 +242,7 @@ fn get_good_move(state: &Klondike) -> Option<KlondikeInstruction> {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let mut session = Session::new(Klondike::new_random());
|
||||
let mut session = Session::new_default(Klondike::new_random());
|
||||
let mut input = String::new();
|
||||
loop {
|
||||
// display game
|
||||
@@ -257,7 +258,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
// run game
|
||||
match instruction {
|
||||
SessionInstruction::New => session = Session::new(Klondike::new_random()),
|
||||
SessionInstruction::New => session = Session::new_default(Klondike::new_random()),
|
||||
SessionInstruction::Undo => session.undo(),
|
||||
SessionInstruction::Exit => break Ok(()),
|
||||
SessionInstruction::Hint => {
|
||||
@@ -277,7 +278,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||
}
|
||||
SessionInstruction::Klondike(naive_instruction) => {
|
||||
if let Some(instruction) =
|
||||
find_valid_instruction(session.state(), naive_instruction)
|
||||
find_valid_instruction(session.config(), session.state(), naive_instruction)
|
||||
{
|
||||
session.process_instruction(instruction);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user