Introduction
Everyone knows that the possibility of successfully navigating an asteroid field is approximately 3,720 to 1. But despite your warning, Han Solo is still willing to try his luck.
Fearing for your artificial life, you decide to code, in the ship's peculiar dialect (read: your preferred Code Golf language), an asteroid avoidance program that will decide which path to take in an asteroid field ASCII maze.
Input
The Millenium Falcon has an asteroid field mapping program, that gives data similar to this:
| ##### ######### |
| ###### # ### # |
| # # # # #### # |
@ ## ####
|# # # ### ## |
|## ## #### # # |
|#### ##### # ## |
Top rows are left of the Falcon, bottom rows are right of the Falcon, and columns represent what is in front of the ship.
- Each
#
is an obstacle. - Each space is empty space that the ship can fly in.
- The input is always 7 characters high. This is the asteroid mapping width limit.
- The input is always 32 characters long (30 for the field itself and 2 for the start and end limits). This is the asteroid mapping depth limit. Vertical bars
|
mark the beginning and the end of the mapping. @
is the Falcon. It is always in the middle row (4th row) and first column in the input.- The space left in the vertical bars on the last column is the place the ship must arrive at. It is always in the middle row (4th row) and last column in the input.
The input can be taken as a multi-line string, an array of strings, from STDIN or a function parameters, or read from a file.
Possible maneuvers
You are pursued by TIE-Fighters, therefore you must always go forward. There are thus three ways the ship can fly at each step:
-
Forward/
Forward and turn left\
Forward and turn right
For example, these are valid paths:
@---
--
/ \ /
@ -
-
/ \
/ \
@ \
As you can see, there is always exactly one move per column. The Falcon is a piece of junk, therefore it cannot do violent turns. Which means moves such as /\
or \/
are disallowed. There must be atleast one pure forward -
between two opposite turns. On the other hand, turning one way for multiple steps in a row is possible, as seen above.
The Falcon crashes if one move leads the ship to be in a spot where an obstacle is. For example, these moves lead to crashes:
@-#
@
\
#
#
/
@
Note that this is not a crash:
@-#
\
-
Output
You must output the same asteroid field ASCII, with a valid path to the end. The Falcon must be printed at the end spot instead of the start spot.
For example, a valid output for the input example given before would be:
| ##### ######### |
| ###### #-------- ### # |
| # # #/ # ####\ # |
--------- ## \ #### ----@
|# # # ### \ ## / |
|## ## #### \ #/ # |
|#### ##### #-- ## |
Your path only needs to not crash the falcon. It doesn't need to be the shortest path possible.
You can assume that there will always be at least one possible path to the end.
You can output to STDOUT, in a file or any equivalent as long as the asteroid field is printed exactly like they are in this post (e.g. outputting a list of coordinates for the path is not valid).
Test cases
A normal asteroid field
| ##### ######### | | ###### # ### # | | # # # # #### # | @ ## #### |# # # ### ## | |## ## #### # # | |#### ##### # ## |
Possible output
| ##### ######### | | ###### #-------- ### # | | # # #/ # ####\ # | --------- ## \ #### ----@ |# # # ### \ ## / | |## ## #### \ #/ # | |#### ##### #-- ## |
Hyperregular asteroid field
|# # # # # # # # # # # # # # # | | # # # # # # # # # # # # # # #| |# # # # # # # # # # # # # # # | @ # # # # # # # # # # # # # # |# # # # # # # # # # # # # # # | | # # # # # # # # # # # # # # #| |# # # # # # # # # # # # # # # |
Possible output
|# # # # # # # # # # # # # # # | | # # # # # # # # # # # # # # #| |# # # # # # # # # # # # # # # | -# #-# #-# #-# #-# #-# #-# #--@ |#\#/#\#/#\#/#\#/#\#/#\#/#\#/# | | #-# #-# #-# #-# #-# #-# #-# #| |# # # # # # # # # # # # # # # |
Death star's core
| # # # # | | # # # | | # # # # # | @ # # # # # | # # # # | | # # # # # | | # # # # |
Possible output
| # # # -- # | | --- # # / #\ - | | / #\ # # / # \ /#\ | - # \ # #/ # - # ----@ | # \ # ---- # # | | # \#/ # # # | | # - # # # |
Death star trench
|##############################| |##############################| |##############################| @ |##############################| |##############################| |##############################|
Output
|##############################| |##############################| |##############################| ------------------------------@ |##############################| |##############################| |##############################|
Asteroid cave
|### ##########################| |## # ############### ## ######| |# ### ######## ### ## # #####| @ ###### ###### ### ## ### |######## ### ### ## #########| |########## # ### ## ##########| |########### #####|
Possible output
|###-##########################| |##/#\############### ##-######| |#/###--######## ### ##/#\#####| -######\###### ### ##/###-----@ |########--### ### ##/#########| |##########\# ### ##/##########| |###########-------- #####|
Scoring
R2D2 is busy swimming in swamps, so you're going to have to program the Falcon's controller by yourself, which is tedious. Therefore the shortest code wins.
-
in the path at each turn, which is defined as a "forward" move. But the actual moves are always two diagonal-left followed by two diagonal-right. \$\endgroup\$