8000 GitHub - talldan/mazes: Implements some of the Mazes from the 'Mazes for Programmers' book using Rust / Bevy
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

talldan/mazes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mazes

This is a learning project for the Rust language and the Bevy game engine.

It implements four of the maze algorithms from the 'Mazes for Programmers' book by James Buck, which are all very simple. Those are:

That book is originally written in Python, so this is a 'port' of sorts, but the code is different to what the book presents. I've avoided some patterns from the book, like maintaining a list of cells that store references to neighbour cells, as my understanding is that would require reference counting in Rust (Rc, or possibly even Arc given Bevy systems run in parallel, see https://doc.rust-lang.org/book/ch15-04-rc.html for more info).

Try the demo

The demo is viewable here - https://talldan.github.io/mazes/.

By default this shows a maze generated using the 'Aldous Broder' algorithm on a 15x15 grid, and the random number generator is seeded using the integer 0, so when the first maze will always be the same.

The 'Go' and 'End' are the start and end points for the maze, and these will always be as far apart as possible.

There are three controls you can use to the change the maze:

  • 'Rando-maze' - this randomizes the random number generator seed, and a random maze will be generated.
  • 'Show solution' - this toggles on an overlay that shows the solution for the maze:
    • The numbers in each cell represent the distance to the cell from the start.
    • The red numbers indicate the path from the start to the finish.
  • 'Maze type' - this dropdown allows changing maze algorithm.

Future improvements

I'm not sure whether I'll devote more time to this, but here's some possible future improvements:

  • Bug: The start and end points aren't always in the same place for a given maze. For some mazes, there might be multiple possibilities of which cell is the start/end. This is ok, but the process of choosing them should be deterministic and consistently reproducible. I expect it's not because those start/end locations are calculated by iterating through an unordered collection type (HashMap), so sometimes a particular cell might be encountered first, sometimes a different cell.
  • Reduce the build size.
  • Change the button colors to something with more contrast.
  • Add more algorithms from the book.
  • Add some unit tests.
  • Show an animation of the maze generation.
  • Make the 'Maze type' dropdown close on a click outside.
  • Make the maze playable.
  • Use HTML for the controls - Bevy's UI primitives are quite basic.
  • Add controls for:
    • Changing the maze dimensions.
    • Typing in a specific seed for the random number generator.

About

Implements some of the Mazes from the 'Mazes for Programmers' book using Rust / Bevy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0