#grid #rectangular #pretty-table

md_grid

A simple library for storing and iterating through data in a rectangular grid

3 unstable releases

0.2.1 Mar 12, 2019
0.2.0 Mar 10, 2019
0.1.0 Jan 2, 2019

#3 in #rectangular

MIT-0 license

13KB
254 lines

This is a library for representing game boards with utilities for doing useful game related functions.

Currently only a simple rectangular grid is supported.

extern crate grid;
extern crate prettytable;
use grid::Grid;

fn main() {
    let data = vec![
        vec![1, 2, 3, 4],
        vec![5, 6, 7, 8],
        vec![9, 10, 11, 12],
    ];
    let grid = Grid::<usize>::new_from(data);

    // neighbors around 6
    let mut iter = grid.eight_neighbors(1, 1);
    iter.for_each(|cell| println!("{}", cell));

    // for debugging, you can printout the whole grid
    // via pretty table pkg
    grid.pretty_table().printstd();
}

With output:

1
2
3
5
7
9

10
11
+---+----+----+----+
| 1 | 2  | 3  | 4  |
+---+----+----+----+
| 5 | 6  | 7  | 8  |
+---+----+----+----+
| 9 | 10 | 11 | 12 |
+---+----+----+----+

Also checkout the chessboard example: cargo run --example chessboard --features="prettytable"

Dependencies

~0–1MB
~13K SLoC