Skip to content

Commit

Permalink
Just use faster maze algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Cox committed Jun 21, 2013
1 parent bafddc1 commit 6804283
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 536 deletions.
5 changes: 0 additions & 5 deletions Makefile
@@ -1,11 +1,6 @@
all: maze fastmaze

maze: maze.c madatabase.c madatabase.h
gcc -Wall -DDD_DEBUG -g maze.c madatabase.c -o maze -lddutil-dbg

fastmaze: fastmaze.c madatabase.c madatabase.h
gcc -Wall -DDD_DEBUG -g fastmaze.c madatabase.c -o fastmaze -lddutil-dbg

madatabase.c: madatabase.h

madatabase.h: Maze.dd
Expand Down
4 changes: 1 addition & 3 deletions Maze.dd
Expand Up @@ -3,8 +3,6 @@ module Maze ma
class Maze

class Room
bool start
bool finish

class Door
bool explored
Expand All @@ -16,7 +14,7 @@ class Path
Path prevPath
bool mostRecent

relationship Maze Room doubly_linked mandatory
relationship Maze Room hashed mandatory
relationship Maze Room:start child_only
relationship Maze Room:finish child_only
relationship Room:from Door:out doubly_linked mandatory
Expand Down
20 changes: 8 additions & 12 deletions README.md
Expand Up @@ -63,15 +63,11 @@ quadratic in terms of the size of the maze.

###Improvements

Various improvements are possible, but I'd like to keep this algorithm simple.
For one thing, we don't have to build loops when we don't discover any rooms
without paths that have unexplored doors. Also, we could combine creating a
loop and splicing paths in one transition of the loop instead of two whenever we
create a loop in a room that already has a path. Another improvement would be
doing a better job of detecting when we have to reset our startLabel, as we
don't have to do it every time we delete a loop or splice paths together.
However, all of these improvements provide only a constant factor speedup, while
complicating the code.

The basic version of the algorithm is in maze.c. A version with some of these
speed improvements is in fastmaze.c
Various improvements are possible. For one thing, we don't have to build loops
when we don't discover any rooms without paths that have unexplored doors.
Also, we could combine creating a loop and splicing paths in one transition of
the loop instead of two whenever we create a loop in a room that already has a
path. Another improvement would be doing a better job of detecting when we have
to reset our startLabel, as we don't have to do it every time we delete a loop
or splice paths together. Some of this is done in maze.c, for about 2X speed
improvement.

0 comments on commit 6804283

Please sign in to comment.