-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.lua
More file actions
103 lines (91 loc) · 3.54 KB
/
Copy pathtest.lua
File metadata and controls
103 lines (91 loc) · 3.54 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
local fog = require "fog"
local function test()
local w, h = 10000, 5000
local map1 = fog.create(w, h)
print(fog.encode(map1)) -- ouput: C
fog.dispel_fog(map1, 100, 100, 10, 10)
assert(fog.is_dispel(map1, 100, 100))
local str = fog.encode(map1)
print(str) -- ouput: ppppplaZapmkCZiJUKhGhEqVmImQmYCFhIhGhEaZioBqWEiqqqqqC
local map2 = fog.decode(str, w, h)
fog.dispel_fog(map2, 0, 0, 10000, 10000)
print(fog.encode(map2)) -- ouput: A
fog.cover_fog(map2, 0, 0, 5000, 10000)
print(fog.encode(map2)) -- ouput: JC
local map3 = fog.union(map1, map2)
print(fog.encode(map3)) -- ouput: JpppplaZapmkCZiJUKhGhEqVmImQmYCFhIhGhEaZioBqWEiqqqqqA
end
print("=========================================")
test()
local function test1(map_size, hole_size, hole_count)
local map = fog.create(map_size.w, map_size.h)
for _ = 1, hole_count do
local x = math.random(0, map_size.w - 1)
local y = math.random(0, map_size.h - 1)
fog.dispel_fog(map, x, y, hole_size.w, hole_size.h)
assert(fog.is_dispel(map, x, y))
end
local str = fog.encode(map)
local size = string.len(str)/1024
print(string.format("map:%dx%d, hole:%dx%d count:%d, size:%.2fkb",
map_size.w, map_size.h, hole_size.w, hole_size.h, hole_count, size))
end
print("=========================================")
for i = 1, 10 do
test1({w = 2500, h = 2500}, {w = 30, h = 30}, 100)
end
local function test2(map_size)
local map = fog.create(map_size.w, map_size.h)
fog.dispel_fog(map, 2, 2, 2, 2)
fog.dispel_fog(map, 3, 3, 2, 2)
fog.dispel_fog(map, 0, 16, 100, 100)
fog.dispel_fog(map, 10, 3, 10, 100)
fog.dump(map)
local str = fog.encode(map)
print(str)
local map2 = fog.decode(str, map_size.w, map_size.h)
fog.cover_fog(map2, 18, 18, 100, 100)
fog.dump(map2)
end
print("=========================================")
test2({w = 20, h = 20})
local function test3()
local w, h = 20, 20
local map1 = fog.create(w, h)
fog.dispel_fog(map1, 10, 10, 10, 10)
fog.dump(map1)
local map2 = fog.create(w, h)
fog.dispel_fog(map2, 5, 5, 10, 10)
fog.dump(map2)
local map3 = fog.union(map1, map2)
fog.dump(map3)
end
print("=========================================")
test3()
local function test4()
local w, h = 2520, 2520
local map1 = fog.create(w, h)
local str = "ZqpWqpmZpmCmBqqqqppppZaaJGoBBCWiQiQFiEiEJCJShIhIRiQikWEJCJEJkERISIRIhRkQCRCJRESIRIhFRISIRIhREiESESYEhESESYEhESESoVWiQiglIkIUhIhIRiQiUISISkIkIZJCJCWiQiQFiEiEJCJShIhIRiQiURkIkQkQSEhIhEhEGRiQCRCJREiESESYREiESESYEhIhEhEGRISIRIhREiESESYRkIkQkQSEhIhEhEGRiQCRCJREiESESYREiESESYEhIhEhEGRISIRIhREiESESYZJCJCWiQiQFiEiEJCJShIhIRiQiklIkIYJCJCVISISkIkIFiEiEJCJSFRiQCRCJREiESESYEJCJEJkERISIRIhFRISIRIhREiESESYEhIhEhEGRISIRIhFRiQCRCJREiESESYEJkQkQSEhESESYREiESESYEhIhEhEGRIhEhEGRIhEhEWaaUiQiAlIkIoWRJCJCUiQigRJCJCUiQigWUiQiAlIkIYUiQiAlIkIoqK"
local map2 = fog.decode(str, w, h)
local fog_list, dispel_list = fog.cmp(map1, map2)
print("fog_list", #fog_list)
print("dispel_list", #dispel_list)
end
print("=========================================")
test4()
local function test5()
local w, h = 3, 3
local map1 = fog.create(w, h)
local map2 = fog.create(w, h)
fog.dispel_fog(map2, 0, 0, 2, 2)
fog.dispel_fog(map2, 2, 2, 2, 2)
local fog_list, dispel_list = fog.cmp(map1, map2)
print("fog_list", #fog_list)
print("dispel_list", #dispel_list)
for _, v in pairs(dispel_list) do
print(v[1], v[2])
end
end
print("=========================================")
test5()
print("test ok")