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=1The bottom half continues this scheme:
H: x=0 y=2
G: x=1 y=2
D: x=0 y=3Note: 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: usizeWidth of the entire board
height: usizeHeight 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: NotifyImplementations§
Source§impl Board
impl Board
Sourcepub fn new(
tiles: Vec<TileType>,
width: usize,
height: usize,
) -> Result<Self, BoardError>
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,AThe Board will be validated, that is, it will be checked whether it complies to the following rules:
tilesmust 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.
Sourcepub fn new_from_arrays<const WIDTH: usize, const HEIGHT: usize>(
tiles: [[TileType; WIDTH]; HEIGHT],
) -> Result<Self, BoardError>
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.
Sourcefn new_from_arrays_unchecked<const WIDTH: usize, const HEIGHT: usize>(
tiles: [[TileType; WIDTH]; HEIGHT],
) -> Self
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.
Sourcepub fn get(&self, pos: Coord) -> Option<TileType>
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.
Sourcepub fn get_size(&self) -> BoardSize
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.
Sourcepub fn iter_half(&self) -> impl Iterator<Item = (Coord, TileType)>
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
Sourcepub fn iter_second_half_mirrored(
&self,
) -> impl Iterator<Item = (Coord, TileType)>
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
3210See also: iter_half and iter_second_half_continuing
Sourcepub fn iter_second_half_continuing(
&self,
) -> impl Iterator<Item = (Coord, TileType)>
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
4567See also: iter_half and iter_second_half_mirrored