diff options
author | natrixaeria <upezu@student.kit.edu> | 2019-12-22 06:55:48 +0100 |
---|---|---|
committer | natrixaeria <upezu@student.kit.edu> | 2019-12-22 06:55:48 +0100 |
commit | db532edb6b63912f6cce0c5b6445b37686473069 (patch) | |
tree | d007ddb0f76355f9593c463e2ad8acd9bf42f9b2 /src | |
parent | dd0ed4cfff1a4af2a518aab399e32174175ed0d8 (diff) |
Create stone wall structure
Diffstat (limited to 'src')
-rw-r--r-- | src/structs.rs | 34 |
1 files changed, 34 insertions, 0 deletions
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> { |