From 7b14653993484029fbf85a1a93fe297d4a2d77c5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 May 2026 18:22:00 +0900 Subject: [PATCH 01/19] feat: start implementing Floyd-Warshall algorithm --- bracket-pathfinding/src/floyd_warshall.rs | 38 +++++++++++++++++++++++ bracket-pathfinding/src/lib.rs | 1 + 2 files changed, 39 insertions(+) create mode 100644 bracket-pathfinding/src/floyd_warshall.rs diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs new file mode 100644 index 00000000..f541b5d8 --- /dev/null +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -0,0 +1,38 @@ +use bracket_algorithm_traits::prelude::BaseMap; +#[cfg(feature = "threaded")] +use rayon::prelude::*; +#[allow(unused_imports)] +use smallvec::SmallVec; +use std::convert::TryInto; + +pub struct FloydWarshallMap { + pub map: Vec, + size_x: usize, + size_y: usize, + max_depth: f32, +} + +#[allow(dead_code)] +impl FloydWarshallMap { + pub fn new( + size_x: T, + size_y: T, + map: &dyn BaseMap, + max_depth: f32, + ) -> FloydWarshallMap + where + T: TryInto, + { + let sz_x: usize = size_x.try_into().ok().unwrap(); + let sz_y: usize = size_y.try_into().ok().unwrap(); + let result: Vec = vec![f32::MAX; sz_x * sz_y]; + let mut f = FloydWarshallMap { + map: result, + size_x: sz_x, + size_y: sz_y, + max_depth, + }; + //FloydWarshallMap::build(&mut f, starts, map); + f + } +} \ No newline at end of file diff --git a/bracket-pathfinding/src/lib.rs b/bracket-pathfinding/src/lib.rs index ba2e767a..07330010 100755 --- a/bracket-pathfinding/src/lib.rs +++ b/bracket-pathfinding/src/lib.rs @@ -3,6 +3,7 @@ mod astar; mod dijkstra; mod field_of_view; +mod floyd_warshall; pub mod prelude { pub use crate::astar::*; From 68af36b3eb1f13f2ab9bf679b7c0cf04c95f53f1 Mon Sep 17 00:00:00 2001 From: Jaesung Hyun Date: Wed, 27 May 2026 00:54:52 +0900 Subject: [PATCH 02/19] feat: implement Floyd-Warshall algorithm --- bracket-pathfinding/src/floyd_warshall.rs | 124 +++++++++++++++++++--- 1 file changed, 111 insertions(+), 13 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index f541b5d8..16ebbc97 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -1,12 +1,10 @@ use bracket_algorithm_traits::prelude::BaseMap; -#[cfg(feature = "threaded")] -use rayon::prelude::*; #[allow(unused_imports)] use smallvec::SmallVec; use std::convert::TryInto; pub struct FloydWarshallMap { - pub map: Vec, + pub depth_map: Vec, size_x: usize, size_y: usize, max_depth: f32, @@ -14,25 +12,125 @@ pub struct FloydWarshallMap { #[allow(dead_code)] impl FloydWarshallMap { - pub fn new( - size_x: T, - size_y: T, - map: &dyn BaseMap, - max_depth: f32, - ) -> FloydWarshallMap + /// Construct a new FloydWarshall map, ready to run. You must specify the map size, and link to an implementation + /// of a BaseMap trait that can generate exits lists. It then builds the map, giving you a result. + pub fn new(size_x: T, size_y: T, map: &dyn BaseMap, max_depth: f32) -> FloydWarshallMap where T: TryInto, { let sz_x: usize = size_x.try_into().ok().unwrap(); let sz_y: usize = size_y.try_into().ok().unwrap(); - let result: Vec = vec![f32::MAX; sz_x * sz_y]; + let result: Vec = vec![f32::MAX; (sz_x * sz_y) * (sz_x * sz_y)]; let mut f = FloydWarshallMap { - map: result, + depth_map: result, size_x: sz_x, size_y: sz_y, max_depth, }; - //FloydWarshallMap::build(&mut f, starts, map); + FloydWarshallMap::build(&mut f, map); f } -} \ No newline at end of file + + + fn idx_helper(start_idx: usize, end_idx: usize, mapsize: usize) -> usize { + start_idx * mapsize + end_idx + } + + pub fn build(fm: &mut FloydWarshallMap, map: &dyn BaseMap) { + let mapsize: usize = fm.size_x * fm.size_y; + + for start_idx in 0..mapsize { + for end_idx in 0..mapsize { + let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); + fm.depth_map[ste_idx] = fm.max_depth; + } + } + + for start_idx in 0..mapsize { + for (end_idx, depth) in map.get_available_exits(start_idx) { + let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); + fm.depth_map[ste_idx] = depth; + } + } + + for mid_idx in 0..mapsize { + for start_idx in 0..mapsize { + let stm_idx = Self::idx_helper(start_idx, mid_idx, mapsize); + for end_idx in 0..mapsize { + let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); + let mte_idx = Self::idx_helper(mid_idx, end_idx, mapsize); + let new_depth = fm.depth_map[stm_idx] + fm.depth_map[mte_idx]; + let prev_depth = fm.depth_map[ste_idx]; + + fm.depth_map[ste_idx] = f32::min(new_depth, prev_depth); + } + } + } + } + + + /// Helper for traversing maps as path-finding. Provides the index of the lowest available + /// exit from the specified position index, or None if there isn't one. + /// You would use this for pathing TOWARDS a starting node. + pub fn find_lowest_exit( + fm: &FloydWarshallMap, + position: usize, + map: &dyn BaseMap, + ) -> Option { + let exits = map.get_available_exits(position); + let mapsize = fm.size_x * fm.size_y; + + if exits.is_empty() { + return None; + } + + let mut lowest_depth = fm.max_depth; + let mut lowest_exit = 0; + + for (exit, _) in exits { + let pos = Self::idx_helper(position, exit, mapsize); + if lowest_depth > fm.depth_map[pos] { + lowest_exit = exit; + lowest_depth = fm.depth_map[pos] + } + } + + Some(lowest_exit) + } + + /// Helper for traversing maps as path-finding. Provides the index of the highest available + /// exit from the specified position index, or None if there isn't one. + /// You would use this for pathing AWAY from a starting node, for example if you are running + /// away. + pub fn find_highest_exit( + fm: &FloydWarshallMap, + position: usize, + map: &dyn BaseMap, + ) -> Option { + let exits = map.get_available_exits(position); + let mapsize = fm.size_x * fm.size_y; + + if exits.is_empty() { + return None; + } + + let mut highest_depth = f32::MIN; + let mut highest_exit = 0; + + for (exit, _) in exits { + let pos = Self::idx_helper(position, exit, mapsize); + if highest_depth < fm.depth_map[pos] { + highest_exit = exit; + highest_depth = fm.depth_map[pos] + } + } + + Some(highest_exit) + } +} + +#[cfg(test)] +mod test { + + +} From ce9178c7f438660261b2ec0c7c8852901d195482 Mon Sep 17 00:00:00 2001 From: Jaesung Hyun Date: Sat, 30 May 2026 10:31:22 +0900 Subject: [PATCH 03/19] test: Implement FloydWarshallMap tests --- bracket-pathfinding/src/floyd_warshall.rs | 24 +++++++++++++++++++++-- bracket-pathfinding/src/lib.rs | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 16ebbc97..210fb709 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -131,6 +131,26 @@ impl FloydWarshallMap { #[cfg(test)] mod test { - - + use crate::prelude::*; + use bracket_algorithm_traits::prelude::*; + // 1 by 3 stripe of tiles + struct MiniMap; + impl BaseMap for MiniMap { + fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> { + match idx { + 0 => smallvec![(1, 1.)], + 2 => smallvec![(1, 1.)], + _ => smallvec![(idx - 1, 1.), (idx + 1, 2.)], + } + } + } + #[test] + fn test_highest_exit() { + let map = MiniMap {}; + let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); + let target = FloydWarshallMap::find_highest_exit(&exits_map, 0, &map); + assert_eq!(target, Some(1)); + let target = FloydWarshallMap::find_highest_exit(&exits_map, 1, &map); + assert_eq!(target, Some(2)); + } } diff --git a/bracket-pathfinding/src/lib.rs b/bracket-pathfinding/src/lib.rs index 0fc1ac63..7e0b9597 100755 --- a/bracket-pathfinding/src/lib.rs +++ b/bracket-pathfinding/src/lib.rs @@ -9,6 +9,7 @@ pub mod prelude { pub use crate::astar::*; pub use crate::dijkstra::*; pub use crate::field_of_view::*; + pub use crate::floyd_warshall::*; pub use bracket_algorithm_traits::prelude::*; pub use bracket_geometry::prelude::*; From 4a0bea7ab7d86a470d3c948e1587d6c0b7bed539 Mon Sep 17 00:00:00 2001 From: Jaesung Hyun Date: Sat, 30 May 2026 11:08:11 +0900 Subject: [PATCH 04/19] feat: add FloydWarshallMap example --- .../examples/floyd_warshall/common.rs | 124 ++++++++++++++++++ .../examples/floyd_warshall/main.rs | 41 ++++++ 2 files changed, 165 insertions(+) create mode 100644 bracket-pathfinding/examples/floyd_warshall/common.rs create mode 100644 bracket-pathfinding/examples/floyd_warshall/main.rs diff --git a/bracket-pathfinding/examples/floyd_warshall/common.rs b/bracket-pathfinding/examples/floyd_warshall/common.rs new file mode 100644 index 00000000..a70ddeda --- /dev/null +++ b/bracket-pathfinding/examples/floyd_warshall/common.rs @@ -0,0 +1,124 @@ +use bracket_color::prelude::*; +use bracket_pathfinding::prelude::*; +use bracket_random::prelude::RandomNumberGenerator; +use crossterm::queue; +use crossterm::style::{Color::Rgb, Print, SetForegroundColor}; +use std::io::{Write, stdout}; + +// Console Support + +pub fn print_color(color: RGB, text: &str) { + queue!( + stdout(), + SetForegroundColor(Rgb { + r: (color.r * 255.0) as u8, + g: (color.g * 255.0) as u8, + b: (color.b * 255.0) as u8, + }) + ) + .expect("Command Fail"); + queue!(stdout(), Print(text)).expect("Command fail"); +} + +pub fn flush_console() { + stdout().flush().expect("Flush Fail"); +} + +// Map + +pub const MAP_WIDTH: usize = 80; +pub const MAP_HEIGHT: usize = 20; +pub const MAP_TILES: usize = MAP_WIDTH * MAP_HEIGHT; +pub const START_POINT: Point = Point::constant(2, MAP_HEIGHT as i32 / 2); +pub const END_POINT: Point = Point::constant(MAP_WIDTH as i32 - 2, MAP_HEIGHT as i32 / 2); + +pub struct Map { + pub tiles: Vec, +} + +impl Map { + pub fn new() -> Self { + let mut tiles = Self { + tiles: vec!['.'; MAP_TILES], + }; + + // Add random walls + let n_walls = 200; + let mut rng = RandomNumberGenerator::new(); + for _ in 0..n_walls { + let target = Point::new( + rng.roll_dice(1, MAP_WIDTH as i32 - 1), + rng.roll_dice(1, MAP_HEIGHT as i32 - 1), + ); + if target != START_POINT && target != END_POINT { + let idx = tiles.point2d_to_index(target); + tiles.tiles[idx] = '#'; + } + } + + tiles + } + + fn valid_exit(&self, loc: Point, delta: Point) -> Option { + let destination = loc + delta; + if self.in_bounds(destination) { + let idx = self.point2d_to_index(destination); + if self.tiles[idx] == '.' { + Some(idx) + } else { + None + } + } else { + None + } + } +} + +impl BaseMap for Map { + fn is_opaque(&self, idx: usize) -> bool { + self.tiles[idx] == '#' + } + + fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> { + let mut exits = SmallVec::new(); + let location = self.index_to_point2d(idx); + + if let Some(idx) = self.valid_exit(location, Point::new(-1, 0)) { + exits.push((idx, 1.0)) + } + if let Some(idx) = self.valid_exit(location, Point::new(1, 0)) { + exits.push((idx, 1.0)) + } + if let Some(idx) = self.valid_exit(location, Point::new(0, -1)) { + exits.push((idx, 1.0)) + } + if let Some(idx) = self.valid_exit(location, Point::new(0, 1)) { + exits.push((idx, 1.0)) + } + + if let Some(idx) = self.valid_exit(location, Point::new(-1, -1)) { + exits.push((idx, 1.4)) + } + if let Some(idx) = self.valid_exit(location, Point::new(1, -1)) { + exits.push((idx, 1.4)) + } + if let Some(idx) = self.valid_exit(location, Point::new(-1, 1)) { + exits.push((idx, 1.4)) + } + if let Some(idx) = self.valid_exit(location, Point::new(-1, 1)) { + exits.push((idx, 1.4)) + } + + exits + } + + fn get_pathing_distance(&self, idx1: usize, idx2: usize) -> f32 { + DistanceAlg::Pythagoras.distance2d(self.index_to_point2d(idx1), self.index_to_point2d(idx2)) + } +} + +impl Algorithm2D for Map { + fn dimensions(&self) -> Point { + Point::new(MAP_WIDTH, MAP_HEIGHT) + } +} diff --git a/bracket-pathfinding/examples/floyd_warshall/main.rs b/bracket-pathfinding/examples/floyd_warshall/main.rs new file mode 100644 index 00000000..d3b1cf1e --- /dev/null +++ b/bracket-pathfinding/examples/floyd_warshall/main.rs @@ -0,0 +1,41 @@ +mod common; +use bracket_color::prelude::*; +use bracket_pathfinding::prelude::*; +use common::*; + +fn main() { + let map = Map::new(); + + // Perform the search + let flow_map = FloydWarshallMap::new(MAP_WIDTH, MAP_HEIGHT, &map, 1024.0); + + // Draw the result + for y in 0..MAP_HEIGHT { + let base_idx = map.point2d_to_index(Point::new(0, y)); + for x in 0..MAP_WIDTH { + let idx = base_idx + x; + + let tile = map.tiles[idx]; + let color = match tile { + '#' => RGB::named(YELLOW), + _ => { + if flow_map.map[idx] < f32::MAX { + RGB::from_u8( + 0, + 255 - { + let n = flow_map.map[idx] * 12.0; + if n > 255.0 { 255.0 } else { n } + } as u8, + 0, + ) + } else { + RGB::named(CHOCOLATE) + } + } + }; + print_color(color, &tile.to_string()); + } + print_color(RGB::named(WHITE), "\n"); + } + flush_console(); +} From 001caf63d5adac5fb9cd6d771f740eb9a914b834 Mon Sep 17 00:00:00 2001 From: Jaesung Hyun Date: Sat, 30 May 2026 21:55:41 +0900 Subject: [PATCH 05/19] feat: modify idx_helper method --- .../examples/floyd_warshall/main.rs | 3 +++ bracket-pathfinding/src/floyd_warshall.rs | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/main.rs b/bracket-pathfinding/examples/floyd_warshall/main.rs index d3b1cf1e..09e6b0f5 100644 --- a/bracket-pathfinding/examples/floyd_warshall/main.rs +++ b/bracket-pathfinding/examples/floyd_warshall/main.rs @@ -4,6 +4,7 @@ use bracket_pathfinding::prelude::*; use common::*; fn main() { +/* let map = Map::new(); // Perform the search @@ -38,4 +39,6 @@ fn main() { print_color(RGB::named(WHITE), "\n"); } flush_console(); + + */ } diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 210fb709..b60af54d 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -31,9 +31,9 @@ impl FloydWarshallMap { f } - - fn idx_helper(start_idx: usize, end_idx: usize, mapsize: usize) -> usize { - start_idx * mapsize + end_idx + // Helper for indexing the Floyd-Warshall distance map. + pub fn idx_helper(&self, start_idx: usize, end_idx: usize) -> usize { + start_idx * (self.size_x * self.size_y) + end_idx } pub fn build(fm: &mut FloydWarshallMap, map: &dyn BaseMap) { @@ -41,24 +41,24 @@ impl FloydWarshallMap { for start_idx in 0..mapsize { for end_idx in 0..mapsize { - let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); + let ste_idx = fm.idx_helper(start_idx, end_idx); fm.depth_map[ste_idx] = fm.max_depth; } } for start_idx in 0..mapsize { for (end_idx, depth) in map.get_available_exits(start_idx) { - let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); + let ste_idx = fm.idx_helper(start_idx, end_idx); fm.depth_map[ste_idx] = depth; } } for mid_idx in 0..mapsize { for start_idx in 0..mapsize { - let stm_idx = Self::idx_helper(start_idx, mid_idx, mapsize); + let stm_idx = fm.idx_helper(start_idx, mid_idx); for end_idx in 0..mapsize { - let ste_idx = Self::idx_helper(start_idx, end_idx, mapsize); - let mte_idx = Self::idx_helper(mid_idx, end_idx, mapsize); + let ste_idx = fm.idx_helper(start_idx, end_idx); + let mte_idx = fm.idx_helper(mid_idx, end_idx); let new_depth = fm.depth_map[stm_idx] + fm.depth_map[mte_idx]; let prev_depth = fm.depth_map[ste_idx]; @@ -78,7 +78,6 @@ impl FloydWarshallMap { map: &dyn BaseMap, ) -> Option { let exits = map.get_available_exits(position); - let mapsize = fm.size_x * fm.size_y; if exits.is_empty() { return None; @@ -88,7 +87,7 @@ impl FloydWarshallMap { let mut lowest_exit = 0; for (exit, _) in exits { - let pos = Self::idx_helper(position, exit, mapsize); + let pos = fm.idx_helper(position, exit); if lowest_depth > fm.depth_map[pos] { lowest_exit = exit; lowest_depth = fm.depth_map[pos] @@ -108,7 +107,6 @@ impl FloydWarshallMap { map: &dyn BaseMap, ) -> Option { let exits = map.get_available_exits(position); - let mapsize = fm.size_x * fm.size_y; if exits.is_empty() { return None; @@ -118,7 +116,7 @@ impl FloydWarshallMap { let mut highest_exit = 0; for (exit, _) in exits { - let pos = Self::idx_helper(position, exit, mapsize); + let pos = fm.idx_helper(position, exit); if highest_depth < fm.depth_map[pos] { highest_exit = exit; highest_depth = fm.depth_map[pos] From d92fc3ff0e45d68a4409176ca59762c129854597 Mon Sep 17 00:00:00 2001 From: Jaesung Hyun Date: Sun, 31 May 2026 23:56:41 +0900 Subject: [PATCH 06/19] test: start implement additonal test --- bracket-pathfinding/src/floyd_warshall.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index b60af54d..6c6f1f9a 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -142,6 +142,17 @@ mod test { } } } + + #[test] + fn test_new() { + + } + + #[test] + fn test_lowest_exit() { + + } + #[test] fn test_highest_exit() { let map = MiniMap {}; From 3097fc400e9801b8f73a9d67269f825f9f9de7f2 Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 00:39:48 +0900 Subject: [PATCH 07/19] test: implement additonal test --- bracket-pathfinding/src/floyd_warshall.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 6c6f1f9a..673d4f5a 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -31,7 +31,9 @@ impl FloydWarshallMap { f } - // Helper for indexing the Floyd-Warshall distance map. + /// Helper for indexing the Floyd-Warshall distance map. + /// Converts a start node index and end node index into a + /// single index within the flattened depth_map array. pub fn idx_helper(&self, start_idx: usize, end_idx: usize) -> usize { start_idx * (self.size_x * self.size_y) + end_idx } @@ -46,6 +48,11 @@ impl FloydWarshallMap { } } + for start_idx in 0..mapsize { + let idx = fm.idx_helper(start_idx, start_idx); + fm.depth_map[idx] = 0.; + } + for start_idx in 0..mapsize { for (end_idx, depth) in map.get_available_exits(start_idx) { let ste_idx = fm.idx_helper(start_idx, end_idx); @@ -145,12 +152,24 @@ mod test { #[test] fn test_new() { + let map = MiniMap {}; + let test_map = FloydWarshallMap::new(3, 1, &map, 10.); + assert_eq!(test_map.depth_map, + vec![0., 1., 3., + 1., 0., 2., + 2., 1., 0.] + ); } #[test] fn test_lowest_exit() { - + let map = MiniMap {}; + let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); + let target = FloydWarshallMap::find_lowest_exit(&exits_map, 0, &map); + assert_eq!(target, Some(1)); + let target = FloydWarshallMap::find_lowest_exit(&exits_map, 1, &map); + assert_eq!(target, Some(0)); } #[test] From e49baf712bb6ee634cb72281aef99a36e4ca6959 Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 03:11:20 +0900 Subject: [PATCH 08/19] fix: remove wrong init depth map --- bracket-pathfinding/src/floyd_warshall.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 673d4f5a..9a90b085 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -41,13 +41,6 @@ impl FloydWarshallMap { pub fn build(fm: &mut FloydWarshallMap, map: &dyn BaseMap) { let mapsize: usize = fm.size_x * fm.size_y; - for start_idx in 0..mapsize { - for end_idx in 0..mapsize { - let ste_idx = fm.idx_helper(start_idx, end_idx); - fm.depth_map[ste_idx] = fm.max_depth; - } - } - for start_idx in 0..mapsize { let idx = fm.idx_helper(start_idx, start_idx); fm.depth_map[idx] = 0.; From 7b130adda82f53f05858e0dd0249162a2f1f4eb6 Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 03:13:19 +0900 Subject: [PATCH 09/19] feat: Floyd-Warshall example implement --- bracket-pathfinding/examples/floyd_warshall/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/main.rs b/bracket-pathfinding/examples/floyd_warshall/main.rs index 09e6b0f5..ec12c189 100644 --- a/bracket-pathfinding/examples/floyd_warshall/main.rs +++ b/bracket-pathfinding/examples/floyd_warshall/main.rs @@ -4,27 +4,27 @@ use bracket_pathfinding::prelude::*; use common::*; fn main() { -/* let map = Map::new(); // Perform the search let flow_map = FloydWarshallMap::new(MAP_WIDTH, MAP_HEIGHT, &map, 1024.0); + let start_idx = map.point2d_to_index(START_POINT); // Draw the result for y in 0..MAP_HEIGHT { - let base_idx = map.point2d_to_index(Point::new(0, y)); for x in 0..MAP_WIDTH { - let idx = base_idx + x; + let idx = y * MAP_WIDTH + x; + let depth_map_idx = flow_map.idx_helper(start_idx, idx); let tile = map.tiles[idx]; let color = match tile { '#' => RGB::named(YELLOW), _ => { - if flow_map.map[idx] < f32::MAX { + if flow_map.depth_map[idx] < f32::MAX { RGB::from_u8( 0, 255 - { - let n = flow_map.map[idx] * 12.0; + let n = flow_map.depth_map[depth_map_idx] * 12.0; if n > 255.0 { 255.0 } else { n } } as u8, 0, @@ -40,5 +40,4 @@ fn main() { } flush_console(); - */ } From 8c6dd08c4895e3807c51cd0003bfcd5e3faa371e Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 03:36:17 +0900 Subject: [PATCH 10/19] docs: add Floyd-Warshall map --- bracket-pathfinding/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bracket-pathfinding/README.md b/bracket-pathfinding/README.md index 3223623e..f1cfc834 100755 --- a/bracket-pathfinding/README.md +++ b/bracket-pathfinding/README.md @@ -105,6 +105,19 @@ Once you have the map, you can access individual distances at `flow_map.map` - o The example `dijkstra` demonstrates this. +## Floyd-Washall Mapping + +Bracket-lib also includes Floyd-Warshall maps. Unlike Dijkstra maps, Floyd-Warshall computes the shortest path between every pair of points on the map. + +```rust +let flow_map = FloydWarshallMap::new(MAP_WIDTH, MAP_HEIGHT, &map, 1024.0); +``` + +Once you have the map, you can use helper functions such as `find_highest_exit` and `find_lowest_exit` to assist with path-finding, similarly to Dijkstra maps. + +Warning: Floyd-Warshall has a significantly higher computational cost than Dijkstra mapping. Large maps may take a long time to generate and can consume a considerable amount of memory. + + ## Field of View (2D only for now) With `is_opaque` defined for your `BaseMap` trait, obtaining a set of all visible tiles is easy: @@ -121,10 +134,11 @@ If you enable the `threaded` feature, some Dijkstra functions will use a multi-t ## Examples -There are three examples (ignore `common.rs` - it's shared code): +There are four examples (ignore `common.rs` - it's shared code): * `astar` (`cargo run --example astar`), demonstrating A-Star pathing across a random map. * `dijkstra` (`cargo run --example dijkstra`), demonstrating Dijkstra mapping to two targets. +* `floyd warshall` (`cargo run --example floyd_warshall`), demonstrating Dijkstra mapping to two targets. * `fov` (`cargo run --example fov`), demonstrating field-of-view generation. These use `crossterm` for rendering to your terminal. From ffdf968e6292454d8c3c175327d4f5868e4b7b2f Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 03:46:40 +0900 Subject: [PATCH 11/19] chore: change code style --- bracket-pathfinding/src/floyd_warshall.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 9a90b085..793d7873 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -68,7 +68,6 @@ impl FloydWarshallMap { } } - /// Helper for traversing maps as path-finding. Provides the index of the lowest available /// exit from the specified position index, or None if there isn't one. /// You would use this for pathing TOWARDS a starting node. @@ -148,11 +147,7 @@ mod test { let map = MiniMap {}; let test_map = FloydWarshallMap::new(3, 1, &map, 10.); - assert_eq!(test_map.depth_map, - vec![0., 1., 3., - 1., 0., 2., - 2., 1., 0.] - ); + assert_eq!(test_map.depth_map, vec![0., 1., 3., 1., 0., 2., 2., 1., 0.]); } #[test] From 4a4513f3e63e7fdf133c3444973fb08eb3ddca79 Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 03:53:50 +0900 Subject: [PATCH 12/19] docs: add Floyd-Warshall at Crate map --- ARCHITECTURE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index ed4fa3e2..441ef833 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -70,7 +70,7 @@ flowchart LR | `rltk` | Backward-compatible facade that maps legacy names onto `bracket-lib` | `bracket-lib`, tutorial/legacy codebases | | `bracket-bevy` | Bevy-oriented CP437/ASCII integration entry point | `bevy`, `bracket-color`, `bracket-geometry`, `bracket-random` | | `bracket-terminal` | Terminal runtime, frame loop, input, and backend-specific rendering | `bracket-color`, `bracket-geometry`, `bracket-rex`, `bracket-embedding` | -| `bracket-pathfinding` | A\*, Dijkstra, and FOV over user-provided map traits | `bracket-algorithm-traits`, `bracket-geometry` | +| `bracket-pathfinding` | A\*, Dijkstra, Floyd-Warshall and FOV over user-provided map traits | `bracket-algorithm-traits`, `bracket-geometry` | | `bracket-algorithm-traits` | Abstractions (`Algorithm2D/3D`, `BaseMap`) that decouple algorithms from storage layout | `bracket-geometry`, `bracket-pathfinding` | | `bracket-noise` | Noise generation utilities (FastNoise-style) | `bracket-random` | | `bracket-geometry` | Points, rectangles, lines, circles, and distance helpers | `bracket-algorithm-traits`, `bracket-pathfinding`, `bracket-terminal` | From 34c8d2254b055d3715fdae5665e7da981d71761a Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 09:33:53 +0900 Subject: [PATCH 13/19] chore: run cargo fmt --- bracket-pathfinding/src/floyd_warshall.rs | 151 +--------------------- 1 file changed, 6 insertions(+), 145 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 793d7873..404c7cf0 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -1,10 +1,12 @@ use bracket_algorithm_traits::prelude::BaseMap; +#[cfg(feature = "threaded")] +use rayon::prelude::*; #[allow(unused_imports)] use smallvec::SmallVec; use std::convert::TryInto; pub struct FloydWarshallMap { - pub depth_map: Vec, + pub map: Vec, size_x: usize, size_y: usize, max_depth: f32, @@ -12,161 +14,20 @@ pub struct FloydWarshallMap { #[allow(dead_code)] impl FloydWarshallMap { - /// Construct a new FloydWarshall map, ready to run. You must specify the map size, and link to an implementation - /// of a BaseMap trait that can generate exits lists. It then builds the map, giving you a result. pub fn new(size_x: T, size_y: T, map: &dyn BaseMap, max_depth: f32) -> FloydWarshallMap where T: TryInto, { let sz_x: usize = size_x.try_into().ok().unwrap(); let sz_y: usize = size_y.try_into().ok().unwrap(); - let result: Vec = vec![f32::MAX; (sz_x * sz_y) * (sz_x * sz_y)]; + let result: Vec = vec![f32::MAX; sz_x * sz_y]; let mut f = FloydWarshallMap { - depth_map: result, + map: result, size_x: sz_x, size_y: sz_y, max_depth, }; - FloydWarshallMap::build(&mut f, map); + //FloydWarshallMap::build(&mut f, starts, map); f } - - /// Helper for indexing the Floyd-Warshall distance map. - /// Converts a start node index and end node index into a - /// single index within the flattened depth_map array. - pub fn idx_helper(&self, start_idx: usize, end_idx: usize) -> usize { - start_idx * (self.size_x * self.size_y) + end_idx - } - - pub fn build(fm: &mut FloydWarshallMap, map: &dyn BaseMap) { - let mapsize: usize = fm.size_x * fm.size_y; - - for start_idx in 0..mapsize { - let idx = fm.idx_helper(start_idx, start_idx); - fm.depth_map[idx] = 0.; - } - - for start_idx in 0..mapsize { - for (end_idx, depth) in map.get_available_exits(start_idx) { - let ste_idx = fm.idx_helper(start_idx, end_idx); - fm.depth_map[ste_idx] = depth; - } - } - - for mid_idx in 0..mapsize { - for start_idx in 0..mapsize { - let stm_idx = fm.idx_helper(start_idx, mid_idx); - for end_idx in 0..mapsize { - let ste_idx = fm.idx_helper(start_idx, end_idx); - let mte_idx = fm.idx_helper(mid_idx, end_idx); - let new_depth = fm.depth_map[stm_idx] + fm.depth_map[mte_idx]; - let prev_depth = fm.depth_map[ste_idx]; - - fm.depth_map[ste_idx] = f32::min(new_depth, prev_depth); - } - } - } - } - - /// Helper for traversing maps as path-finding. Provides the index of the lowest available - /// exit from the specified position index, or None if there isn't one. - /// You would use this for pathing TOWARDS a starting node. - pub fn find_lowest_exit( - fm: &FloydWarshallMap, - position: usize, - map: &dyn BaseMap, - ) -> Option { - let exits = map.get_available_exits(position); - - if exits.is_empty() { - return None; - } - - let mut lowest_depth = fm.max_depth; - let mut lowest_exit = 0; - - for (exit, _) in exits { - let pos = fm.idx_helper(position, exit); - if lowest_depth > fm.depth_map[pos] { - lowest_exit = exit; - lowest_depth = fm.depth_map[pos] - } - } - - Some(lowest_exit) - } - - /// Helper for traversing maps as path-finding. Provides the index of the highest available - /// exit from the specified position index, or None if there isn't one. - /// You would use this for pathing AWAY from a starting node, for example if you are running - /// away. - pub fn find_highest_exit( - fm: &FloydWarshallMap, - position: usize, - map: &dyn BaseMap, - ) -> Option { - let exits = map.get_available_exits(position); - - if exits.is_empty() { - return None; - } - - let mut highest_depth = f32::MIN; - let mut highest_exit = 0; - - for (exit, _) in exits { - let pos = fm.idx_helper(position, exit); - if highest_depth < fm.depth_map[pos] { - highest_exit = exit; - highest_depth = fm.depth_map[pos] - } - } - - Some(highest_exit) - } -} - -#[cfg(test)] -mod test { - use crate::prelude::*; - use bracket_algorithm_traits::prelude::*; - // 1 by 3 stripe of tiles - struct MiniMap; - impl BaseMap for MiniMap { - fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> { - match idx { - 0 => smallvec![(1, 1.)], - 2 => smallvec![(1, 1.)], - _ => smallvec![(idx - 1, 1.), (idx + 1, 2.)], - } - } - } - - #[test] - fn test_new() { - let map = MiniMap {}; - - let test_map = FloydWarshallMap::new(3, 1, &map, 10.); - assert_eq!(test_map.depth_map, vec![0., 1., 3., 1., 0., 2., 2., 1., 0.]); - } - - #[test] - fn test_lowest_exit() { - let map = MiniMap {}; - let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); - let target = FloydWarshallMap::find_lowest_exit(&exits_map, 0, &map); - assert_eq!(target, Some(1)); - let target = FloydWarshallMap::find_lowest_exit(&exits_map, 1, &map); - assert_eq!(target, Some(0)); - } - - #[test] - fn test_highest_exit() { - let map = MiniMap {}; - let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); - let target = FloydWarshallMap::find_highest_exit(&exits_map, 0, &map); - assert_eq!(target, Some(1)); - let target = FloydWarshallMap::find_highest_exit(&exits_map, 1, &map); - assert_eq!(target, Some(2)); - } } From 491ffda4c33b5e50e6117cddccd7be23f904159d Mon Sep 17 00:00:00 2001 From: jshyun912 <108142462+jshyun912@users.noreply.github.com> Date: Mon, 1 Jun 2026 09:56:30 +0900 Subject: [PATCH 14/19] chore: run cargo fmt --- bracket-pathfinding/src/floyd_warshall.rs | 151 +++++++++++++++++++++- 1 file changed, 145 insertions(+), 6 deletions(-) diff --git a/bracket-pathfinding/src/floyd_warshall.rs b/bracket-pathfinding/src/floyd_warshall.rs index 404c7cf0..793d7873 100644 --- a/bracket-pathfinding/src/floyd_warshall.rs +++ b/bracket-pathfinding/src/floyd_warshall.rs @@ -1,12 +1,10 @@ use bracket_algorithm_traits::prelude::BaseMap; -#[cfg(feature = "threaded")] -use rayon::prelude::*; #[allow(unused_imports)] use smallvec::SmallVec; use std::convert::TryInto; pub struct FloydWarshallMap { - pub map: Vec, + pub depth_map: Vec, size_x: usize, size_y: usize, max_depth: f32, @@ -14,20 +12,161 @@ pub struct FloydWarshallMap { #[allow(dead_code)] impl FloydWarshallMap { + /// Construct a new FloydWarshall map, ready to run. You must specify the map size, and link to an implementation + /// of a BaseMap trait that can generate exits lists. It then builds the map, giving you a result. pub fn new(size_x: T, size_y: T, map: &dyn BaseMap, max_depth: f32) -> FloydWarshallMap where T: TryInto, { let sz_x: usize = size_x.try_into().ok().unwrap(); let sz_y: usize = size_y.try_into().ok().unwrap(); - let result: Vec = vec![f32::MAX; sz_x * sz_y]; + let result: Vec = vec![f32::MAX; (sz_x * sz_y) * (sz_x * sz_y)]; let mut f = FloydWarshallMap { - map: result, + depth_map: result, size_x: sz_x, size_y: sz_y, max_depth, }; - //FloydWarshallMap::build(&mut f, starts, map); + FloydWarshallMap::build(&mut f, map); f } + + /// Helper for indexing the Floyd-Warshall distance map. + /// Converts a start node index and end node index into a + /// single index within the flattened depth_map array. + pub fn idx_helper(&self, start_idx: usize, end_idx: usize) -> usize { + start_idx * (self.size_x * self.size_y) + end_idx + } + + pub fn build(fm: &mut FloydWarshallMap, map: &dyn BaseMap) { + let mapsize: usize = fm.size_x * fm.size_y; + + for start_idx in 0..mapsize { + let idx = fm.idx_helper(start_idx, start_idx); + fm.depth_map[idx] = 0.; + } + + for start_idx in 0..mapsize { + for (end_idx, depth) in map.get_available_exits(start_idx) { + let ste_idx = fm.idx_helper(start_idx, end_idx); + fm.depth_map[ste_idx] = depth; + } + } + + for mid_idx in 0..mapsize { + for start_idx in 0..mapsize { + let stm_idx = fm.idx_helper(start_idx, mid_idx); + for end_idx in 0..mapsize { + let ste_idx = fm.idx_helper(start_idx, end_idx); + let mte_idx = fm.idx_helper(mid_idx, end_idx); + let new_depth = fm.depth_map[stm_idx] + fm.depth_map[mte_idx]; + let prev_depth = fm.depth_map[ste_idx]; + + fm.depth_map[ste_idx] = f32::min(new_depth, prev_depth); + } + } + } + } + + /// Helper for traversing maps as path-finding. Provides the index of the lowest available + /// exit from the specified position index, or None if there isn't one. + /// You would use this for pathing TOWARDS a starting node. + pub fn find_lowest_exit( + fm: &FloydWarshallMap, + position: usize, + map: &dyn BaseMap, + ) -> Option { + let exits = map.get_available_exits(position); + + if exits.is_empty() { + return None; + } + + let mut lowest_depth = fm.max_depth; + let mut lowest_exit = 0; + + for (exit, _) in exits { + let pos = fm.idx_helper(position, exit); + if lowest_depth > fm.depth_map[pos] { + lowest_exit = exit; + lowest_depth = fm.depth_map[pos] + } + } + + Some(lowest_exit) + } + + /// Helper for traversing maps as path-finding. Provides the index of the highest available + /// exit from the specified position index, or None if there isn't one. + /// You would use this for pathing AWAY from a starting node, for example if you are running + /// away. + pub fn find_highest_exit( + fm: &FloydWarshallMap, + position: usize, + map: &dyn BaseMap, + ) -> Option { + let exits = map.get_available_exits(position); + + if exits.is_empty() { + return None; + } + + let mut highest_depth = f32::MIN; + let mut highest_exit = 0; + + for (exit, _) in exits { + let pos = fm.idx_helper(position, exit); + if highest_depth < fm.depth_map[pos] { + highest_exit = exit; + highest_depth = fm.depth_map[pos] + } + } + + Some(highest_exit) + } +} + +#[cfg(test)] +mod test { + use crate::prelude::*; + use bracket_algorithm_traits::prelude::*; + // 1 by 3 stripe of tiles + struct MiniMap; + impl BaseMap for MiniMap { + fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> { + match idx { + 0 => smallvec![(1, 1.)], + 2 => smallvec![(1, 1.)], + _ => smallvec![(idx - 1, 1.), (idx + 1, 2.)], + } + } + } + + #[test] + fn test_new() { + let map = MiniMap {}; + + let test_map = FloydWarshallMap::new(3, 1, &map, 10.); + assert_eq!(test_map.depth_map, vec![0., 1., 3., 1., 0., 2., 2., 1., 0.]); + } + + #[test] + fn test_lowest_exit() { + let map = MiniMap {}; + let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); + let target = FloydWarshallMap::find_lowest_exit(&exits_map, 0, &map); + assert_eq!(target, Some(1)); + let target = FloydWarshallMap::find_lowest_exit(&exits_map, 1, &map); + assert_eq!(target, Some(0)); + } + + #[test] + fn test_highest_exit() { + let map = MiniMap {}; + let exits_map = FloydWarshallMap::new(3, 1, &map, 10.); + let target = FloydWarshallMap::find_highest_exit(&exits_map, 0, &map); + assert_eq!(target, Some(1)); + let target = FloydWarshallMap::find_highest_exit(&exits_map, 1, &map); + assert_eq!(target, Some(2)); + } } From 7a8d4596285f969c01ed1b8460de0bb798b8094a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 10:06:30 +0900 Subject: [PATCH 15/19] chore: run cargo fmt --- bracket-pathfinding/examples/floyd_warshall/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/main.rs b/bracket-pathfinding/examples/floyd_warshall/main.rs index ec12c189..58f8895e 100644 --- a/bracket-pathfinding/examples/floyd_warshall/main.rs +++ b/bracket-pathfinding/examples/floyd_warshall/main.rs @@ -39,5 +39,4 @@ fn main() { print_color(RGB::named(WHITE), "\n"); } flush_console(); - } From 671b64a992c6afc3030ff5ec8d20a440cb8e3a50 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 10:33:23 +0900 Subject: [PATCH 16/19] chore: update to common.rs's latest commit --- .../examples/floyd_warshall/common.rs | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/common.rs b/bracket-pathfinding/examples/floyd_warshall/common.rs index a70ddeda..7e2f4a27 100644 --- a/bracket-pathfinding/examples/floyd_warshall/common.rs +++ b/bracket-pathfinding/examples/floyd_warshall/common.rs @@ -1,6 +1,5 @@ use bracket_color::prelude::*; use bracket_pathfinding::prelude::*; -use bracket_random::prelude::RandomNumberGenerator; use crossterm::queue; use crossterm::style::{Color::Rgb, Print, SetForegroundColor}; use std::io::{Write, stdout}; @@ -29,8 +28,8 @@ pub fn flush_console() { pub const MAP_WIDTH: usize = 80; pub const MAP_HEIGHT: usize = 20; pub const MAP_TILES: usize = MAP_WIDTH * MAP_HEIGHT; -pub const START_POINT: Point = Point::constant(2, MAP_HEIGHT as i32 / 2); -pub const END_POINT: Point = Point::constant(MAP_WIDTH as i32 - 2, MAP_HEIGHT as i32 / 2); +pub const START_POINT: Point = Point::constant(2, 2); +pub const END_POINT: Point = Point::constant(MAP_WIDTH as i32 - 2, MAP_HEIGHT as i32 - 2); pub struct Map { pub tiles: Vec, @@ -42,18 +41,10 @@ impl Map { tiles: vec!['.'; MAP_TILES], }; - // Add random walls - let n_walls = 200; - let mut rng = RandomNumberGenerator::new(); - for _ in 0..n_walls { - let target = Point::new( - rng.roll_dice(1, MAP_WIDTH as i32 - 1), - rng.roll_dice(1, MAP_HEIGHT as i32 - 1), - ); - if target != START_POINT && target != END_POINT { - let idx = tiles.point2d_to_index(target); - tiles.tiles[idx] = '#'; - } + // Add walls + for i in 0..15 { + tiles.tiles[10 + i * MAP_WIDTH] = '#'; + tiles.tiles[18 + (i + 5) * MAP_WIDTH] = '#'; } tiles @@ -63,7 +54,7 @@ impl Map { let destination = loc + delta; if self.in_bounds(destination) { let idx = self.point2d_to_index(destination); - if self.tiles[idx] == '.' { + if self.tiles[idx] != '#' { Some(idx) } else { None @@ -99,13 +90,13 @@ impl BaseMap for Map { if let Some(idx) = self.valid_exit(location, Point::new(-1, -1)) { exits.push((idx, 1.4)) } - if let Some(idx) = self.valid_exit(location, Point::new(1, -1)) { + if let Some(idx) = self.valid_exit(location, Point::new(-1, 1)) { exits.push((idx, 1.4)) } - if let Some(idx) = self.valid_exit(location, Point::new(-1, 1)) { + if let Some(idx) = self.valid_exit(location, Point::new(1, -1)) { exits.push((idx, 1.4)) } - if let Some(idx) = self.valid_exit(location, Point::new(-1, 1)) { + if let Some(idx) = self.valid_exit(location, Point::new(1, 1)) { exits.push((idx, 1.4)) } From 10979d2c6d4329f99796e5f0d5f324a4c5eb00d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 10:37:45 +0900 Subject: [PATCH 17/19] fix: change wrong idx --- bracket-pathfinding/examples/floyd_warshall/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/main.rs b/bracket-pathfinding/examples/floyd_warshall/main.rs index 58f8895e..9a731ae9 100644 --- a/bracket-pathfinding/examples/floyd_warshall/main.rs +++ b/bracket-pathfinding/examples/floyd_warshall/main.rs @@ -20,7 +20,7 @@ fn main() { let color = match tile { '#' => RGB::named(YELLOW), _ => { - if flow_map.depth_map[idx] < f32::MAX { + if flow_map.depth_map[depth_map_idx] < f32::MAX { RGB::from_u8( 0, 255 - { From a7727ec8415389e3257979dc8372f656c51ce439 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 10:39:49 +0900 Subject: [PATCH 18/19] docs: fix typo --- bracket-pathfinding/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bracket-pathfinding/README.md b/bracket-pathfinding/README.md index f1cfc834..ac4ed4cb 100755 --- a/bracket-pathfinding/README.md +++ b/bracket-pathfinding/README.md @@ -105,7 +105,7 @@ Once you have the map, you can access individual distances at `flow_map.map` - o The example `dijkstra` demonstrates this. -## Floyd-Washall Mapping +## Floyd-Warshall Mapping Bracket-lib also includes Floyd-Warshall maps. Unlike Dijkstra maps, Floyd-Warshall computes the shortest path between every pair of points on the map. @@ -138,7 +138,7 @@ There are four examples (ignore `common.rs` - it's shared code): * `astar` (`cargo run --example astar`), demonstrating A-Star pathing across a random map. * `dijkstra` (`cargo run --example dijkstra`), demonstrating Dijkstra mapping to two targets. -* `floyd warshall` (`cargo run --example floyd_warshall`), demonstrating Dijkstra mapping to two targets. +* `floyd warshall` (`cargo run --example floyd_warshall`), demonstrating all-pairs shortest-path mapping on a random map. * `fov` (`cargo run --example fov`), demonstrating field-of-view generation. These use `crossterm` for rendering to your terminal. From 33ee7be994a5ed46d88131c9dc4b34db905ecc6b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 10:45:01 +0900 Subject: [PATCH 19/19] chore: remove dead code --- bracket-pathfinding/examples/floyd_warshall/common.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bracket-pathfinding/examples/floyd_warshall/common.rs b/bracket-pathfinding/examples/floyd_warshall/common.rs index 7e2f4a27..26a8365c 100644 --- a/bracket-pathfinding/examples/floyd_warshall/common.rs +++ b/bracket-pathfinding/examples/floyd_warshall/common.rs @@ -29,7 +29,6 @@ pub const MAP_WIDTH: usize = 80; pub const MAP_HEIGHT: usize = 20; pub const MAP_TILES: usize = MAP_WIDTH * MAP_HEIGHT; pub const START_POINT: Point = Point::constant(2, 2); -pub const END_POINT: Point = Point::constant(MAP_WIDTH as i32 - 2, MAP_HEIGHT as i32 - 2); pub struct Map { pub tiles: Vec,