Struct Ruleset

Source
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

Source

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

Source

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.

Source

pub fn get_possible_turns(&self, position: &Position) -> Vec<Turn>

Implementations of this Ruleset function must return a vector of all possible turns

Source

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.

Source

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.

Source

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

Trait Implementations§

Source§

impl Clone for Ruleset

Source§

fn clone(&self) -> Ruleset

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.