diff --git a/src/game.rs b/src/game.rs index 44c531b..a35a995 100644 --- a/src/game.rs +++ b/src/game.rs @@ -54,7 +54,7 @@ pub enum LogSeverity { Debug, } -const LOG_SEVERITY: LogSeverity = LogSeverity::Basic; +const LOG_SEVERITY: LogSeverity = LogSeverity::Debug; impl PlayerColor { pub fn swap(&mut self) { @@ -483,7 +483,7 @@ impl MillGame { scene: &mut Scene, board: &mut [[[BoardSlot; 3]; 3]; 3], state: &mut GameState, - ) -> Result { + ) -> Result> { Self::log( &format!("move stone ({:?}) to ({:?})", (x, y, z), (tx, ty, tz)), LogSeverity::Debug, @@ -492,9 +492,11 @@ impl MillGame { let slot = &board[x][y][z]; let neighbour = &board[tx][ty][tz]; - if neighbour.state() != BoardSlotState::Empty { + if neighbour.state() != BoardSlotState::Empty + || !Self::is_neighbour((x, y, z), (tx, ty, tz)) + { Self::log("neighbour not empty", LogSeverity::Debug); - return Ok(MillState::None); + return Ok(None); } neighbour.set_state(slot.state()); @@ -544,7 +546,7 @@ impl MillGame { LogSeverity::Debug, ); - Ok(millstate) + Ok(Some(millstate)) } pub fn remove_stone(stone: &mut Stone, slot: &mut BoardSlot, scene: &mut Scene) -> Result<()> { @@ -822,9 +824,12 @@ impl EngineObject for MillGame { match *selected_slot { Some((x, y, z)) => { if Self::is_neighbour((x, y, z), (tx, ty, tz)) { - if Self::move_stone((x,y,z), (tx,ty,tz), scene, board, &mut state)? == MillState::None { - *selected_slot = None; - self.finish_turn(); + if let Some(millstate) + = Self::move_stone((x,y,z), (tx,ty,tz), scene, board, &mut state)? { + if let MillState::None = millstate { + *selected_slot = None; + self.finish_turn(); + } } } } diff --git a/src/simple_ai.rs b/src/simple_ai.rs index 38c0717..12aee9c 100644 --- a/src/simple_ai.rs +++ b/src/simple_ai.rs @@ -129,15 +129,16 @@ impl SimpleAI { let (tx, ty, tz) = (neighbour.x, neighbour.y, neighbour.z); scene.on_scene(|scene| { - if MillGame::move_stone( + if let Some(millstate) = MillGame::move_stone( (x, y, z), (tx, ty, tz), scene, board, state, - )? != MillState::None - { - found_a_mill = true; + )? { + if MillState::None != millstate { + found_a_mill = true; + } } Ok(())