[−][src]Struct thud::Board
A configuration of Thud Piece
s 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 Piece
s 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 full_raw(&self) -> [[Piece; 15]; 15]
[src]
pub fn army(&self, piece_type: Piece) -> Vec<Coord>
[src]
Return a vector of all the Coord
s 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 Coord
s 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
troll
square is notPiece::Troll
- The
target
square is notPiece::Empty
- The
target
square is more than 1 squares away from thetroll
square
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
troll
square is notPiece::Troll
- The
target
square is notPiece::Empty
- There are no
Piece::Dwarf
s adjacent to thetarget
square
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 Direction
s 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
Direction
s 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
dwarf
is notPiece::Dwarf
- square
target
is 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
dwarf
is notPiece::Dwarf
- square
target
is notPiece::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]
Get a Vec
of Coord
s 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:
Some(EndState::Won(Player))
if a player has won the matchSome(EndState::Draw)
if the match is a drawNone
if the board still has moves to play
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]
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,