gridit 0.1.0

2D grid library utilizing the fun of iterators
Documentation
  • Coverage
  • 52.38%
    22 out of 42 items documented1 out of 17 items with examples
  • Size
  • Source code size: 232.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 14.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jomsch/gridit
    2 0 5
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jomsch

Gridit

A 2D grid library utilizing the fun of iterators.

Gridit is a experimental 2D grid library which implements different Iterators to go over the cells of the grid. It was created with board games like chess in mind but can also be used for other use cases.

Gridit started to see how it would feel to create Chess movement patterns with iterators. The example chess board can be found in examples/board.

Simple example: possible moves of the king without checking for check.

fn possible_moves(&self, grid: &Grid<BoardPiece>, current_pos: Position) -> Vec<Position> {
	grid.neighbors(pos)
		.grid_positions()
		.filter(|(pos, cell)| !matches!(cell, NonEmpty(piece) if piece.color == self.color))
		.map(|(pos, _)| pos)
		.collect()
}

Examples

git clone https://github.com/jomsch/gridit.git
cd gridit

Run the examples as following:

Game Of Life

cargo run --example gameoflife

Board

cargo run --example board

The piece with the T in it is a Blocker it can not beat any pieces and moves by teleporting to a friendly piece.
The Giraffe is a blank piece for testing purposes. If you want to quickly test this library i recommend to clone this repository and implement some movement pattern for the Giraffe piece. Just write the fn possible_moves function and run the board example. For inspiration see the chess piece implementation here.

What's missing

These functions are missing. Waiting for generic associated typesto land in rust.

  • pattern_mut
  • neighbor_mut

Feedback & Questions

Having feedback or questions?
Open an issue or shot me a message on Twitter or Reddit.
I would love to hear your thoughts and ideas on Gridit.

Asset License

Assets found in resources are licensed under CC-BY-SA 3.0. These assets can be found here. Thanks and credit to:

  • Colin M.L. Burnett
  • Francois-Pier
  • NikNaks

License

Distributed under the MIT License. See LICENSE.txt for more information.