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
impl Board
Sourcepub fn fresh() -> Self
pub fn fresh() -> Self
Get a “fresh” Board, with Pieces placed in the default positions for thud.
pub fn full_raw(&self) -> [[Piece; 15]; 15]
Sourcepub fn army(&self, piece_type: Piece) -> Vec<Coord>
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));Sourcepub fn adjacent(&self, square: Coord) -> Vec<(Coord, Piece)>
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.
Sourcepub fn troll_move(
&mut self,
troll: Coord,
target: Coord,
) -> Result<(), ThudError>
pub fn troll_move( &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
Sourcepub fn troll_shove(
&mut self,
troll: Coord,
target: Coord,
) -> Result<(), ThudError>
pub fn troll_shove( &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
Sourcepub fn troll_capture(
&mut self,
troll: Coord,
targets: Vec<Direction>,
) -> Result<usize, ThudError>
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.
Sourcepub fn dwarf_move(
&mut self,
dwarf: Coord,
target: Coord,
) -> Result<(), ThudError>
pub fn dwarf_move( &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.
Sourcepub fn dwarf_hurl(
&mut self,
dwarf: Coord,
target: Coord,
) -> Result<(), ThudError>
pub fn dwarf_hurl( &mut self, dwarf: Coord, target: Coord, ) -> Result<(), ThudError>
“Hurl” a dwarf.
Returns Err(ThudError::IllegalMove) if:
- square
dwarfis notPiece::Dwarf - square
targetis 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
Sourcepub fn available_moves(&self, loc: Coord) -> Vec<Coord>
pub fn available_moves(&self, loc: Coord) -> Vec<Coord>
Get a Vec of Coords that the piece at loc can make
Sourcepub fn winner(&self) -> Option<EndState>
pub fn winner(&self) -> Option<EndState>
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 drawNoneif the board still has moves to play