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