From db532edb6b63912f6cce0c5b6445b37686473069 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sun, 22 Dec 2019 06:55:48 +0100 Subject: Create stone wall structure --- src/structs.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/structs.rs b/src/structs.rs index 571c79d..fdc20f4 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -13,6 +13,27 @@ impl StoneWall { rows, } } + + pub fn set_stone(&mut self, row: u32, pos: u32, stone: u32) -> Option<()> { + self.rows.get_mut(row as usize).and_then(|v| v.get_mut(pos as usize)) + .map(|v| *v = stone) + } + + pub fn output(&self) { + let colors = [ + [31, 32], + [33, 35], + ]; + for (i, row) in self.rows.iter().enumerate() { + for (j, &stone) in row.iter().enumerate() { + print!("{}", colors[i & 1][j & 1]); + print!("\x1b[{}m{}", + colors[i & 1][j & 1], + "◙".repeat(stone as usize)); + } + println!("\x1b[m"); + } + } } pub struct GapHeights { @@ -81,6 +102,19 @@ impl GapHeights { i: 0, } } + + pub fn as_stone_wall(&self, n: u32) -> StoneWall { + let h = n/2 + 1; + let mut rows = Vec::with_capacity(h as usize); + for i in 0..h { + let mut row = vec![0; n as usize]; + self.calculate_row(i, &mut row); + rows.push(row); + } + StoneWall { + rows + } + } } pub struct GapIter<'a> { -- cgit v1.2.3-54-g00ecf