Struct Thud

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

Stores the current state of a game of Thud

Implementations§

Source§

impl Thud

Source

pub fn new() -> Self

Get a Thud ready to be played!

Source

pub fn turn(&self) -> Option<Player>

Find which player’s turn it is.

Will return Some(Player) if the game is still in progress, or if the game is ended None will be returned.

Source

pub fn board(&self) -> Board

Get a copy of the current Board

Source

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

Wrapper for Board::winner()

Source

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

Wrapper for Board::score()

Source

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

Move a piece of the player whose turn it is

On a Dwarf turn, the turn will automatically tick over, on a Troll turn, the player may make a capture afterward with .troll_cap(). Should the troll player not wish to make a capture, they may call .troll_cap() with an empty Vec.

Will pass errors from Board.dwarf_move() and Board.troll_move().

Source

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

Attack with a piece of the player whose turn it is

This can only be taken as the first action of the player’s turn, otherwise Err(ThudError::BadAction) will be returned.

On a Dwarf turn, it will automatically tick over to the next turn, on a Troll turn, at least one capture must be made afterward with .troll_cap().

Will pass errors from Board.dwarf_hurl() and Board.troll_shove().

Source

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

Capture a number of dwarves with a troll

This may only be called after a move or a shove/attack on a troll player’s turn.

If the previous action was a shove/attack then targets must contain at least 1 valid dwarf to take, otherwise Err(ThudError::IllegalMove) will be returned and the method must be called again before play can continue.

Otherwise, the turn will be ticked over automatically.

Auto Trait Implementations§

§

impl Freeze for Thud

§

impl RefUnwindSafe for Thud

§

impl Send for Thud

§

impl Sync for Thud

§

impl Unpin for Thud

§

impl UnwindSafe for Thud

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> 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, 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.