-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements first-pass of simulating games, not parallelized
- Loading branch information
1 parent
5fbec97
commit bdaefd0
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod card; | ||
pub mod deck; | ||
pub mod hand; | ||
pub mod stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! | ||
//! File: stats.rs | ||
//! Description: Data structures for gathering statistics | ||
//! | ||
//! | ||
//! | ||
use std::fmt; | ||
|
||
use crate::types::hand::Outcome; | ||
|
||
/// Data to track per player "run" (how long a player sits at the table) | ||
pub struct RunStats { | ||
num_games: usize, | ||
wins: usize, | ||
losses: usize, | ||
pushes: usize, | ||
remaining_credits: isize, | ||
} | ||
|
||
impl RunStats { | ||
pub fn new() -> Self { | ||
RunStats { | ||
num_games: 0, | ||
wins: 0, | ||
losses: 0, | ||
pushes: 0, | ||
remaining_credits: 0, | ||
} | ||
} | ||
|
||
/// Records stats when a game (single match) ends | ||
pub fn record_match_end(&mut self, outcome: Outcome) { | ||
self.num_games += 1; | ||
match outcome { | ||
Outcome::Win => self.wins += 1, | ||
Outcome::Loss => self.losses += 1, | ||
Outcome::Push => self.pushes += 1, | ||
} | ||
} | ||
|
||
/// Record the final credit count | ||
pub fn record_credits(&mut self, credits: isize) { | ||
self.remaining_credits = credits; | ||
} | ||
} | ||
|
||
impl fmt::Display for RunStats { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!( | ||
f, | ||
"Games: {} | W/L/P: {}/{}/{} | Credits: ${}", | ||
self.num_games, self.wins, self.losses, self.pushes, self.remaining_credits | ||
) | ||
} | ||
} |