15
1
So, here's a map of, let's say, a dungeon...
##########
# #####
# #####
##########
##########
##########
##########
#### ##
#### ##
##########
Let's say that the hero is in Room A (at the top left) and their goal (a prince in distress?) is in Room B (to the bottom right). Our map does not allow the hero to progress to their goal.
We need to add a passageway...
##########
# #####
# #####
####.#####
####.#####
####.#####
####.#####
#### ##
#### ##
##########
There, much better!
Rules
- A program or function which accepts a dungeon map (made up of hashes and spaces, with rows separated by new line characters).
- It will output a map with dots added to denote passages in all spaces which are on a direct path between the space characters.
- It will not change the line length, or number of lines.
- Passages are all in a direct line from spaces to spaces.
- Passages can not turn around corners
- They will not be between spaces and the edge of the map.
- Use any language.
- Attempt to perform the conversion in the fewest bytes.
- If no passageways can be drawn, return the map, unchanged.
- The map should always have hashes around all edges (You do not need to handle spaces at the edge).
- Input maps are always rectangular, each row should be the same width.
Test cases
#### ####
# # => # #
# # # #
#### ####
########## ##########
# ##### # #####
# ##### # #####
########## ####.#####
########## => ####.#####
########## ####.#####
########## ####.#####
#### ## #### ##
#### ## #### ##
########## ##########
########## ##########
# ##### # #####
# ##### # #####
########## ##########
########## => ##########
########## ##########
########## ##########
###### ## ###### ##
###### ## ###### ##
########## ##########
########## ##########
# ##### # #####
# ##### # #####
########## ####.#####
########## => ####.#####
#### ### #### ###
########## ######.###
###### ## ###### ##
###### ## ###### ##
########## ##########
########## ##########
# ##### # #####
# ##### # #####
########## ##..######
########## => ##..######
########## ##..######
########## ##..######
## ####### ## .######
## ###### ## ######
########## ##########
########## ##########
# ##### # #####
# ##### # #####
########## #.########
########## => #.########
########## #.########
####### # #.##### #
####### # #.##### #
# ##### # # ..... #
########## ##########
########## ##########
# ##### # #####
# ##### # #####
########## #.########
##### ### => #.### ###
##### ### #.### ###
####### # #.##### #
####### # #.##### #
# ##### # # ..... #
########## ##########
########## ##########
## # ## #
########## ##......##
########## ##......##
########## => ##......##
########## ##......##
########## ##......##
########## ##......##
# ## # ##
########## ##########
########## ##########
#### #### #### ####
####### ## ####..# ##
###### ### ####.. ###
# ### ## # => # ... .. #
# ## ### # # .. ... #
### ###### ### ..####
## ####### ## #..####
#### #### #### ####
########## ##########
Can I use different characters than
#
and.
? – user202729 – 2018-04-05T14:36:26.3101@user202729 Nope. It was in the rules from the start, and there's already been one answer with it. Probably best to leave the reqs consistent. – AJFaraday – 2018-04-05T14:37:01.250
@user202729 The test case you suggested is similar to my penultimate case. I might add it when i next change the question, but it doesn't add much. – AJFaraday – 2018-04-05T14:57:06.797
... I just didn't scroll down. No problem. – user202729 – 2018-04-05T14:57:34.327
@l4m2 Same rules apply, wherever there's a straight line between rooms, it's a passage. So a u-shaped room would have the gap filled in with passages. – AJFaraday – 2018-04-05T14:58:55.250
"between rooms" may mean "should connect two different room", so i ask – l4m2 – 2018-04-05T15:00:21.813
@l4m2 Okay, that's the answer. It doesn't matter if it's a single room, if there's a straight line between parts of it. – AJFaraday – 2018-04-05T15:01:01.963
Are the inputs always squares? – recursive – 2018-04-05T15:20:21.217
@recursive Not necessarily (although all my test cases are). I think they should have to be rectangular. I'll edit the question. – AJFaraday – 2018-04-05T15:21:03.900
I think there's an issue with the second to last example. I think in the output there are extra # in the second column, specifically, (1,1) just shows up. Am I missing something? – Drise – 2018-04-05T21:19:07.180