forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlos_symm.lua
63 lines (55 loc) · 1.71 KB
/
los_symm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Vet LOS for symmetry.
local FAILMAP = 'losfail.map'
local checks = 0
local function test_losight_symmetry()
-- Send the player to a random spot on the level.
you.random_teleport()
checks = checks + 1
local you_x, you_y = you.pos()
local visible_spots = { }
for y = -8, 8 do
for x = -8, 8 do
if x ~= 0 or y ~= 0 then
local px, py = x + you_x, y + you_y
-- It makes sense to check visibility of a cell on the border, but
-- we'd be unable to test the reverse.
if dgn.in_bounds(px, py) and you.see_cell(px, py) then
table.insert(visible_spots, { px, py })
end
end
end
end
-- For each position in LOS, jump to that position and make sure we
-- can see the original spot.
for _, spot in ipairs(visible_spots) do
local x, y = unpack(spot)
you.moveto(x, y)
if not you.see_cell(you_x, you_y) then
-- Draw the view to show the problem.
crawl.redraw_view()
local this_p = dgn.point(x, y)
local you_p = dgn.point(you_x, you_y)
dgn.fprop_changed(you_x, you_y, "highlight")
debug.dump_map(FAILMAP)
assert(false,
"LOS asymmetry detected (iter #" .. checks .. "): " .. you_p ..
" sees " .. this_p .. ", but not vice versa." ..
" Map saved to " .. FAILMAP)
end
end
end
local function run_los_tests(depth, nlevels, tests_per_level)
local place = "D:" .. depth
crawl.message("Running LOS tests on " .. place)
debug.goto_place(place)
for lev_i = 1, nlevels do
debug.flush_map_memory()
debug.generate_level()
for t_i = 1, tests_per_level do
test_losight_symmetry()
end
end
end
for depth = 1, 15 do
run_los_tests(depth, 1, 3)
end