1 unstable release
0.1.0 | May 10, 2021 |
---|
#969 in Game dev
91KB
1.5K
SLoC
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.