You are in a maze containing revolving doors. The doors can be turned 90
degrees by pushing against them in either direction. You are to find a
route from the start square to the end square that involves revolving as few
doors as possible. Given a map of the maze, determine the fewest number of
door revolutions necessary to get from the start to the end.
In the map:
' ': empty space
'#': wall
'O': center of a revolving door (letter "oh", not zero)
'-': horizontal door (always adjacent to a 'O')
'|': vertical door (always adjacent to a 'O')
'S': start square
'E': end square
Each revolving door will always be oriented horizontally (with two horizontal segments) or vertically (with two vertical segments):
|
O or -O-
|
Doors can be revolved 90 degrees by moving onto a door segment from any of the 4 squares diagonally adjacent to the door center, i.e., the 'X' characters below:
X|X X X
O or -O-
X|X X X
Here is an example map:
###
#E#
## #
#### ##
# S -O-#
# ### #
# #
########
In this example, 2 door revolutions are necessary to get from 'S' to 'E'. The first turn is shown here:
### ###
#E# #E#
## # ## #
#### ## #### |##
# S -O-# # S OX#
# ### X# # ###| #
# # # #
######## ########
And the second turn is shown here:
### ###
#E# #E#
## # ## #
####X|## #### X##
# S O # # S -O-#
# ###| # # ### #
# # # #
######## ########
Your method should return an int, the minimum number of door revolutions necessary to get from the start square to the end square.
If there is no way to reach the end square, return -1.
|