jamis / theseus

A very flexible random maze generator, solver, and renderer for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot solve mazes with wrap x or wrap xy, wrap y works fine

MtnViewJohn opened this issue · comments

Theseus can solve mazes with no wrapping or with wrap y but it hangs when trying to solve mazes with wrap x or wrap xy. The astar solver cannot solve with wrap y.

john@paravmubuntu16_04:~$ theseus -w 10 -H 10 --wrap x -f png -o maze
maze written to maze.png
john@paravmubuntu16_04:~$ theseus -w 10 -H 10 --wrap x -f png -o maze -V
^C/var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/solvers/base.rb:29:in `solved?': Interrupt
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/solvers/base.rb:43:in `solve'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/formatters/png.rb:79:in `initialize'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/formatters/png/orthogonal.rb:16:in `initialize'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/maze.rb:653:in `new'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/maze.rb:653:in `to'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/cli.rb:157:in `block in run_static'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/cli.rb:157:in `open'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/cli.rb:157:in `run_static'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/cli.rb:70:in `run'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/lib/theseus/cli.rb:25:in `run'
	from /var/lib/gems/2.3.0/gems/theseus-1.1.0/bin/theseus:5:in `<top (required)>'
	from /usr/local/bin/theseus:23:in `load'
	from /usr/local/bin/theseus:23:in `<main>'

john@paravmubuntu16_04:~$ theseus -w 10 -H 10 --wrap y -f png -o maze -V
maze written to maze.png
john@paravmubuntu16_04:~$ 

This is because of how the default entrance and exit are determined by theseus. When wrapping in x (or xy), theseus's default algorithm for finding those points doesn't work, so the solver gets stuck trying to find a path between two points that aren't actually connected to the maze.

While theseus should definitely handle this case more gracefully, you can work around it in the meantime by telling it exactly where you want solution to start and stop, e.g.:

$ theseus -w 10 -H 10 --wrap x -f png -o maze -V -E 0,0 -X 9,9
maze written to maze.png

The -E option says which cell should be treated as the entrance (starting point), and the -X says which cell should be treated as the exit (ending point).

Maybe theseus should just refuse to create a default entrance and exit if wrapping is enabled. There is still something going on with the astar algorithm. This command sometimes hangs and sometimes runs to completion:

theseus -w 40 -H 10 --solve astar --wrap x -E 0,0 -X 20,9 -f png -o maze2

The backtracker algorithm always seems to work if an entrance and exit are provided.

Yeah. To be honest, I don't really have a lot of time to maintain this program. It needs to be rewritten (the existing architecture makes some dubious choices) and tested (the existing tests don't really cover much). It's not much better than a proof-of-concept at the moment, though it can do some fun things if you're willing to work around the quirks. :/