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(())