display stats
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use card_game::{Card, CardValue, Game, Pile, Session, Suit};
|
||||
use card_game::{Card, CardValue, Game, Pile, Session, SessionStats, Suit};
|
||||
use klondike::{
|
||||
DstFoundation, DstTableau, Foundation, Klondike, KlondikeConfig, KlondikeInstruction,
|
||||
KlondikePile, KlondikePileStack, SkipCards, Tableau, TableauStack,
|
||||
KlondikePile, KlondikePileStack, KlondikeStats, SkipCards, Tableau, TableauStack,
|
||||
};
|
||||
|
||||
use std::fmt::Display;
|
||||
@@ -83,6 +83,18 @@ impl Display for Displayed<&Klondike> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Displayed<&SessionStats<KlondikeStats>> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"recycles: {} moves: {} undos: {}",
|
||||
self.0.stats().recycle_count(),
|
||||
self.0.stats().moves(),
|
||||
self.0.undos()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Invalid;
|
||||
struct Parsed<T>(T);
|
||||
@@ -245,6 +257,8 @@ fn main() -> Result<(), std::io::Error> {
|
||||
let mut session = Session::new_default(Klondike::new_random());
|
||||
let mut input = String::new();
|
||||
loop {
|
||||
// display stats
|
||||
println!("{}", Displayed(session.stats()));
|
||||
// display game
|
||||
println!("{}", Displayed(session.state()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user