Add a crate to start defining 2-d grids
This commit is contained in:
parent
7abb33c4fe
commit
55e0c98db3
|
@ -1219,6 +1219,10 @@ dependencies = [
|
|||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gaming-grid"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "gcd"
|
||||
version = "2.3.0"
|
||||
|
|
|
@ -11,6 +11,7 @@ members = [
|
|||
"emseries",
|
||||
"file-service",
|
||||
"fluent-ergonomics",
|
||||
"gaming-grid",
|
||||
"geo-types",
|
||||
"gm-control-panel",
|
||||
"hex-grid",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "gaming-grid"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,61 @@
|
|||
// The gaming grid is a collection of coordinates and grouping utilities that I have developed from
|
||||
// doing Advent of Code and from building the hex map coordinate system.
|
||||
//
|
||||
// This initial version works with square spaces, with the intent to be unified with the hexagonal
|
||||
// coordinates.
|
||||
|
||||
/// A Group is a collection of locations that create a group, in whatever that means for a game. In
|
||||
/// Go, this means a group of stones. In Advent of Code 2023 Day 3, that would be a "part" or a
|
||||
/// "component".
|
||||
///
|
||||
/// AddrType is the data type of the addresses used in the coordinate system.
|
||||
trait Group<AddrType> {
|
||||
/// Return a list of all coordinates that make up the body of a group.
|
||||
fn body(&self) -> dyn Iterator<Item = Coordinate<AddrType>>;
|
||||
|
||||
/// Return a list of all coordinates within x distance of the border of a group. By definition,
|
||||
/// this will not include any coordinates within the group.
|
||||
fn halo(&self, distance: u32) -> dyn Iterator<Item = Coordinate<AddrType>>;
|
||||
}
|
||||
|
||||
struct Coordinate<T> {
|
||||
row: T,
|
||||
col: T,
|
||||
}
|
||||
|
||||
/// The rules by which objects are adjacent to one another.
|
||||
enum Adjacency {
|
||||
/// Only calculate adjacency according to those objects that are on the same row.
|
||||
Horizontal,
|
||||
|
||||
/// Only calculate adjacency according to those objects that are in the same column.
|
||||
Vertical,
|
||||
|
||||
/// Calculate adjacency according to orthogonal rules. Two objects are adjacent if they are in
|
||||
/// the same row or the same column.
|
||||
Orthogonal,
|
||||
|
||||
/// Calculate adjacency according to how the King moves in Chess: one space in any direction is
|
||||
/// adjacent.
|
||||
Chess,
|
||||
}
|
||||
|
||||
/// Which set of rules to use when calculating a distance on a square board.
|
||||
enum DistanceTraversal {
|
||||
/// Taxicab distance is calculated exactly along orthogonal lines, in the way that a taxi would
|
||||
/// have to move in a city that is on a perfect square.
|
||||
Taxicab,
|
||||
|
||||
/// Chess rules allow for diagonal movement in addition to handicap, similar to how a Queen
|
||||
/// moves.
|
||||
Chess,
|
||||
|
||||
/// Circular rules calculate actual distance based on a true circular calculation. Unlike Chess
|
||||
/// rules (where a distance of 8 takes a queen from one corner of the board to another), under
|
||||
/// Circular rules a distance of 8 along the diagonal would only take one between five and six
|
||||
/// spaces along both the X and Y axis.
|
||||
Circular,
|
||||
}
|
||||
|
||||
// bounding function: filters out coordinates that are outside of the bounds of the board. What
|
||||
// exactly that means depends on the bounding function and the extra rules injected into it.
|
Loading…
Reference in New Issue