Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix solution rendering for mazes that wrap

  • Loading branch information...
commit 01600e45b2ccb5080f8048b772394be1b218a041 1 parent af72e0b
@jamis authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/theseus/maze.rb
View
16 lib/theseus/maze.rb
@@ -568,7 +568,21 @@ def adjacent_point(point)
# Returns the direction of +to+ relative to +from+. +to+ and +from+
# are both points (2-tuples).
def relative_direction(from, to)
- if from[0] < to[0]
+ # first, look for the case where the maze wraps, and from and to
+ # are on opposite sites of the grid.
+ if wrap_x? && from[1] == to[1] && (from[0] == 0 || to[0] == 0) && (from[0] == @width-1 || to[0] == @width-1)
+ if from[0] < to[0]
+ W
+ else
+ E
+ end
+ elsif wrap_y? && from[0] == to[0] && (from[1] == 0 || to[1] == 0) && (from[1] == @height-1 || to[1] == @height-1)
+ if from[1] < to[1]
+ N
+ else
+ S
+ end
+ elsif from[0] < to[0]
if from[1] < to[1]
SE
elsif from[1] > to[1]
Please sign in to comment.
Something went wrong with that request. Please try again.