Sub ZoomIn (x As Int, y As Int) As Boolean
'Accept Case - we found the destination
If x = DestX And y = DestY Then
Visited(x, y) = True
Return True
End If
'Reject Case - we hit a block|wall Or our path
If Blocked(x, y) Or Visited(x, y) Then Return False
Visited(x, y) = True
dx = DestX - x
dy = DestY - y
If dx < 0 Then dxa = -dx Else dxa = dx
If dy < 0 Then dya = -dy Else dya = dy
'version: 1 'i = x < 0 ? -x : x; -- version: 2 'i = (x ^ (x >> 31)) - (x >> 31);
If (dxa > dya) Then ' Move along the X axis
If dx > 0 Then ' Try East first
' Order(0) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
If dy >= 0 Then
' Order(1) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
' Order(2) = NORTH
If y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
Else
' Order(1) = NORTH
If Y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
' Order(2) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
End If
' Order(3) = WEST
If x > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
Else ' Try West first
' Order(0) = WEST
If x > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
If dy >= 0 Then
' Order(1) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
' Order(2) = NORTH
If Y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
Else
' Order(1) = NORTH
If Y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
' Order(2) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
End If
' Order(3) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
End If
Else ' Move along the Y axis
If dy > 0 Then ' Try South first
' Order(0) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
If dx < 0 Then
' Order(1) = WEST
If X > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
' Order(2) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
Else
' Order(1) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
' Order(2) = WEST
If X > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
End If
' Order(3) = NORTH
If Y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
Else ' Try North first
' Order(0) = NORTH
If Y > 0 And Blocked(x, y-1) = False Then
If ZoomIn(x, y-1) Then Return True
End If
If dx < 0 Then
' Order(1) = WEST
If X > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
' Order(2) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
Else
' Order(1) = EAST
If x < SizeX -1 And Blocked(x+1, y) = False Then
If ZoomIn(x+1, y) Then Return True
End If
' Order(2) = WEST
If X > 0 And Blocked(x-1, y) = False Then
If ZoomIn(x-1, y) Then Return True
End If
End If
' Order(3) = SOUTH
If y < SizeY - 1 And Blocked(x, y+1) = False Then
If ZoomIn(x, y+1) Then Return True
End If
End If
End If
'Deadend - this location can't be part of path
Return False
End Sub