Rob the King: Hexagonal Mazes
Consider the following hexagonal maze:
E . \ . . .
. . . \ . \ .
. . . . \ . \ .
_ _ _ _ . \ . \ .
. / . . . . . . | .
. | . . _ _ _ _ / . .
. \ . \ . . . / . .
. \ . \ . . / . .
. \ . \ . . . .
. \ . \ / . .
. \ . | . X
E
represents the entrance, X
the exit. |_/\
are walls and .
are free spaces. In order to navigate from E
to X
, we can move to any free space in the up to 6 immediately surrounding spaces. The path from E
to X
, marked with P
is:
E P \ P P P
. . P \ P \ P
. . . P \ P \ P
_ _ _ _ P \ P \ P
. / . . . P P P | P
. | . . _ _ _ _ / . P
. \ . \ . . . / . P
. \ . \ . . / . P
. \ . \ . . . P
. \ . \ / . P
. \ . | . X
This isn't the only path, but the others are trivial variations on it.
Cops
You are to write a function in Python 3 which takes a positive integer \$n \ge 2\$ and returns a hexagonal maze of side-length \$n\$, as shown above. The maze will meet the following criteria:
- The only characters in the output are
EX.|_\/
, space and newline
- The hexagon is shown as a hexagon. That means:
- The first \$n\$ lines will have one more non-space character than the previous line (the first has \$n\$ non-space characters), separated by a single space, and offset from adjacent lines
- The first \$n\$ lines have one fewer leading space than the previous line (the first line has \$n - 1\$ leading spaces)
- The next \$n - 1\$ lines have one more leading space than the previous line
- The next \$n - 1\$ lines will have one fewer non-space character than the previous line, separated by a single space, and offset from adjacent lines
- Lines may not have trailing whitespace
- The
E
is the first non-space character on the first line, and the X
is the last non-space character on the last line
- There is at least 1 valid path that connects the
E
and the X
, only moving from one free space to an adjacent free space.
How your program generates these mazes is entirely up to you. It could randomly places walls in the grid, ensuring there is always at least one path left, or it could only block the center row except for one gap, or anything else.
You may return either a multi-line string, or a list of lines. Lines should have appropriate space padding at the start, and may have a consistent amount of trailing spaces. "Consistent" here means either the same number on each line, or padding each line to the same length.
The Robbers will be writing maze-solving programs that try to solve your mazes, so you should aim to generate mazes that are somewhat difficult to solve.
This is not code-golf, you are under no obligation to golf your submission.
Additionally, you may submit multiple submissions. You may not include anything in your submission that attempts to communicate with other submissions, attempts to interfere with other submissions or the controller or anything that could be malicious. If you do, your submission will be disqualified
Empty mazes of sizes \$n = 2, 3, 4, 5, 6\$:
E . . . . .
E . . . . . . . . . . .
E . . . . . . . . . . . . . . . . .
E . . . . . . . . . . . . . . . . . . . . . . .
E . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. X . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . X . . . . . . . . . . . . . . . . . . . . .
. . . X . . . . . . . . . . . . . .
. . . . X . . . . . . .
. . . . . X
Robbers
You are to write a Python 3 function that takes in the return value of a cop's answer. It may also take the number of sides, \$n\$, as an argument if you so wish. The input will only contain EX_|/\.
and space, and newlines if inputting as a multiline string. It will either be a multiline string or a list of lines. Your function should handle both.
Your function should then output the maze with any valid path connecting the E
and X
using only connected free spaces. You may show the path with any character aside from EX_|/\.
, space or newline.
This is not code-golf, you are under no obligation to golf your submission.
Additionally, you may submit multiple submissions. You may not include anything in your submission that attempts to communicate with other submissions, attempts to interfere with other submissions or the controller or anything that could be malicious. If you do, your submission will be disqualified
Scoring
The scoring will take the form of a round-robin, similar to king-of-the-hill challenges. Every cop will be paired up with every robber, and the following will happen with each pair:
- The controller will call the cop's function 5 times with \$n = 2\$ as an argument, saving each of the 5 mazes. The cop will have 1 minute to produce each maze
- It will then pass each maze to the robber to solve. The robber will have 1 minute per maze to produce a correct output.
- If all 5 mazes are correctly solved by the robber within 1 minute each, the controller goes again, but with \$n = 3\$, and so on, increasing the \$n\$ by one, until either:
- The robber fails to solve a maze within 1 minute
- The robber produces an incorrect solution to an input maze
- The cop fails to return a maze within 1 minute
- The cop returns a maze with no path
At this point, both the cop and the robber receive points equal to the highest \$n\$ that neither of them failed. If the cop failed, the robber receives an additional point, and if the robber failed, the cop receives an additional point instead.
If both the cop and the robber reach \$n = 50\$ without failing, they both receive \$50\$ points.
After all pairs have be run, the cop and robber with the most points are the respective winners
Meta