Crates.io | gridit |
lib.rs | gridit |
version | 0.1.0 |
source | src |
created_at | 2021-05-10 19:30:22.753291 |
updated_at | 2021-05-10 19:30:22.753291 |
description | 2D grid library utilizing the fun of iterators |
homepage | |
repository | https://github.com/jomsch/gridit |
max_upload_size | |
id | 395749 |
size | 233,522 |
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()
}
git clone https://github.com/jomsch/gridit.git
cd gridit
Run the examples as following:
cargo run --example gameoflife
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.
These functions are missing. Waiting for generic associated typesto land in rust.
pattern_mut
neighbor_mut
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
.
Assets found in resources are licensed under CC-BY-SA 3.0. These assets can be found here. Thanks and credit to:
Distributed under the MIT License. See LICENSE.txt for more information.