Skip to content

Commit

Permalink
Add no moves handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmarsh committed Feb 26, 2024
1 parent 80bf8f5 commit 1b11a9d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/games/gonnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Move(u8, u64);

impl Move {
const SWAP: Move = Move(0xff, 0);
const NO_MOVE: Move = Move(0xfe, 0);
}

#[derive(Clone, Copy, Serialize, Debug)]
Expand Down Expand Up @@ -121,7 +122,9 @@ impl<const N: usize> State<N> {

#[inline]
fn apply(&mut self, action: &Move) -> Self {
if *action == Move::SWAP {
if *action == Move::NO_MOVE {
self.winner = true;
} else if *action == Move::SWAP {
swap(&mut self.black, &mut self.white);
self.can_swap = false;
} else {
Expand Down Expand Up @@ -178,6 +181,9 @@ impl<const N: usize> Game for Gonnect<N> {
actions.push(Move(index as u8, will_capture.get_raw()))
}
}
if actions.is_empty() {
actions.push(Move::NO_MOVE);
}
}

fn is_terminal(state: &State<N>) -> bool {
Expand Down

0 comments on commit 1b11a9d

Please sign in to comment.