From bb350d3ec7db21b09702d9cd46eaaf9abc36b78d Mon Sep 17 00:00:00 2001 From: eraden Date: Thu, 3 Oct 2024 06:10:27 +0200 Subject: [PATCH] Correct Test --- maze/src/lib.rs | 108 +++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/maze/src/lib.rs b/maze/src/lib.rs index 00ab166..352e3da 100644 --- a/maze/src/lib.rs +++ b/maze/src/lib.rs @@ -426,16 +426,16 @@ impl AsciiBroad { write!(bottom_line, "#").unwrap(); for x in 0..X { - write!(top_line, " ").unwrap(); + write!(top_line, ".").unwrap(); let east_boundary = if grid.is_carved((x, y), Cell::EAST) { - " " + "." } else { "#" }; write!(top_line, "{east_boundary}").unwrap(); let south_boundary = if grid.is_carved((x, y), Cell::SOUTH) { - " " + "." } else { "#" }; @@ -577,10 +577,7 @@ impl BinaryMapVisitor BinaryMapVisitor::new(); - g.cells[0] = Cell::EAST; - g.cells[1] = Cell::default(); - g.cells[2] = Cell::EAST; - g.cells[3] = Cell::WEST; - g.cells[4] = Cell::default(); + g.cells[0] = Cell::EAST | Cell::SOUTH; + g.cells[1] = Cell::EAST | Cell::SOUTH; + g.cells[2] = Cell::WEST | Cell::SOUTH; + g.cells[3] = Cell::EAST | Cell::SOUTH; + g.cells[4] = Cell::WEST | Cell::SOUTH; - g.cells[5] = Cell::EAST | Cell::WEST; - g.cells[6] = Cell::EAST | Cell::WEST; - g.cells[7] = Cell::EAST | Cell::WEST; - g.cells[8] = Cell::EAST | Cell::WEST; - g.cells[9] = Cell::EAST | Cell::WEST; + g.cells[5] = Cell::WEST | Cell::SOUTH; + g.cells[6] = Cell::WEST | Cell::SOUTH; + g.cells[7] = Cell::WEST | Cell::NORTH; + g.cells[8] = Cell::WEST | Cell::SOUTH; + g.cells[9] = Cell::WEST | Cell::SOUTH; - g.cells[10] = Cell::EAST | Cell::WEST; - g.cells[11] = Cell::SOUTH; - g.cells[12] = Cell::NORTH; - g.cells[13] = Cell::WEST | Cell::SOUTH; - g.cells[14] = Cell::EAST | Cell::WEST; + g.cells[10] = Cell::WEST | Cell::SOUTH; + g.cells[11] = Cell::EAST | Cell::NORTH; + g.cells[12] = Cell::EAST | Cell::SOUTH; + g.cells[13] = Cell::WEST | Cell::NORTH; + g.cells[14] = Cell::WEST | Cell::SOUTH; - g.cells[15] = Cell::WEST; - g.cells[16] = Cell::WEST | Cell::NORTH | Cell::SOUTH; - g.cells[17] = Cell::WEST | Cell::SOUTH; - g.cells[18] = Cell::EAST | Cell::NORTH; - g.cells[19] = Cell::EAST | Cell::WEST; + g.cells[15] = Cell::EAST | Cell::SOUTH; + g.cells[16] = Cell::WEST | Cell::NORTH; + g.cells[17] = Cell::EAST | Cell::NORTH; + g.cells[18] = Cell::WEST | Cell::SOUTH; + g.cells[19] = Cell::WEST | Cell::SOUTH; - g.cells[20] = Cell::WEST | Cell::SOUTH; - g.cells[21] = Cell::SOUTH | Cell::NORTH; - g.cells[22] = Cell::SOUTH | Cell::NORTH; - g.cells[23] = Cell::SOUTH | Cell::EAST; - g.cells[24] = Cell::WEST | Cell::SOUTH; + g.cells[20] = Cell::EAST | Cell::NORTH; + g.cells[21] = Cell::EAST | Cell::NORTH; + g.cells[22] = Cell::EAST | Cell::NORTH; + g.cells[23] = Cell::WEST | Cell::NORTH; + g.cells[24] = Cell::WEST | Cell::NORTH; - let mut map = BinaryMap::<12, 12, 144>::new(); - BinaryMapVisitor.format(&mut g, &mut map.0); + let mut map = BinaryMap::<11, 11, 121>::new(); + BinaryMapVisitor.format(&g, &mut map.0); + + let mut s = heapless::String::<144>::new(); + AsciiBroad.format(&g, &mut s); + println!("{s}"); use MazePart::Passage as P; use MazePart::Wall as W; use MazePart::*; #[derive(PartialEq)] - struct MB([MazePart; 144]); + struct MB([MazePart; 121]); impl std::fmt::Debug for MB { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "\n"); - for x in 0..12 { - for y in 0..12 { - let c = match self.0[y * 12 + x] { - P => ' ', + for x in 0..11 { + for y in 0..11 { + let c = match self.0[y * 11 + x] { + P => '.', W => '#', Noop => '?', Player => 'O', }; - write!(f, "{c} "); + write!(f, "{c}"); } write!(f, "\n"); } @@ -746,18 +751,17 @@ mod print_tests { assert_eq!( MB(map.0), MB([ - W, W, W, W, W, W, W, W, W, W, W, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, P, P, P, P, P, P, P, P, P, P, W, // - W, W, W, W, W, W, W, W, W, W, W, W, + W, W, W, W, W, W, W, W, W, W, W, // + W, P, P, P, P, P, W, P, P, P, W, // + W, P, W, P, W, P, W, P, W, P, W, // + W, P, W, P, W, P, W, P, W, P, W, // + W, P, W, P, W, W, W, P, W, P, W, // + W, P, W, P, P, P, P, P, W, P, W, // + W, P, W, W, W, P, W, W, W, P, W, // + W, P, P, P, W, P, P, P, W, P, W, // + W, P, W, W, W, W, W, P, W, P, W, // + W, P, P, P, P, P, P, P, W, P, W, // + W, W, W, W, W, W, W, W, W, W, W, ]) ); }