[][src]Struct thud::Board

pub struct Board { /* fields omitted */ }

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.

Methods

impl Board[src]

pub fn fresh() -> Self[src]

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

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

Put a Piece on the board.

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

Find what Piece is at the Coord specified.

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

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

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));

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

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.

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

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

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

"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

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

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.

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

Move a dwarf.

Returns Err(ThudError::IllegalMove) if:

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

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

"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

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

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

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

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

Returns:

pub fn score(&self) -> (usize, usize)[src]

Get the scores of each player

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

Trait Implementations

impl Clone for Board[src]

impl Copy for Board[src]

impl Debug for Board[src]

impl Default for Board[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.