Fix logic error regarding mills
This commit is contained in:
parent
27eb709c02
commit
9b0b9d5680
2 changed files with 18 additions and 12 deletions
17
src/game.rs
17
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<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,12 +824,15 @@ 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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let slot = &board[tx][ty][tz];
|
||||
|
||||
|
|
|
@ -129,16 +129,17 @@ 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
|
||||
{
|
||||
)? {
|
||||
if MillState::None != millstate {
|
||||
found_a_mill = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
|
Loading…
Reference in a new issue