Expand description
Core rules implementation for Voronoi Go. Machine translated from the original implementation playable at voronoigo.com.
This small section of docs was written by a human, but the rest can be assumed to be machine-written unless stated otherwise. All of the code was also written by a machine but reviewed by a human and verified against output from the original implementation. For more information and support for using this implementation in non-rust languages, visit the repo. For questions left unanswered by these docs, you can also join the discord and ask there. I am happy to help you out.
You’ll mainly want to interact with the Game struct to play moves, calculate
territory, compute cuttability, etc. Code sample:
use voronoi_go::{Game, Point};
// A board nine stones across is 18 units wide: coordinates are stone radii.
let mut game = Game::new(18.0);
game.try_move(Point::new(4.0, 4.0))?; // black
game.try_move(Point::new(14.0, 14.0))?; // white
assert_eq!(game.stones().len(), 2);
// Territory is area, and the two shares sum to the whole board.
let area = game.territory();
assert!((area.black() + area.white() - 18.0 * 18.0).abs() < 1e-9);
// Undo restores the previous state bit for bit.
game.undo_move();
assert_eq!(game.stones().len(), 1);§Feature flags
Both are on by default but are optional.
svg—Game::dump_svgandAliveZone::to_svg, which write a standalone board image. Items behind it are labelled on docs.rs.serde—Serialize/Deserializeon the public data types. Required by the engine binary and the Python bindings.
Re-exports§
pub use alive_zone::AliveZone;pub use alive_zone::DeadZoneError;pub use alive_zone::ZoneError;pub use connectivity::BoardEdge;pub use connectivity::Connectivity;pub use connectivity::CutError;pub use connectivity::CutKind;pub use game::BoardError;pub use game::Commit;pub use game::DeltaError;pub use game::Game;pub use game::GameOverError;pub use game::GameStatus;pub use game::StonePlayError;pub use voronoi::Voronoi;pub use voronoi::VoronoiGroup;
Modules§
- alive_
zone - The alive zone: where a stone centre may still be placed.
- connectivity
- Cutting: which same-colour pairs an enemy cannot wedge itself between.
- game
- The rules, and the board they act on.
- geometry
- Plane geometry: the shapes the board is described with, and the predicates and distance queries over them.
- voronoi
- Territory: the Voronoi diagram of the stones, merged into contiguous same-colour groups.
Structs§
- Game
Delta - One turn’s change to the board: a stone placed (or not, for a pass) and the stones that placement captured.
- PerColor
- A pair of values, one per
Color. - Point
- A position on the board, in units where a stone has radius
STONE_RADIUS. - Point
Key - The identity of a
Point: the exact bit patterns of its coordinates. - SegId
- Identifies one segment of a shape’s clipped outline.
- ShapeId
- Identifies one shape — a dead-zone circle or a board edge — that the playable area is clipped against.
- Stone
- A stone on the board: a disc of radius
STONE_RADIUScentred onposition. - StoneId
- Identifies a stone within one game.
Enums§
- Color
- A player.
- Structure
Error - Something the clipping structure guarantees, found not to hold.
Constants§
- EPSILON
- Slack for magnitude comparisons that guard a genuine degeneracy — a near-tangency whose square root would otherwise go negative, or a divisor whose sign is noise.
- STONE_
DIAMETER - Centre-to-centre distance below which two stones cannot both exist: a stone carves a disc of this radius out of the playable area.
- STONE_
RADIUS - Radius of a stone, and the unit all board coordinates are expressed in.