Doorknobs are great and all, but when you open a door, it always dents the walls around it. I need you to take input of ASCII art of a room, like this:
+---------+--X --X --+-----+ | \ \ |\ | \ | | \ \ | \ | \| | X | \ | X | / | | \ X | / | \ / | / | \ / | +---X --+-------X------+-----+
And output the room with doorstops, like this:
+---------+--X --X --+-----+ | \ . \ |\ | \.| | \ \ | \ .| \| | X | \ | X | / | |. \ X | / .| \ / |. / | .\ / | +---X --+-------X------+-----+
- The ASCII room (input) will consist of
|. These characters are purely cosmetic; they could all be
+s but that would look horrible. It will also contain hinges (
X) and doors (
- Doors are made up of
\. Starting from the "hinge" character, which is
X, they will go directly diagonally (change of 1 in
xand 1 in
y) for 2 or more units (characters).
To find where to put the doorstop for a door (there is always only one doorstop per door), find the doorway for the door. The doorway will always start at one hinge, and go the same amount of spaces as the door's length up, down, left, or right from there. The next space after that will always be a wall. For example, in this door, the doorway is marked by
\ \ ---DDX-----
One the doorway is found, find out whether you need to go clockwise or counterclockwise to reach the door. For example, in that example door above, you have to go clockwise, and in this one, you must go counterclockwise:
\ <- \ ) -----X ---
Once you know which way to go, keep going that way (ignoring the door) until you reach a wall.
Here's a visualization of that for the example door above:
The blue is the doorway, the orange is finding that you must go clockwise, and the red is continuing to go clockwise until a wall is reached.
Once you reach a wall, go (the door's length) spaces from the hinge (
X) on that wall, move one space away from the wall towards the door (so you don't place the doorstop right on the wall), and insert a
.there. Here's the same example door showing how the doorstop is placed:
\ \ . ---DDX12---
Repeat for every door, and output the result! Use the example input at the top of this post as a test case to check if your program is valid.
Note that you do not have to handle doors that don't fit on their walls, such as:
| / | / | / | / +-X --
/ / / +-X -- | |
- This is code-golf, so the shortest code in bytes will win.