From a71e5b180d4e0d0d7cc274229c0326b260506819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20Witters=C3=B8?= Date: Sat, 24 Feb 2024 21:55:55 +0100 Subject: [PATCH] Finish take_tiles market implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Løvbrøtte Olsen Co-authored-by: Adrian Gunnar Lauterer --- src/azul.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/azul.rs b/src/azul.rs index 8f25aff..4bb24f7 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -316,7 +316,7 @@ impl GameState { (c, s, _) if self.get_color(s, c) == 0 => { return Err(MoveErr::Color("Source does not contain that color")) } - (_, Source::Factory(f), _) if f >= self.factories.len() => { + (_, Source::Factory(f), _) if f > self.factories.len() => { return Err(MoveErr::Src("Not a valid factory")) } (_, _, Destination::PatternLine(l)) @@ -400,10 +400,11 @@ impl GameState { self.market.start -= 1; player.floor.start += 1; } + let _ = self.market.add_color(color, -(amount as isize)); } Source::Factory(f) => { let factory = &mut self.factories[f]; - factory.add_color(color, -(amount as isize)).unwrap(); + let _ = factory.add_color(color, -(amount as isize)); self.market += *factory; factory.clear(); } @@ -538,13 +539,17 @@ impl TileSetWithStart { Color::Blue => self.blue, Color::Yellow => self.yellow, Color::Red => self.red, - Color::Black => self.white, - Color::White => self.black, + Color::Black => self.black, + Color::White => self.white, } } fn add_color(&mut self, color: Color, n: isize) -> Result<(), &'static str> { match color { + Color::Start if n == 1 && self.start == 0 => { + self.start = usize::checked_add_signed(self.white, n).ok_or("would overflow")? + } + Color::Start => return Err("Tried to add more than 1 start tile to TileSet"), Color::Blue => { self.blue = usize::checked_add_signed(self.blue, n).ok_or("would overflow!")? } @@ -560,10 +565,6 @@ impl TileSetWithStart { Color::White => { self.white = usize::checked_add_signed(self.white, n).ok_or("would overflow")? } - Color::Start if n == 1 && self.start == 0 => { - self.start = usize::checked_add_signed(self.white, n).ok_or("would overflow")? - } - Color::Start => return Err("Tried to add more than 1 start tile to TileSet"), } Ok(())