Struct Board

Source
pub struct Board { /* private fields */ }
Expand description

A configuration of Thud Pieces on a Thud board

Note: Board is not aware of the whole state of the game, only the position of the pieces. As a result, the movement methods provided only perform checks according to the pieces on the board, but they will not check whether the move is valid in terms of turn progress - you should use the methods on Thud for that.

Implementations§

Source§

impl Board

Source

pub fn fresh() -> Self

Get a “fresh” Board, with Pieces placed in the default positions for thud.

Source

pub fn place(&mut self, square: Coord, piece: Piece)

Put a Piece on the board.

Source

pub fn get(&self, square: Coord) -> Piece

Find what Piece is at the Coord specified.

Source

pub fn full_raw(&self) -> [[Piece; 15]; 15]

Source

pub fn army(&self, piece_type: Piece) -> Vec<Coord>

Return a vector of all the Coords of squares occupied by the given piece type.

use thud::{Board, Piece, Coord};

let board = Board::fresh();
let stone = board.army(Piece::Thudstone);

assert_eq!(stone[0].value(), (7, 7));
Source

pub fn adjacent(&self, square: Coord) -> Vec<(Coord, Piece)>

Get a vector of valid Coords in the 8 possible adjacent squares to the one given.

Coordinates out of board bounds will not be included.

Source

pub fn troll_move( &mut self, troll: Coord, target: Coord, ) -> Result<(), ThudError>

Move a troll.

Returns Err(ThudError::IllegalMove) if:

  • The troll square is not Piece::Troll
  • The target square is not Piece::Empty
  • The target square is more than 1 squares away from the troll square
Source

pub fn troll_shove( &mut self, troll: Coord, target: Coord, ) -> Result<(), ThudError>

“Shove” a troll.

Returns Err(ThudError::IllegalMove) if:

Returns Err(ThudError::Obstacle) if the target square is obstructed

Returns Err(ThudError::LineTooShort) if the distance to the target square is larger than the length of the line of trolls going in the other direction

Source

pub fn troll_capture( &mut self, troll: Coord, targets: Vec<Direction>, ) -> Result<usize, ThudError>

Use a troll to selectively capture dwarves around it.

targets should be a Vec of Directions in which to capture; if there is a dwarf above your troll and you wish to capture it then targets should contain Direction::Up.

Note that any invalid (out of board limits) or duplicate Directions will be ignored.

Returns Err(ThudError::IllegalMove) if the piece at troll is not Piece::Troll.

Source

pub fn dwarf_move( &mut self, dwarf: Coord, target: Coord, ) -> Result<(), ThudError>

Move a dwarf.

Returns Err(ThudError::IllegalMove) if:

Returns Err(ThudError::Obstacle) if there is a piece in the way.

Source

pub fn dwarf_hurl( &mut self, dwarf: Coord, target: Coord, ) -> Result<(), ThudError>

“Hurl” a dwarf.

Returns Err(ThudError::IllegalMove) if:

Returns Err(ThudError::Obstacle) if there is a piece in the way.

Returns Err(ThudError::LineTooShort) if the distance to the target square is larger than the length of the line of dwarves going in the other direction

Source

pub fn available_moves(&self, loc: Coord) -> Vec<Coord>

Get a Vec of Coords that the piece at loc can make

Source

pub fn winner(&self) -> Option<EndState>

Find if there is a winner or the game is over.

Returns:

Source

pub fn score(&self) -> (usize, usize)

Get the scores of each player

Given in format (<dwarf score>, <troll score>)

Trait Implementations§

Source§

impl Clone for Board

Source§

fn clone(&self) -> Board

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Board

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Board

Source§

fn default() -> Board

Returns the “default value” for a type. Read more
Source§

impl Copy for Board

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnwindSafe for Board

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.