Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 334084e4df | |||
| 792c9acba3 | |||
| a5ca7ff25d |
@@ -52,6 +52,12 @@ pub struct KlondikeInstruction {
|
|||||||
pub dst: KlondikePileId,
|
pub dst: KlondikePileId,
|
||||||
}
|
}
|
||||||
impl KlondikeInstruction {
|
impl KlondikeInstruction {
|
||||||
|
pub fn stock() -> Self {
|
||||||
|
Self {
|
||||||
|
src: KlondikePileId::Stock,
|
||||||
|
dst: KlondikePileId::Stock,
|
||||||
|
}
|
||||||
|
}
|
||||||
fn next(self) -> Option<Self> {
|
fn next(self) -> Option<Self> {
|
||||||
let KlondikeInstruction { src, dst } = self;
|
let KlondikeInstruction { src, dst } = self;
|
||||||
if let Some(next_dst) = dst.next() {
|
if let Some(next_dst) = dst.next() {
|
||||||
|
|||||||
+7
-1
@@ -70,7 +70,7 @@ impl Display for Klondike {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
{
|
{
|
||||||
write!(f, "T{i} ")?;
|
write!(f, "T{} ", i + 1)?;
|
||||||
let pile = self.pile(tableau);
|
let pile = self.pile(tableau);
|
||||||
for _ in pile.face_down() {
|
for _ in pile.face_down() {
|
||||||
write!(f, "]")?;
|
write!(f, "]")?;
|
||||||
@@ -119,16 +119,20 @@ impl core::str::FromStr for Parsed<KlondikePileId> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum SessionInstruction {
|
enum SessionInstruction {
|
||||||
|
New,
|
||||||
Undo,
|
Undo,
|
||||||
Hint,
|
Hint,
|
||||||
|
Stock,
|
||||||
Klondike(KlondikeInstruction),
|
Klondike(KlondikeInstruction),
|
||||||
}
|
}
|
||||||
impl core::str::FromStr for SessionInstruction {
|
impl core::str::FromStr for SessionInstruction {
|
||||||
type Err = Invalid;
|
type Err = Invalid;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(match s {
|
Ok(match s {
|
||||||
|
"NEW" | "new" => Self::New,
|
||||||
"UNDO" | "undo" => Self::Undo,
|
"UNDO" | "undo" => Self::Undo,
|
||||||
"HINT" | "hint" => Self::Hint,
|
"HINT" | "hint" => Self::Hint,
|
||||||
|
"s" => Self::Stock,
|
||||||
other => {
|
other => {
|
||||||
let Parsed(ki) = other.parse()?;
|
let Parsed(ki) = other.parse()?;
|
||||||
Self::Klondike(ki)
|
Self::Klondike(ki)
|
||||||
@@ -153,12 +157,14 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
|
|
||||||
// run game
|
// run game
|
||||||
match instruction {
|
match instruction {
|
||||||
|
SessionInstruction::New => session = Session::new(Klondike::new_random_default()),
|
||||||
SessionInstruction::Undo => session.undo(),
|
SessionInstruction::Undo => session.undo(),
|
||||||
SessionInstruction::Hint => {
|
SessionInstruction::Hint => {
|
||||||
for instruction in session.possible_instructions() {
|
for instruction in session.possible_instructions() {
|
||||||
println!("{instruction:?}");
|
println!("{instruction:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SessionInstruction::Stock => session.process_instruction(KlondikeInstruction::stock()),
|
||||||
SessionInstruction::Klondike(instruction) => {
|
SessionInstruction::Klondike(instruction) => {
|
||||||
if session.is_instruction_valid(instruction) {
|
if session.is_instruction_valid(instruction) {
|
||||||
session.process_instruction(instruction);
|
session.process_instruction(instruction);
|
||||||
|
|||||||
Reference in New Issue
Block a user