40
7
Input
- A binary matrix \$M\$ representing the walls of a dungeon.
- The position \$(x,y)\$ of the player within the dungeon.
- The direction \$d\$ that the player is currently facing (0 = North, 1 = East, 2 = South, 3 = West)
Output
A pseudo-3D representation of the walls that are in the field of view of the player, as an ASCII art of \$30\times 10\$ characters.
Below are several possible output frames, along with the corresponding map and compass to help getting the hang of it (but drawing the map and the compass is not part of the challenge).
Specification
Field of view
The player has \$13\$ walls in his field of view, labeled from \$A\$ to \$M\$. Below are the positions of the walls relative to the player (in yellow), in all possible directions.
Drawing the walls
The walls are supposed to be drawn from \$A\$ to \$M\$ in this exact order, given that any part drawn previously may be overwritten by closer walls. You may of course implement it differently as long as the final result is the same.
The entire output is drawn with 7 distinct characters: " "
, "'"
, "."
, "|"
, "-"
, "_"
and ":"
.
Because detailing the shapes of the walls in the body of this challenge would make it too lengthy, they are instead provided in the following TIO link:
The characters that are not part of a given wall are marked with a "?"
in these diagrams. They must be treated as 'transparent' characters that are not drawn at all. On the other hand, all spaces within a wall are 'solid' and must overwrite any other characters that may have been previously drawn there.
Rules
About the input
- You may take \$M\$, \$x\$, \$y\$ and \$d\$ in any reasonable format.
- You may use either 0-indexed or 1-indexed coordinates.
- You may use 4 distinct values of your choice for the directions.
- The matrix is guaranteed to be at least \$3\times 3\$.
- You may assume that there will always be surrounding walls on the edges.
- The player is guaranteed to be located on an empty square.
- The input is guaranteed to be valid.
About the output
- The walls must be drawn exactly as described.
- However, the output format is also flexible: single string, array of strings, matrix of characters, etc.
- Leading and trailing whitespace is acceptable as long as it's consistent.
This is code-golf.
Test cases
All test cases are using the following matrix:
[ [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 0, 1, 1, 1, 0, 0, 0, 0, 1 ],
[ 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 0, 0, 0, 1, 1, 0, 1 ],
[ 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ],
[ 1, 1, 1, 1, 0, 0, 0, 0, 0, 1 ],
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ]
The following inputs are using 0-indexed coordinates, with \$(0,0)\$ pointing to the top-left corner.
x=3, y=3, d=0
x=6, y=4, d=3
x=4, y=4, d=1
x=1, y=5, d=2
x=7, y=7, d=3
x=6, y=6, d=1
x=8, y=1, d=2
x=7, y=6, d=1
Expected outputs:
------------------------------ ------------------------------
x=3, y=3, d=0: x=6, y=4, d=3:
------------------------------ ------------------------------
__ __ '. .'
|'. .'| | |
| '.--------------.' | |----. |
| | | | | | '.--------. |
| | | | | | | | |
| | | | | | | | |
| | | | | | .'--------' |
| .'--------------'. | |----' |
__|.' '.|__ | |
.' '.
------------------------------ ------------------------------
x=4, y=4, d=1: x=1, y=5, d=2:
------------------------------ ------------------------------
.' __ ________________________ .'
| | |
-------. .----| | |
| '.--------.' | | | |
| | | | | | |
| | | | | | |
| .'--------'. | | | |
-------' '----| | |
| __|________________________|
'. '.
------------------------------ ------------------------------
x=7, y=7, d=3: x=6, y=6, d=1:
------------------------------ ------------------------------
'. '.
|'. |'.
| '. | '.
| | '. .- | |--.--------.--------.-
| | |: :| | | | | |
| | |: :| | | | | |
| | .' '- | |--'--------'--------'-
| .' | .'
|.' |.'
.' .'
------------------------------ ------------------------------
x=8, y=1, d=2: x=7, y=6, d=1:
------------------------------ ------------------------------
'. __ '.
|'. .'| |
| '. .' | |----.--------------.-------
| | '. .' | | | | |
| | |: :| | | | | |
| | |: :| | | | | |
| | .' '. | | | | |
| .' '. | |----'--------------'-------
|.' '.|__ |
.' .'
Related challenge:
This challenge from 2013 is closely related. But it has a different winning criterion (code-challenge), a much looser specification of the output, and requires interactive I/O.
This instantly reminded me of 3D Monster Maze, although that uses block graphics of course. – Neil – 2018-12-20T23:37:48.500
9Your challenges are so fun and well-written! – Oliver – 2018-12-21T00:32:49.980
Waiting for a solution in Minecraft... – None – 2018-12-22T20:20:05.840
Does anyone else remember the windows screen saver? Was such a fun "game" when I was 5 or 6...
– Magic Octopus Urn – 2019-01-31T19:44:18.560