From 0b21b9fcf0a01574cf1be84dd9900e32d95a1e79 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Wed, 7 Oct 2009 22:17:12 +0200 Subject: Add test to compare LOS against sample maps. New test cases can be added by adding appropriate maps to debug-los.des. Also separate the LOS tests into three separate files. --- crawl-ref/source/dat/debug-los.des | 236 +++++++++++++++++++++++++++++++++++++ crawl-ref/source/test/los.lua | 111 ----------------- crawl-ref/source/test/los_gsg.lua | 58 +++++++++ crawl-ref/source/test/los_maps.lua | 56 +++++++++ crawl-ref/source/test/los_symm.lua | 67 +++++++++++ 5 files changed, 417 insertions(+), 111 deletions(-) create mode 100644 crawl-ref/source/dat/debug-los.des delete mode 100644 crawl-ref/source/test/los.lua create mode 100644 crawl-ref/source/test/los_gsg.lua create mode 100644 crawl-ref/source/test/los_maps.lua create mode 100644 crawl-ref/source/test/los_symm.lua (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/dat/debug-los.des b/crawl-ref/source/dat/debug-los.des new file mode 100644 index 0000000000..42736b44fa --- /dev/null +++ b/crawl-ref/source/dat/debug-los.des @@ -0,0 +1,236 @@ +# Sample maps illustrating what LOS should be like. +# test/los_maps.lua tests losight() against these. +# +# For the moment, these need to be 10x10 with an @ +# in the nw corner and show one quadrant, with +# visibility encoded as follows. +# +# x: visible wall +# c: non-visible wall +# .: visible floor +# w: non-visible floor (water actually; could just place c's there) +# @: center + +NAME: los_empty +ORIENT: float +TAGS: debug_los +MAP +@........c +.........c +........cc +........cc +........cc +.......ccc +......cccc +.....ccccc +..cccccccc +cccccccccc +ENDMAP + +NAME: los_edge +ORIENT: float +TAGS: debug_los +MAP +@.......xc +.......xxc +.......xcc +.......xcc +......xxcc +.....xxccc +....xxcccc +.xxxxccccc +xxcccccccc +cccccccccc +ENDMAP + +NAME: los_blocking_wall +ORIENT: float +TAGS: debug_los +MAP +@..xwwwwwc +..xxwwwwwc +.xxwwwwwcc +xxwwwwwwcc +wwwwwwwwcc +wwwwwwwccc +wwwwwwcccc +wwwwwccccc +wwcccccccc +cccccccccc +ENDMAP + +NAME: los_corner +ORIENT: float +TAGS: debug_los +MAP +@xcccccccc +x........c +cxxxxxxxcc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_2 +ORIENT: float +TAGS: debug_los +MAP +@.xccccccc +xx.......c +cccxxxxxcc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_3 +ORIENT: float +TAGS: debug_los +MAP +@..xcccccc +xxx......c +cccccxxxcc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_4 +ORIENT: float +TAGS: debug_los +MAP +@...xccccc +xxxx.....c +cccccccxcc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_5 +ORIENT: float +TAGS: debug_los +MAP +@....xcccc +xxxxx....c +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_6 +ORIENT: float +TAGS: debug_los +MAP +@.....xccc +xxxxxx...c +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_7 +ORIENT: float +TAGS: debug_los +MAP +@......xcc +xxxxxxx..c +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_8 +ORIENT: float +TAGS: debug_los +MAP +@.......xc +xxxxxxxx.c +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_corner_9 +ORIENT: float +TAGS: debug_los +MAP +@........c +xxxxxxxxxw +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +cccccccccc +ENDMAP + +NAME: los_gap +ORIENT: float +TAGS: debug_los +MAP +@.xccccccc +x.xccccccc +c..ccccccc +c...cccccc +c....ccccc +c.....cccc +c.....cccc +c....ccccc +c.cccccccc +cccccccccc +ENDMAP + +NAME: los_gap2 +ORIENT: float +TAGS: debug_los +MAP +@.xccccccc +x.xccccccc +c.xccccccc +c..ccccccc +c..ccccccc +c...cccccc +c...cccccc +c....ccccc +c.cccccccc +cccccccccc +ENDMAP diff --git a/crawl-ref/source/test/los.lua b/crawl-ref/source/test/los.lua deleted file mode 100644 index 8feb0bc7f4..0000000000 --- a/crawl-ref/source/test/los.lua +++ /dev/null @@ -1,111 +0,0 @@ --- Vet LOS for symmetry. - -local FAILMAP = 'losfail.map' -local checks = 0 - -local function test_losight_symmetry() - -- Clear messages to prevent them accumulating and forcing a --more-- - crawl.mesclr() - -- Send the player to a random spot on the level. - you.random_teleport() - - -- Forcibly redo LOS. - you.losight() - - 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 - if you.see_grid(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) - you.losight() - if not you.see_grid(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.grid(you_x, you_y, "floor_special") - dgn.dbg_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 test_gridseegrid_symmetry() - -- Clear messages to prevent them accumulating and forcing a --more-- - crawl.mesclr() - -- Send the player to a random spot on the level. - you.random_teleport() - - checks = checks + 1 - local you_x, you_y = you.pos() - - for y = -9, 9 do - for x = -9, 9 do - local px, py = x + you_x, y + you_y - if (x ~= 0 or y ~= 0) and dgn.in_bounds(px, py) then - local foreward = dgn.grid_see_grid(you_x, you_y, px, py) - local backward = dgn.grid_see_grid(px, py, you_x, you_y) - this_p = dgn.point(you_x, you_y) - other_p = dgn.point(px, py) - if not forward then - you.moveto(px, py) - local temp = this_p - this_p = other_p - other_p = temp - end - if forward ~= backward then - dgn.grid(other_p.x, other_p.y, "floor_special") - dgn.dbg_dump_map(FAILMAP) - assert(false, - "grid_see_grid asymmetry detected (iter #" .. checks .. "): " - .. this_p .. " sees " .. other_p .. ", but not vice versa." - .. " Map saved to " .. FAILMAP) - end - end - end - end -end - -local function run_los_tests(depth, nlevels, tests_per_level) - local place = "D:" .. depth - crawl.mpr("Running LOS tests on " .. place) - dgn.dbg_goto_place(place) - - for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() - for t_i = 1, tests_per_level do - test_losight_symmetry() - end - end - - for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() - for t_i = 1, tests_per_level do - test_gridseegrid_symmetry() - end - end -end - -for depth = 1, 27 do - run_los_tests(depth, 1, 10) -end diff --git a/crawl-ref/source/test/los_gsg.lua b/crawl-ref/source/test/los_gsg.lua new file mode 100644 index 0000000000..69b86d1da7 --- /dev/null +++ b/crawl-ref/source/test/los_gsg.lua @@ -0,0 +1,58 @@ +-- Vet LOS for symmetry. + +local FAILMAP = 'losfail.map' +local checks = 0 + +local function test_gridseegrid_symmetry() + -- Clear messages to prevent them accumulating and forcing a --more-- + crawl.mesclr() + -- Send the player to a random spot on the level. + you.random_teleport() + + checks = checks + 1 + local you_x, you_y = you.pos() + + for y = -9, 9 do + for x = -9, 9 do + local px, py = x + you_x, y + you_y + if (x ~= 0 or y ~= 0) and dgn.in_bounds(px, py) then + local foreward = dgn.grid_see_grid(you_x, you_y, px, py) + local backward = dgn.grid_see_grid(px, py, you_x, you_y) + this_p = dgn.point(you_x, you_y) + other_p = dgn.point(px, py) + if not forward then + you.moveto(px, py) + local temp = this_p + this_p = other_p + other_p = temp + end + if forward ~= backward then + dgn.grid(other_p.x, other_p.y, "floor_special") + dgn.dbg_dump_map(FAILMAP) + assert(false, + "grid_see_grid asymmetry detected (iter #" .. checks .. "): " + .. this_p .. " sees " .. other_p .. ", but not vice versa." + .. " Map saved to " .. FAILMAP) + end + end + end + end +end + +local function run_los_tests(depth, nlevels, tests_per_level) + local place = "D:" .. depth + crawl.mpr("Running LOS tests on " .. place) + dgn.dbg_goto_place(place) + + for lev_i = 1, nlevels do + dgn.dbg_flush_map_memory() + dgn.dbg_generate_level() + for t_i = 1, tests_per_level do + test_gridseegrid_symmetry() + end + end +end + +for depth = 1, 27 do + run_los_tests(depth, 1, 10) +end diff --git a/crawl-ref/source/test/los_maps.lua b/crawl-ref/source/test/los_maps.lua new file mode 100644 index 0000000000..769cd251ec --- /dev/null +++ b/crawl-ref/source/test/los_maps.lua @@ -0,0 +1,56 @@ +-- check LOS according to pre-defined maps + +local checks = 0 + +-- visible: +local rock_wall = dgn.find_feature_number("rock_wall") +local floor = dgn.find_feature_number("floor") +-- invisible (not needed): +local stone_wall = dgn.find_feature_number("stone_wall") +local water = dgn.find_feature_number("deep_water") + +local function test_los_map(map) + crawl.mesclr() + -- choose random debug map; better choose all + dgn.tags(map, "no_rotate no_vmirror no_hmirror no_pool_fixup") + local name = dgn.name(map) + -- local width, height = dgn.mapsize(map) -- returns (0,0) + local function place_map() + return dgn.place_map(map, true, true) + end + dgn.with_map_anchors(30, 30, place_map) + you.moveto(30, 30) + you.losight() + crawl.redraw_view() + for x = 0, 9 do + for y = 0, 9 do + local xa = 30 + x + local ya = 30 + y + local p = dgn.point(x, y) + local should_see = ((x == 0 and y == 0) or + dgn.grid(xa, ya) == rock_wall or + dgn.grid(xa, ya) == floor) + local can_see = you.see_grid(xa, ya) + if can_see and (not should_see) then + assert(false, "los error in " .. name .."(iter #" .. checks .. + "): can see " .. p .. " but shouldn't.") + elseif (not can_see) and should_see then + assert(false, "los error in " .. name .. "(iter #" .. checks .. + "): should see " .. p .. " but can't.") + end + end + end +end + +local function test_los_maps() + dgn.load_des_file("debug-los.des") + local map = dgn.map_by_tag("debug_los") + while map do + test_los_map(map) + checks = checks + 1 + map = dgn.map_by_tag("debug_los") + end +end + +test_los_maps() + diff --git a/crawl-ref/source/test/los_symm.lua b/crawl-ref/source/test/los_symm.lua new file mode 100644 index 0000000000..beb809beee --- /dev/null +++ b/crawl-ref/source/test/los_symm.lua @@ -0,0 +1,67 @@ +-- Vet LOS for symmetry. + +local FAILMAP = 'losfail.map' +local checks = 0 + +local function test_losight_symmetry() + -- Clear messages to prevent them accumulating and forcing a --more-- + crawl.mesclr() + -- Send the player to a random spot on the level. + you.random_teleport() + + -- Forcibly redo LOS. + you.losight() + + 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 + if you.see_grid(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) + you.losight() + if not you.see_grid(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.grid(you_x, you_y, "floor_special") + dgn.dbg_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.mpr("Running LOS tests on " .. place) + dgn.dbg_goto_place(place) + + for lev_i = 1, nlevels do + dgn.dbg_flush_map_memory() + dgn.dbg_generate_level() + for t_i = 1, tests_per_level do + test_losight_symmetry() + end + end +end + +for depth = 1, 27 do + run_los_tests(depth, 1, 10) +end -- cgit v1.2.3-54-g00ecf