it got cancelled
i am going to fucking kill myself xd
tomatenmhark: caniseeu
Implementation of an algorithm to check if a unit can see
another unit with the given obstacles on the map, using only
integers, because perfection and/or float hate i guess
spec
The algorithm works on a n*m grid of squares,
where each square may or may not be an obstacle.
Obstacles take up the entire square except for the edges,
so there is an infinitely small gap between obstacles.
Units can see through this gap, for example in the following situation:
o
|
###
###
###
###
o
|
This algorithm checks if one unit can attack another.
The conditions for this is that there is a line of sight
between the two units, specifically between the centers of the squares on
which the two units are positioned.
To avoid inaccuracies, this implementation uses only integers instead of floats.
api
A grid is represented as {width}/{height}/{grid}
, where {grid}
is a string of length {width}*{height}
,
which contains the squares of the actual grid in order left-to-right, then down a line.
Each character is either numeric, representing an obstacle, or alphabetic (a-Z), representing anything else.
The above grid could be represented as eeeue0eeee0eueee
:
eeeu
e0ee
ee0e
ueee
Where e = empty, u = unit, 0 = normal obstacle.
/check/{w}/{h}/{grid}/{x1}/{y1}/{x2}/{y2}
responds with 200 Ok
if there is a line of sight between (x1,y1) and (x2,y2) on the grid, or 404 Not Found
otherwise.
/checkall/{w}/{h}/{grid}/{x1}/{y1}
responds with a same-size grid where each square is either "y" (there is a line of sight) or "0" (there is not).