ADOM
Time limit1sMemory limit128 MB
For each board, remove every wall tile that the hero at the center of P cannot see within visibility radius r, given that walls block line of sight.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force, Implementation
- Solved
- No attempts yet
Problem
A roguelike game draws its world with ASCII characters: every tile is a square, and the map shows the walls of buildings and the hero. We must compute what the hero can see.
The visibility model is realistic: an object hidden behind a wall is not shown, and the hero can only perceive objects within a maximum distance, the visibility radius . In this simplified version the only objects on the map are the square walls of buildings.
Given the map, determine which walls the hero can see.
Input
The first line contains the number of test cases .
The first line of each test case contains three integers , , : the height of the board, the width of the board, and the hero's visibility radius.
The next lines contain characters each and describe the board: . is an empty tile, X is a wall, and P is the hero's position. Each board contains exactly one P.
Output
For each test case, output the board with every wall (X) that the hero cannot see replaced by .. Print the boards in order, separating consecutive boards with a single blank line.
Visibility is defined as follows.
- A wall
Xcompletely fills its square tile, and there is no gap between two adjacent walls. - The hero's observation point is exactly the center of the tile containing
P. - A wall is considered visible if there exists a point in its square such that (1) the straight-line distance from the observation point to is at most , and (2) the open segment from the observation point to does not pass through the interior of any other wall. In other words, a wall is visible if even its smallest fragment is visible.
- Because each wall fills its tile completely and adjacent walls leave no gap, a line of sight cannot pass through a point where two walls meet only at a single corner.