# Struct hexgame::Board

``pub struct Board { /* private fields */ }``
Expand description

`Board` represents the Hex board and all placed stones.

The `play` method can be used to place stones on the board. Note that `Board` has no notion of a current player and will allow to place any amount of stones in any color.

A nice human-readable format can be obtained via the `Display` trait:

``````use hexgame::{Board, Color, Coords};
let mut board = Board::new(5);
board.play(Coords::new(1, 3), Color::Black);
board.play(Coords::new(0, 2), Color::White);
println!("{}", board);``````

will output

`````` a  b  c  d  e
1\.  .  ○  .  .\1
2\.  .  .  ●  .\2
3\.  .  .  .  .\3
4\.  .  .  .  .\4
5\.  .  .  .  .\5
a  b  c  d  e``````

## Implementations

Create a new board with the given size. Boards are always square.

This method will panic if the size is not bounded by `MIN_BOARD_SIZE` and `MAX_BOARD_SIZE`.

Load a board from a `StoneMatrix`.

Convert this board to a `StoneMatrix`.

Return the size of this board. Boards are always square.

Return the color at the given coordinates or edge. If no stone has been placed in the given cell, this method will return None.

Return all empty cells.

Return all neighbors of the given cell, including edges that border the cell.

Example:

`````` a  b  c
1\.  .  .\1
2\.  .  .\2
3\●  .  .\3
a  b  c``````

Let’s compute the neighbors of the stone in the bottom left corner.

``````let board = Board::new(3);
let neighbors: Vec<CoordsOrEdge> = board.get_neighbors(Coords::new(2, 0)).collect();
assert_eq!(neighbors, vec![
CoordsOrEdge::Edge(Edge::Left),
CoordsOrEdge::Coords("a2".parse().unwrap()),
CoordsOrEdge::Coords("b2".parse().unwrap()),
CoordsOrEdge::Coords("b3".parse().unwrap()),
CoordsOrEdge::Edge(Edge::Bottom),
]);``````

Return all bridges that are attacked by a given stone.

A bridge is the most common virtual connection pattern in Hex. In the following example, White cannot prevent Black from connecting their stones: If White places a stone between the black stones, Black may just choose the other cell between the black stones.

`````` a  b  c
1\.  .  .\1
2\.  .  ●\2
3\●  .  .\3
a  b  c``````

This method assumes that one player has just played on `coords`. It computes all bridges of the other player that are being attacked by this move. For each attacked bridge, the free cell in the middle is returned. If the attacked player places a stone on this cell, the bridge will be fully connected despite the attack.

This method will also return bridges that connect a stone to one of the player’s own edges (see the example below).

The color at `coords` determines the attacking player (if the cell at `coords` is empty, this method returns an empty list.)

Example:

`````` a  b  c
1\.  .  .\1
2\.  .  ●\2
3\●  ○  .\3
a  b  c``````

The attacked bridges on this board and coords=b3 are:

• a3 - b2 - c2
• c2 - c3 - bottom edge

Thus, this method would return the middle cells [b2, c3].

## Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from `source`. Read more

Pretty human-readable format for boards.

Example:

`````` a  b  c  d  e
1\.  .  .  .  .\1
2\.  ●  .  ○  .\2
3\.  .  ●  .  .\3
4\.  .  .  ○  .\4
5\.  .  .  .  .\5
a  b  c  d  e``````

## Blanket Implementations

Gets the `TypeId` of `self`. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a `String`. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.