pub struct Board {
cells: Vec<Square>,
pub width: usize,
pub height: usize,
pub current_turn: Team,
}
Expand description
Single state of a checkers board
Fields
cells: Vec<Square>
1D backing array of board squares for the 2D game board
width: usize
height: usize
current_turn: Team
Implementations
sourceimpl Board
impl Board
sourcepub fn cell_mut(&mut self, idx: usize) -> &mut Square
pub fn cell_mut(&mut self, idx: usize) -> &mut Square
Get a mutable reference to a board square by 1D array index
sourcepub fn adjacent_indices(&self, idx: BrdIdx) -> Option<Vec<usize>>
pub fn adjacent_indices(&self, idx: BrdIdx) -> Option<Vec<usize>>
Get the 1D array indices for the diagonally adjacent squares of a given board square
Returns
None
: If the given square is unplayable
Some(Vec
sourcepub fn adjacent_dir(&self, idx: BrdIdx) -> Option<Direction<Square>>
pub fn adjacent_dir(&self, idx: BrdIdx) -> Option<Direction<Square>>
Get a Direction
structure for the diagonally adjacent squares of a given board square
Similar to the Board::adjacent_indices
function with differently formatted results
Returns
None
: If the given square is unplayable
Some(DirectionDirection
structure for the diagonally adjacent squares.
sourcepub fn filter_indices(
&self,
idx: BrdIdx,
player: Team,
indices: Vec<usize>
) -> Vec<usize>
pub fn filter_indices(
&self,
idx: BrdIdx,
player: Team,
indices: Vec<usize>
) -> Vec<usize>
Filter an array of diagonal indices (Like those from Board::adjacent_indices
, Board::jumpable_indices
) for those that are legal for a team’s man, i.e. solely up or down the board
pub fn player_adjacent_indices(
&self,
idx: BrdIdx,
player: Team
) -> Option<Vec<usize>>
sourcepub fn jumpable_indices(&self, idx: BrdIdx) -> Option<Vec<usize>>
pub fn jumpable_indices(&self, idx: BrdIdx) -> Option<Vec<usize>>
Get the 1D array indices for the diagonally jumpable squares of a given board square
Returns
None
: If the given square is unplayable
Some(Vec
sourcepub fn jumpable_dir(&self, idx: BrdIdx) -> Option<Direction<Square>>
pub fn jumpable_dir(&self, idx: BrdIdx) -> Option<Direction<Square>>
Get a Direction
structure for the diagonally jumpable squares of a given board square
Similar to the Board::jumpable_indices
function with differently formatted results
Returns
None
: If the given square is unplayable
Some(DirectionDirection
structure for the diagonally jumpable squares.
pub fn player_jumpable_indices(
&self,
idx: BrdIdx,
player: Team
) -> Option<Vec<usize>>
sourceimpl Board
impl Board
sourcepub fn set_cell(&mut self, idx: usize, square: Square)
pub fn set_cell(&mut self, idx: usize, square: Square)
Get a copy of a board square by 1D array index
sourcepub fn cell_index(&self, row: usize, col: usize) -> usize
pub fn cell_index(&self, row: usize, col: usize) -> usize
Transform a 2D row/column board index into a single 1D index for use with Board::cells
sourcepub fn cell_idx(&self, idx: BrdIdx) -> usize
pub fn cell_idx(&self, idx: BrdIdx) -> usize
Similar to Board::cell_index
but with a BrdIdx
instead of separate indices. Transform a 2D row/column board index into a single 1D index for use with Board::cells
sourcepub fn board_index(&self, idx: usize) -> BrdIdx
pub fn board_index(&self, idx: usize) -> BrdIdx
Transform a 1D array index (for Board::cells
) into a 2D game board index (by row/col)
sourcepub fn can_move(&self, from: BrdIdx, to: BrdIdx) -> Moveable
pub fn can_move(&self, from: BrdIdx, to: BrdIdx) -> Moveable
Check whether a move given by source and destination indices is legal
sourcepub fn validate_man_move(
&self,
from: BrdIdx,
to: BrdIdx,
from_square_occupant: Piece
) -> Moveable
pub fn validate_man_move(
&self,
from: BrdIdx,
to: BrdIdx,
from_square_occupant: Piece
) -> Moveable
Check that given move trajectory is valid for a man piece
sourcepub fn validate_king_move(
&self,
from: BrdIdx,
to: BrdIdx,
from_square_occupant: Piece
) -> Moveable
pub fn validate_king_move(
&self,
from: BrdIdx,
to: BrdIdx,
from_square_occupant: Piece
) -> Moveable
Check that given move trajectory is valid for a king piece
sourcepub fn jumpee_idx(&self, from: BrdIdx, to: BrdIdx) -> usize
pub fn jumpee_idx(&self, from: BrdIdx, to: BrdIdx) -> usize
Get cell index of jumpee square given from and to locations
sourcepub fn cells(&self) -> *const Square
pub fn cells(&self) -> *const Square
Get a pointer to the backing array of board squares, Board::cells
sourcepub fn num_pieces(&self) -> usize
pub fn num_pieces(&self) -> usize
Get the number of remaining pieces
sourcepub fn num_player(&self, team: Team) -> usize
pub fn num_player(&self, team: Team) -> usize
Get the number of remaining pieces for a player
sourcepub fn cell_state(&self, idx: usize) -> SquareState
pub fn cell_state(&self, idx: usize) -> SquareState
Get the state of a board square by 1D array index
sourcepub fn apply_move(&self, from: BrdIdx, to: BrdIdx) -> Board
pub fn apply_move(&self, from: BrdIdx, to: BrdIdx) -> Board
Get new board derived from current with given move applied
sourcepub fn apply_jump(&self, from: BrdIdx, to: BrdIdx) -> Board
pub fn apply_jump(&self, from: BrdIdx, to: BrdIdx) -> Board
Get new board derived from current with given jump applied
sourcepub fn king_row_idx(&self) -> usize
pub fn king_row_idx(&self) -> usize
Get row index for current team, top row for black, bottom row for white
sourceimpl Board
impl Board
sourcepub fn validate_jumpee(jumpee: Square, from_occ: Piece) -> Moveable
pub fn validate_jumpee(jumpee: Square, from_occ: Piece) -> Moveable
Unwrap the jumpee piece from the square and Board::check_jumpee_team
with Moveable
response
sourcepub fn check_jumpee_team(from: Piece, jumpee: Piece) -> bool
pub fn check_jumpee_team(from: Piece, jumpee: Piece) -> bool
Check that the source piece and the jumpee are of opposing teams
sourcefn check_kinged(new_board: &mut Board, idx: BrdIdx)
fn check_kinged(new_board: &mut Board, idx: BrdIdx)
Check and apply king strength
Trait Implementations
sourceimpl FromWasmAbi for Board
impl FromWasmAbi for Board
sourceimpl IntoWasmAbi for Board
impl IntoWasmAbi for Board
sourceimpl OptionFromWasmAbi for Board
impl OptionFromWasmAbi for Board
sourceimpl OptionIntoWasmAbi for Board
impl OptionIntoWasmAbi for Board
sourceimpl RefFromWasmAbi for Board
impl RefFromWasmAbi for Board
type Anchor = Ref<'static, Board>
type Anchor = Ref<'static, Board>
The type that holds the reference to Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous. Read more
sourceunsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
Recover a Self::Anchor
from Self::Abi
. Read more
sourceimpl RefMutFromWasmAbi for Board
impl RefMutFromWasmAbi for Board
sourceimpl WasmDescribe for Board
impl WasmDescribe for Board
impl Eq for Board
impl StructuralEq for Board
impl StructuralPartialEq for Board
Auto Trait Implementations
impl RefUnwindSafe for Board
impl Send for Board
impl Sync for Board
impl Unpin for Board
impl UnwindSafe for Board
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
sourcefn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
. Read more