Skip to content

Commit

Permalink
Merge pull request #6 from Dalvany/fix_ellers_algorithm
Browse files Browse the repository at this point in the history
Fix ellers algorithm
  • Loading branch information
ftsell committed Aug 26, 2023
2 parents 39433e1 + 98664d5 commit 539e352
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/ellers_algorithm.rs
Expand Up @@ -353,7 +353,7 @@ impl Generator for EllersGenerator {
self.graph = MazeGraph::with_capacity((width * height) as usize, 0);

self.init_fields_first_row(width);
for y in 0..height {
for y in 0..(height - 1) {
self.randomly_join_fields(y)
.with_context(|| "Could not generate maze")?;
self.create_downward_connections(y);
Expand All @@ -376,8 +376,33 @@ impl Generator for EllersGenerator {

#[cfg(test)]
mod test {
use crate::prelude::{Coordinates, Direction, Generator};

use super::EllersGenerator;

test_all_coordinates_have_fields!(super::EllersGenerator);
test_route_from_start_to_goal_exists!(super::EllersGenerator);
test_all_fields_connected!(super::EllersGenerator);
test_generation_is_deterministic!(super::EllersGenerator);

#[test]
fn test_south_passage() -> anyhow::Result<()> {
let mut generator = EllersGenerator::new(Some([1; 32]));
let maze = generator.generate(3, 3)?;
let (width, height) = maze.size;

println!("{maze:?}");

for i in 0..width {
if let Some(field) = maze.get_field(&Coordinates::new(i, height - 1)) {
assert!(
!field.has_passage(&Direction::South),
"South passage at ({i}, {})",
height - 1
);
}
}

Ok(())
}
}

0 comments on commit 539e352

Please sign in to comment.