20
2
Challenge
Write a program/function that accepts an "image" and outputs a picture maze formed from that image.
Input
Your program should accept two arguments:
- I, the image to form the maze from
- S, a boolean specifying whether or not to display the solution to the maze
I is given in the following form:
.......
.#####.
.#####.
#######
.#####.
.#####.
.......
where #
's are cells to be included in the solution path and .
's are cells to be excluded.
You may swap out the .
's, #
's and newlines with any character of your choosing as long as they differ from each other.
Alternatively, you may accept an actual bitmap of the input image.
Output
Your resulting maze should be in the following form:
###############
# #
# ### ####### #
# #.........# #
# #.#######.# #
# #.#.......# #
###.#.#########
....#.#........
#####.#.#######
# ...#..... #
# #.#######.# #
# #.........# #
# ####### ### #
# # # #
###############
where #
's denote walls, .
's denote portions of the path that are part of the solution, and spaces are paths excluded from the solution. The .
's may be replaced by spaces if S is false. Again, characters may be swaped with other characters of your choosing or you may output an actual bitmap of the maze with the solution highlighted.
Additional Details
- Paths must be one cell wide (cannot have giant pool of empty space be the path)
- The maze must not contain any loops
- The maze must be fully connected (all cells must be reachable from the entrance/exit)
- The maze must be surrounded by walls (unless its an entrance/exit)
- The solution path must not include dead-ends
- There must be exactly 1 entrance and 1 exit for the maze
- The entrance and exit must be aligned to the edge of the grid and adjacent to a cell included in the solution path
- You may choose where the entrance and exit are placed
- You may assume that a valid path can be formed from the given input image
(Added for clarification) The diagram below shows how the solution path is correlated to the input image:
Input (I): | Output: | Corresponding Cells:
| | (@'s denote #'s from I)
| |
....... | ############### | ###############
.#####. | # # | # #
.#####. | # ### ####### # | # ### ####### #
####### | # #.........# # | # #@.@.@.@.@# #
.#####. | # #.#######.# # | # #.#######.# #
.#####. | # #.#.......# # | # #@#@.@.@.@# #
....... | ###.#.######### | ###.#.#########
| ....#.#........ | .@.@#@#@.@.@.@.
| #####.#.####### | #####.#.#######
| # ...#..... # | # @.@#@.@.@ #
| # #.#######.# # | # #.#######.# #
| # #.........# # | # #@.@.@.@.@# #
| # ####### ### # | # ####### ### #
| # # # # | # # # #
| ############### | ###############
| |
Test Cases
Watering can example from Wikipedia:
Input:
..................
..................
.......####.......
......##..##......
.....##....##....#
.....#......#...##
.#############.##.
##..############..
#...###########...
#...##########....
#...##########....
#...##########....
#...##########....
....##########....
....##########....
....##########....
..................
..................
Output (S=false):
#####################################
# # # # # # #
# ### ### ### # # ##### ### ### ### #
# # # # # # # # # # #
# ### # ##### # ########### # ### # #
# # # # # # # # #
# # # ### ##### # ### ### # ### ### #
# # # # # # # # # # # # #
# ### # ##### ##### ### ##### # # ###
# # # # # # # # #
### ####### ### ### # ### ##### ### #
# # # # # # # # # # #
# ### ##### # ### ####### # # # # # #
# # # # # # # #
# # ##### ############# ### ### ### #
# # # # # # # # # #
# ### # ####### # ### ### # # ### # #
# # # # # # # # # #
# # # ### ######### # # ##### # #####
# # # # # # # # # # # #
# ##### # # ##### # ##### # # ### # #
# # # # # # # # # # #
# ### ### ### # ### # ##### ####### #
# # # # # # # # # #
# # # # ####### # ### # ##### # ### #
# # # # # # # # # # #
### # # # # # ############# # ### # #
# # # # # # # # # # #
##### # # ##### ####### # ### ##### #
# # # # # # # # #
##### # # # # ####### # ### #########
# # # # # #
# ### ######### ############# # #####
# # # # # # # # #
# # ######### # ####### ####### ### #
# # # #
#####################################
Output (S=true):
#####################################
# # # # # # #
# ### ### ### # # ##### ### ### ### #
# # # # # # # # # # #
# ### # ##### # ########### # ### # #
# # # #....... # # # # #
# # # ### #####.# ###.### # ### ### #
# # # # #...# # #...# # # # #
# ### # #####.##### ###.##### # # ###
# # # ...# # #... # # #..
### #######.### ### # ###.##### ###.#
# # #.# # # #.# # #...#
# ### #####.# ### #######.# # # #.# #
# #.......#.............#...# #...# #
# #.#####.#############.###.###.### #
#...# #.......#.....#...#.#...# # #
#.### # #######.#.###.###.#.#.### # #
#.# # # .......#...#.#...#...# #
#.# # ###.#########.#.#.##### # #####
#.# # #.#.......#.#...#...# # # #
#.##### #.#.#####.#.#####.#.# ### # #
#. #.#...#...#.#.....#.# # # #
#.### ###.###.#.###.#.#####.####### #
#. # # #.....#.#...#.#..... # #
#.# # # #######.#.###.#.##### # ### #
..# # # #...#...#.....#.....# # # #
### # # #.#.#.#############.# ### # #
# # # #.#...#.........#...# # # #
##### # #.#####.#######.#.### ##### #
# # #.#...#.......#.#...# #
##### # #.#.#.#######.#.###.#########
# # ...#.........#..... # #
# ### ######### ############# # #####
# # # # # # # # #
# # ######### # ####### ####### ### #
# # # #
#####################################
Bitmap example (same maze as above):
4It might just be me, but I don't see the input picture in the output maze. – Mike Bufardeci – 2015-09-29T00:33:23.037
@mike-bufardeci Added a diagram showing the input picture in the output maze. Hope that helps! – Dendrobium – 2015-09-29T01:01:11.107
2
There doesn't seem to be a rule requiring that the maze is connected. Would this be a valid solution? There also doesn't seem to be a rule that the grid must be surrounded by walls (unless every non-wall is considered an entrance or exit). Would this be a valid solution?
– Martin Ender – 2015-09-29T06:24:05.4301Also, please add some more test cases. – flawr – 2015-09-29T15:33:51.927
@MartinBüttner The maze should be fully connected and surrounded by walls, edited the question clarifying these points. – Dendrobium – 2015-09-29T16:41:50.600
@flawr Added more test cases. – Dendrobium – 2015-09-29T17:26:18.877