Struct Board

Source
pub struct Board {
    tiles: Vec<TileType>,
    width: usize,
    height: usize,
    routing: Receiver<Option<Vec<Vec<Directions>>>>,
    routing_sender: Sender<Option<Vec<Vec<Directions>>>>,
    routing_note: Notify,
}
Expand description

Representation of the board specified by the board config and used in-game.

A Board is a rectangular grid of Tiles with integer Coordinates.

§Mirroring

Boards are mirrored on the x and the y axis (effectively mirrored on the center point). Because of this, only half of the board has to be stored. When a tile on the other half should be read, the coordinates are simply mirrored:

 A B|C D
_E_F|G_H_
 H G|F E
 D C|B A

§Board Coordinates

The top half of the board is indexed in Left-to-Right (x) and Top-to-Bottom (y) order:

A: x=0 y=0
B: x=1 y=0
E: x=0 y=1

The bottom half continues this scheme:

H: x=0 y=2
G: x=1 y=2
D: x=0 y=3

Note: The top half is the one from which Player 1 sees the game, the bottom half is the one from which Player 2 sees the game.

Fields§

§tiles: Vec<TileType>

The tiles of one half of the board, in order (0,0), (0,width-1), (1,0), …

§width: usize

Width of the entire board

§height: usize

Height of half the board

§routing: Receiver<Option<Vec<Vec<Directions>>>>

For each tile, this stores the directions to take for the shortest path for any other tile.

Structure: Source tile < Target tile Full board coordinates are used.

§routing_sender: Sender<Option<Vec<Vec<Directions>>>>§routing_note: Notify

Implementations§

Source§

impl Board

Source

pub async fn get_dirs(&self, source: Coord, target: Coord) -> Option<Directions>

Get the directions for the shortest path from source to target. Returns None if any of the coordinates are out of bounds or on a rock tile, if source and target overlap. May wait for route calculation to finish.

Source§

impl Board

Source

pub fn new( tiles: Vec<TileType>, width: usize, height: usize, ) -> Result<Self, BoardError>

Creates a new Board from a list of tiles.

tiles must contain the top half of the board, in row-major order, with the halves width and height defined by the parameters of the same name.

This means that [A,B,C,D,E,F] with width=3, height=2 represents the board

A,B,C
D,E,F
F,E,D
C,B,A

The Board will be validated, that is, it will be checked whether it complies to the following rules:

  • tiles must have the correct length
  • There must be at least 8 grass tiles per board half
  • The entire board must be strictly connected: Every non-rock tile must be reachable from every other non-rock tile.

This function returns Err when the board does not fulfill any of the above conditions.

Source

fn new_unchecked(tiles: Vec<TileType>, width: usize, height: usize) -> Self

See the docs on new for input format of tiles. This function does not do any of the checks new does, and may result in invalid state. It is only intended for test cases which specifically don’t care about some of the conditions new guarantees.

Source

pub fn new_from_arrays<const WIDTH: usize, const HEIGHT: usize>( tiles: [[TileType; WIDTH]; HEIGHT], ) -> Result<Self, BoardError>

Removes the possibility of an InvalidLength error by using arrays of known sizes. Input is expected to be an array of rows 0 to height-1, where each row contains the tiles 0 to width-1 of that row.

You may also want to read the docs on new for possible errors this function can return.

Source

fn new_from_arrays_unchecked<const WIDTH: usize, const HEIGHT: usize>( tiles: [[TileType; WIDTH]; HEIGHT], ) -> Self

See the docs on new_from_arrays and new_unchecked.

Source

pub fn get(&self, pos: Coord) -> Option<TileType>

Returns the tile at position pos, or None if pos is out of bounds.

Supports getting tiles from anywhere on the full board, meaning that this function will return Some(_) if and only if
pos.x < self.get_size().width && pos.y < self.get_size().height.

Source

pub fn get_size(&self) -> BoardSize

Returns the size of the full board.

height will always be an even number, because the full board is two half boards, both of which have the same height.

You may want to see the documentation of Board.

Source

pub fn iter_half(&self) -> impl Iterator<Item = (Coord, TileType)>

Iterates through the rows of the top half of this board.

Iteration order is (0,0) to (0,1) to (0,width-1) to (1,0) to (1,1) and so on, stopping when half the board has been traversed (0 <= y < self.get_size().height/2).

A 4x4 board would be traversed in the following order:

0123
4567
----
----

See also: iter_second_half_mirrored and iter_second_half_continuing

Source

pub fn iter_second_half_mirrored( &self, ) -> impl Iterator<Item = (Coord, TileType)>

Iterates through the rows of the bottom half of this board, returning the same tiles as iter_half in the same order, just with different coordinates.

Iteration order is (height-1,width-1) to (height-1,0), …, (h,width-1) to (h,0). where h is self.get_size().height/2, or the height of a half-board.

A 4x4 board would be traversed in the following order:

----
----
7654
3210

See also: iter_half and iter_second_half_continuing

Source

pub fn iter_second_half_continuing( &self, ) -> impl Iterator<Item = (Coord, TileType)>

Iterates through the rows of the bottom half of this board, continuing in the same coordinate order as iter_half.

Iteration order is (h,0) to (h,1) to (h,width-1) to (h+1,0) to (h+1,1) and so on, where h is self.get_size().height/2, or the height of a half-board.

A 4x4 board would be traversed in the following order:

----
----
0123
4567

See also: iter_half and iter_second_half_mirrored

Source

pub fn is_line_of_sight_blocked(&self, from: Coord, to: Coord) -> bool

Source

fn validate(&self) -> Result<(), BoardError>

Trait Implementations§

Source§

impl Debug for Board

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Board

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Board

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !Freeze for Board

§

impl !RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl !UnwindSafe for Board

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V