Fix logic error regarding mills

This commit is contained in:
hodasemi 2023-05-12 09:04:48 +02:00
parent 27eb709c02
commit 9b0b9d5680
2 changed files with 18 additions and 12 deletions

View file

@ -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<MillState> {
) -> Result<Option<MillState>> {
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();
}
}
}
}

View file

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