[−][src]Struct thud::Board
Represents the positioning of the Thud Pieces on the 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]
pub fn get_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.get_army(Piece::Thudstone); assert_eq!(stone[0].value(), (7, 7));
pub fn get_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]
&mut self,
troll: Coord,
target: Coord
) -> Result<(), ThudError>
Move a troll.
Returns Err(ThudError::IllegalMove) if:
- The
trollsquare is notPiece::Troll - The
targetsquare is notPiece::Empty - The
targetsquare is more than 1 squares away from thetrollsquare
pub fn troll_shove(
&mut self,
troll: Coord,
target: Coord
) -> Result<(), ThudError>[src]
&mut self,
troll: Coord,
target: Coord
) -> Result<(), ThudError>
"Shove" a troll.
Returns Err(ThudError::IllegalMove) if:
- The
trollsquare is notPiece::Troll - The
targetsquare is notPiece::Empty - There are no
Piece::Dwarfs adjacent to thetargetsquare
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]
&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.
pub fn dwarf_move(
&mut self,
dwarf: Coord,
target: Coord
) -> Result<(), ThudError>[src]
&mut self,
dwarf: Coord,
target: Coord
) -> Result<(), ThudError>
Move a dwarf.
Returns Err(ThudError::IllegalMove) if:
- square
dwarfis notPiece::Dwarf - square
targetis notPiece::Empty
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]
&mut self,
dwarf: Coord,
target: Coord
) -> Result<(), ThudError>
"Hurl" a dwarf.
Returns Err(ThudError::IllegalMove) if:
- square
dwarfis notPiece::Dwarf - square
targetis not eitherPiece::EmptyorPiece::Troll
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]
pub fn winner(&self) -> Option<Player>[src]
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,