From aa6272c77d50a0580d4fee9fd1b522a86e6b8459 Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 9 Sep 2019 13:50:12 +1000 Subject: [PATCH 1/3] fix game end bits --- server/src/img.rs | 6 +++--- server/src/instance.rs | 4 ++++ server/src/item.rs | 2 +- server/src/mtx.rs | 2 +- server/src/player.rs | 2 +- server/src/vbox.rs | 6 +++--- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/server/src/img.rs b/server/src/img.rs index 75b0d95f..d9309323 100644 --- a/server/src/img.rs +++ b/server/src/img.rs @@ -43,8 +43,8 @@ pub fn invader_write(id: Uuid) -> Result { let mut colours = std::iter ::repeat_with(|| { let h = rng.gen_range(0, 360); - let s = s_dist.sample(&mut rng) as u16; - let l = l_dist.sample(&mut rng) as u16; + let s = s_dist.sample(&mut rng) as usize; + let l = l_dist.sample(&mut rng) as usize; format!("hsl({:}, {:}%, {:}%)", h, s, l) }) .take(3) @@ -201,7 +201,7 @@ mod tests { // - let actions = mode_drops(mode); // + let log_normal = LogNormal::new(1.0, 1.0); -// + let num_drops = log_normal.sample(&mut rng).floor() as u16; +// + let num_drops = log_normal.sample(&mut rng).floor() as usize; // + // + println!("{:?} drops", num_drops); diff --git a/server/src/instance.rs b/server/src/instance.rs index 3061cb10..57bc00aa 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -403,6 +403,8 @@ impl Instance { None => return Ok(self.finish()), }; + let bits = 12 + 6 * self.rounds.len(); + { let loser = self.players.iter() .find(|p| p.id != winner_id) @@ -414,6 +416,7 @@ impl Instance { .unwrap(); winner.score = winner.score.add_win(&loser); + winner.vbox.balance_add(bits.into()); } { @@ -422,6 +425,7 @@ impl Instance { .unwrap(); loser.score = loser.score.add_loss(); + loser.vbox.balance_add(bits.into()); } if self.all_games_finished() { diff --git a/server/src/item.rs b/server/src/item.rs index a2d4b5cf..55c883f9 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -306,7 +306,7 @@ impl Item { } } - pub fn cost(&self) -> u16 { + pub fn cost(&self) -> usize { match self { Item::Red => 1, Item::Green => 1, diff --git a/server/src/mtx.rs b/server/src/mtx.rs index 81aeadbe..e71a481b 100644 --- a/server/src/mtx.rs +++ b/server/src/mtx.rs @@ -36,7 +36,7 @@ pub struct Shop { #[derive(Debug,Copy,Clone,PartialEq,Serialize,Deserialize)] pub struct Listing { variant: MtxVariant, - credits: u16, + credits: usize, } #[derive(Debug,Copy,Clone,PartialEq,Serialize,Deserialize)] diff --git a/server/src/player.rs b/server/src/player.rs index 8c42743d..5f6b3259 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -12,7 +12,7 @@ use vbox::{Vbox}; use item::{Item, ItemEffect}; use effect::{Effect}; -const DISCARD_COST: u16 = 2; +const DISCARD_COST: usize = 2; #[derive(Debug,Copy,Clone,Serialize,Deserialize,Eq,PartialEq)] pub enum Score { diff --git a/server/src/vbox.rs b/server/src/vbox.rs index 4e2e1a96..7088d0e9 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -21,7 +21,7 @@ use item::*; #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Vbox { - pub bits: u16, + pub bits: usize, pub free: Vec>>, pub bound: Vec, } @@ -47,7 +47,7 @@ impl Vbox { } } - pub fn balance_sub(&mut self, amount: u16) -> Result<&mut Vbox, Error> { + pub fn balance_sub(&mut self, amount: usize) -> Result<&mut Vbox, Error> { let new_balance = self.bits .checked_sub(amount) .ok_or(format_err!("insufficient balance: {:?}", self.bits))?; @@ -57,7 +57,7 @@ impl Vbox { Ok(self) } - pub fn balance_add(&mut self, amount: u16) -> &mut Vbox { + pub fn balance_add(&mut self, amount: usize) -> &mut Vbox { self.bits = self.bits.saturating_add(amount); self } From 198711b3b2f8015b17fbdea46e1774713c6874f7 Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 9 Sep 2019 13:50:39 +1000 Subject: [PATCH 2/3] version 1.4.1 --- VERSION | 2 +- acp/package.json | 2 +- client/package.json | 2 +- ops/package.json | 2 +- server/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index e21e727f..13175fdc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.0 \ No newline at end of file +1.4.1 \ No newline at end of file diff --git a/acp/package.json b/acp/package.json index cc8e63ce..47c34b9f 100644 --- a/acp/package.json +++ b/acp/package.json @@ -1,6 +1,6 @@ { "name": "mnml-client", - "version": "1.4.0", + "version": "1.4.1", "description": "", "main": "index.js", "scripts": { diff --git a/client/package.json b/client/package.json index cd637efa..dd2e36f9 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "mnml-client", - "version": "1.4.0", + "version": "1.4.1", "description": "", "main": "index.js", "scripts": { diff --git a/ops/package.json b/ops/package.json index 5286926e..77c0c307 100755 --- a/ops/package.json +++ b/ops/package.json @@ -1,6 +1,6 @@ { "name": "mnml-ops", - "version": "1.4.0", + "version": "1.4.1", "description": "", "main": "index.js", "scripts": { diff --git a/server/Cargo.toml b/server/Cargo.toml index ded86d14..1497df85 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mnml" -version = "1.4.0" +version = "1.4.1" authors = ["ntr "] [dependencies] From faf54dc3ae4aac6ddaadea13c8c610305d6bf710 Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 9 Sep 2019 16:46:26 +1000 Subject: [PATCH 3/3] game finished find round --- server/src/instance.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/instance.rs b/server/src/instance.rs index 57bc00aa..d6a76c7a 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -384,14 +384,14 @@ impl Instance { fn game_finished(&mut self, game: &Game) -> Result<&mut Instance, Error> { { let current_round = self.rounds - .last_mut() - .expect("instance does not have any rounds"); + .iter_mut() + .filter(|r| r.game_id.is_some()) + .find(|r| r.game_id.unwrap() == game.id); - if current_round.game_id.unwrap() != game.id { - return Err(err_msg("instance does not have a round for this game")); - } - - current_round.finished = true; + match current_round { + Some(c) => c.finished = true, + None => return Err(err_msg("instance does not have a round for this game")), + }; } // if you don't win, you lose