Saturday
May182019

Lee Maze, a new rust crate on crates.io

Leemaze is my latest crate, offered as a MIT/Apache2 licensed, open source gift to the Rust programming community.  It's named after the Lee Algorithm https://en.wikipedia.org/wiki/Lee_algorithm.  It solves 2d, 3d, 4d and 5d block mazes.  A 5d block maze is basically your morning commute with moving walls (cars) and 2% driver crazies that cause ..predictably best avoided.. random daily events, so... yea... if you are trying to avoid things that haven't even happened yet you might be living in a 5d maze world.   

What does leemaze do?  It gives maze directions.  Feed it a boolean block maze and it will find one contender for shortest possible path.  Or maybe it returns a None().  Or if your entrance is your exit a empty vec![].  Any maze with a open 2x2 block may have multiple shortest path solutions.   

Why did I make leemaze?  I was learning the superb KISS3D rust graphics library in April and wrote a 3D block maze.  Then I decided to generalize my code - navigation is a common computing problem after all... and then realized that rust didn't have jump out at me obvious Lee Maze crate that did the same thing.

how does it work?  Forgive the unchecked code- i'm in a HTML editor but my intent is all goodnesss -

       use leemaze::{AllowedMoves2D, boolify_2d_maze, maze2dpath};

let mymaze = vec![

                   vec![0,1,0],

                   vec![0,1,0],

                   vec![0,0,0], ];

let maze = boolify_2d_maze[&mymaze, &0];  //convert type to boolean trues and falses,  

let northsoutheastwest = AllowedMoves2D {rules: vec![(0,-1),(0,1),(1,0),(-1,0)] };  //allowed x,y axis moves.  

let entrance = (0,0);

let mazeexit = (0,3);

let maze_escape_directions = maze2dpath(&maze, &northsoutheastwest, &entrance, &mazeexit);

And that's it, out comes a None() or a Some(contender_for_shortest_possible_maze_directions).  Um... are the directions indexed? YES, from the list of AllowedMoves2D you provide --> if your allowed moves were 'northsoutheastwest', maze_escape_directions might be vec![1,1,2,2,0,0] - for south south, east east, north north.  Use the directions to move your robotic death tank or NPC towards its goal.

Ok, all well and good but I want to do a 5d maze, hows that work?  Build a 5d maze and just replace AllowedMoves2D --> AllowedMoves5D,  boolify_2d_maze --> boolify_5d_maze, and maze2dpath --> maze5dpath.   

So a gift of code to the rust community, enjoy.  And good luck on your morning commutes.  :)     

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Game of Thrones Should Issue Season 8 Shorts | Main | A Round Up on why it sucks to be Bayer »