Skip to content

Commit

Permalink
feat(shapes): added bonk-tie
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeSchmied committed Feb 25, 2024
1 parent cf6f84c commit 139d0c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ impl fmt::Display for Universe {
}
}

/// Number of currently supported shapes
pub const SHAPES_N: u8 = 6;

#[derive(Debug)]
pub enum ShapeError {
OutOfRange,
Expand All @@ -210,7 +207,7 @@ impl std::fmt::Display for ShapeError {
/// `from_figur()`
/// `IndexOutOfRange`
pub fn get_shape(wh: u32, i: usize) -> Result<Universe, ShapeError> {
if i > SHAPES_N as usize {
if i > shapes::N as usize {
return Err(ShapeError::OutOfRange);
}

Expand All @@ -227,6 +224,8 @@ pub fn get_shape(wh: u32, i: usize) -> Result<Universe, ShapeError> {

5 => Universe::from_figur(wh, &shapes::rabbits()),

6 => Universe::from_figur(wh, &shapes::bonk_tie()),

_ => Err(ShapeError::OutOfRange),
}
// todo!();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn print_events() -> io::Result<()> {
} else if kmaps::restart().contains(&event) {
universe = get_shape(wh, i).unwrap();
} else if kmaps::next().contains(&event) {
if i + 1 != SHAPES_N as usize {
if i + 1 != shapes::N as usize {
i += 1;
} else {
i = 0;
Expand Down
59 changes: 37 additions & 22 deletions src/shapes.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
use super::*;

pub fn two_engine_cordership() -> String {
todo!();
// [
// "_".repeat(19),
// "##".into(),
// "_".repeat(19),
// "\n".into(),
// "_".repeat(19),
// "####".into(),
// "_".repeat(17),
// "\n".into(),
// ]
// .concat()
}
/// Number of currently supported shapes
pub const N: u8 = 7;

pub fn copperhead() -> Vec<String> {
// ["_".repeat(5), "#_##".into(), "_".repeat(7), "#".into(), "_".repeat(6), "#".into(), "___##___#__###_"]
Expand Down Expand Up @@ -76,14 +64,6 @@ pub fn gosper_glider_gun() -> Vec<String> {
.to_vec()
}

pub fn sir_robin() -> String {
todo!()
}

pub fn snark_loop() -> String {
todo!()
}

pub fn featherweigth_spaceship() -> Vec<String> {
["__#".into(), "#_#".into(), "_##".into()].to_vec()
}
Expand All @@ -98,6 +78,18 @@ pub fn rabbits() -> Vec<String> {
.to_vec()
}

/// 3×5
pub fn bonk_tie() -> Vec<String> {
[
"##_".into(),
"##_".into(),
"__#".into(),
"__#".into(),
"__#".into(),
]
.to_vec()
}

pub fn rand(width: u32, height: u32) -> Universe {
let cells = (0..width * height)
.map(|_i| {
Expand Down Expand Up @@ -135,3 +127,26 @@ pub fn stripes(width: u32, height: u32) -> Universe {
cells,
}
}

pub fn two_engine_cordership() -> String {
todo!();
// [
// "_".repeat(19),
// "##".into(),
// "_".repeat(19),
// "\n".into(),
// "_".repeat(19),
// "####".into(),
// "_".repeat(17),
// "\n".into(),
// ]
// .concat()
}

pub fn sir_robin() -> String {
todo!()
}

pub fn snark_loop() -> String {
todo!()
}

0 comments on commit 139d0c2

Please sign in to comment.