cgt/short/impartial/impartial_game.rs
1//! Impartial game - both players have the same moves
2
3use crate::numeric::nimber::Nimber;
4
5/// Impartial game
6pub trait ImpartialGame: Sized {
7 /// Get a list of moves from the position
8 fn moves(&self) -> Vec<Self>;
9
10 /// Calculate the Nim value of the position
11 fn nim_value(&self) -> Nimber {
12 let moves = self.moves();
13 let mut game_moves = Vec::with_capacity(moves.len());
14 for m in moves {
15 game_moves.push(m.nim_value());
16 }
17 Nimber::mex(game_moves)
18 }
19}