From 8417c160fe4144d10da7b2fbef174efa36cea8ba Mon Sep 17 00:00:00 2001 From: Evan Slack Date: Fri, 6 Dec 2024 23:30:05 -0500 Subject: [PATCH] add round and game display --- src/core/game.rs | 22 ++++++++++++++++++++++ src/lib.rs | 7 ++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/core/game.rs b/src/core/game.rs index c3f688e..37aa1cc 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -6,9 +6,11 @@ use crate::core::error::GameError; use crate::core::hand::{MadeHand, SelectHand}; use crate::core::stage::{Blind, End, Stage}; use std::collections::HashSet; +use std::fmt; use itertools::Itertools; +const DEFAULT_ROUND_START: usize = 0; const DEFAULT_PLAYS: usize = 4; const DEFAULT_DISCARDS: usize = 4; const DEFAULT_MONEY: usize = 0; @@ -31,6 +33,7 @@ pub struct Game { pub stage: Stage, pub ante: Ante, pub action_history: Vec, + pub round: usize, // playing pub plays: usize, @@ -54,6 +57,7 @@ impl Game { stage: Stage::PreBlind, ante: Ante::One, action_history: Vec::new(), + round: DEFAULT_ROUND_START, plays: DEFAULT_PLAYS, discards: DEFAULT_DISCARDS, reward: DEFAULT_REWARD, @@ -216,6 +220,7 @@ impl Game { pub fn next_round(&mut self) -> Result<(), GameError> { self.stage = Stage::PreBlind; + self.round += 1; return Ok(()); } @@ -449,6 +454,23 @@ impl Game { } } +impl fmt::Display for Game { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + writeln!(f, "deck length: {}", self.deck.len())?; + writeln!(f, "available length: {}", self.available.len())?; + writeln!(f, "discard length: {}", self.discarded.len())?; + writeln!(f, "action history length: {}", self.action_history.len())?; + writeln!(f, "blind: {:?}", self.blind)?; + writeln!(f, "stage: {:?}", self.stage)?; + writeln!(f, "ante: {:?}", self.ante)?; + writeln!(f, "round: {}", self.round)?; + writeln!(f, "hands remaining: {}", self.plays)?; + writeln!(f, "discards remaining: {}", self.discards)?; + writeln!(f, "money: {}", self.money)?; + writeln!(f, "score: {}", self.score) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/lib.rs b/src/lib.rs index 146da0e..2441b9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,8 +23,9 @@ mod tests { // Pick a random move and execute it let i = rand::thread_rng().gen_range(0..actions.len()); let action = actions[i].clone(); - dbg!(action.clone()); - let action_res = g.handle_action(action.clone()); + println!("game state:\n{}", g.clone()); + println!("play action: {}", action.clone()); + let action_res = g.handle_action(action); debug_assert!(action_res.is_ok()); } let result = g.result(); @@ -32,6 +33,6 @@ mod tests { assert!(result.is_some()); // Check game state at end assert!(matches!(g.stage, Stage::End(_))); - dbg!(g.action_history); + println!("game action history: {:?}", g.action_history); } }