pub struct Ruleset { /* private fields */ }
Expand description
Contains functions which describe the rules of a chess game
Can be used to alter the rules of the game
(e.g. for variants like Chess960)
Each Ruleset
has to implement specific functions.
Implementations§
Source§impl Ruleset
impl Ruleset
pub const fn new( generate_initial_position: fn() -> Position, get_possible_turns: fn(&Position) -> Vec<Turn>, execute_turn: fn(&Position, &Turn) -> Position, game_over_check: fn(&Position) -> Option<GameResult>, is_in_check: fn(&Position, PlayerColor) -> bool, ) -> Self
Sourcepub fn generate_initial_position(&self) -> Position
pub fn generate_initial_position(&self) -> Position
Implementations of this Ruleset
function must place the initial position of the pieces on the board
and return the initial position.
Sourcepub fn get_possible_turns(&self, position: &Position) -> Vec<Turn>
pub fn get_possible_turns(&self, position: &Position) -> Vec<Turn>
Implementations of this Ruleset
function must return a vector of all possible turns
Sourcepub fn execute_turn(&self, position: &Position, turn: &Turn) -> Position
pub fn execute_turn(&self, position: &Position, turn: &Turn) -> Position
Implementations of this Ruleset
function must execute a turn and return the new position.
For any given position, each Turn
which is returned by the get_possible_turns
function
for the same position must be executable by this function.
Sourcepub fn game_over_check(&self, position: &Position) -> Option<GameResult>
pub fn game_over_check(&self, position: &Position) -> Option<GameResult>
Implementations of this Ruleset
function must check if the game is over
and return the result of the game.
Sourcepub fn is_in_check(
&self,
position: &Position,
player_color: PlayerColor,
) -> bool
pub fn is_in_check( &self, position: &Position, player_color: PlayerColor, ) -> bool
Implementations of this Ruleset
function must check if the given player is in check