diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-05-25 22:52:19 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-05-25 22:52:19 +0200 |
commit | 7b3fe83b4bdb943d3d44ed036150d017279cfe05 (patch) | |
tree | 4ed9bc57722d771fdecf9845e2412ec086eb80d0 /src/json.rs | |
parent | e9a514409565c17a4a86e8c6402be8d7a4f399ae (diff) |
Implemented tracking of the tiebreaking score
Diffstat (limited to 'src/json.rs')
-rw-r--r-- | src/json.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/json.rs b/src/json.rs index c796d2b..3cd603c 100644 --- a/src/json.rs +++ b/src/json.rs @@ -37,6 +37,12 @@ pub struct Player { pub worms: Vec<PlayerWorm>, } +impl Player { + pub fn health_score(&self) -> i32 { + self.health / self.worms.len() as i32 + } +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct PlayerWorm { @@ -56,6 +62,12 @@ pub struct Opponent { pub worms: Vec<OpponentWorm>, } +impl Opponent { + pub fn health_score(&self) -> i32 { + self.worms.iter().map(|w| w.health).sum::<i32>() / 3 + } +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct OpponentWorm { |