Skip to main content
Commonmark migration
Source Link

##Input

Input

##Output

Output

##Specification

Specification

###Field of view

Field of view

###Drawing the walls

Drawing the walls

##Rules

Rules

###About the input

About the input

###About the output

About the output

##Test cases

Test cases

##Input

##Output

##Specification

###Field of view

###Drawing the walls

##Rules

###About the input

###About the output

##Test cases

Input

Output

Specification

Field of view

Drawing the walls

Rules

About the input

About the output

Test cases

Tweeted twitter.com/StackCodeGolf/status/1076039579009011712
added x, y and d in the animation
Source Link
Arnauld
  • 206.5k
  • 21
  • 189
  • 673

animationanimation

  • 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.

The following inputs are using 0-indexed coordinates:, with \$(0,0)\$ pointing to the top-left corner.

animation

  • 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.

The following inputs are using 0-indexed coordinates:

animation

  • 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.

The following inputs are using 0-indexed coordinates, with \$(0,0)\$ pointing to the top-left corner.

Source Link
Arnauld
  • 206.5k
  • 21
  • 189
  • 673

Dungeon Crawler

##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).

animation

##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.

field of view

###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:

Try it online!

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 .

##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:

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.