-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
tests.lua
244 lines (211 loc) · 10.3 KB
/
tests.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
-- Copyright (C) 2022 veden
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
local tests = {}
local constants = require("libs/Constants")
local chunkUtils = require("libs/ChunkUtils")
local chunkPropertyUtils = require("libs/ChunkPropertyUtils")
function tests.chunkCount()
local count = 0
for _,map in pairs(global.universe.maps) do
count = count + #map.processQueue
end
print(count)
end
function tests.fillableDirtTest()
local playerPosition = game.players[1].position
local chunkX = math.floor(playerPosition.x * 0.03125) * 32
local chunkY = math.floor(playerPosition.y * 0.03125) * 32
game.get_surface(global.natives.activeSurface).set_tiles({{name="fillableDirt", position={chunkX-1, chunkY-1}},
{name="fillableDirt", position={chunkX, chunkY-1}},
{name="fillableDirt", position={chunkX-1, chunkY}},
{name="fillableDirt", position={chunkX, chunkY}}},
false)
end
function tests.tunnelTest()
local playerPosition = game.players[1].position
local chunkX = math.floor(playerPosition.x * 0.03125) * 32
local chunkY = math.floor(playerPosition.y * 0.03125) * 32
game.get_surface(global.natives.activeSurface).create_entity({name="tunnel-entrance-rampant", position={chunkX, chunkY}})
end
function tests.reveal (size)
local pos = game.player.character.position
game.player.force.chart(game.player.surface,
{{x=-size+pos.x, y=-size+pos.y}, {x=size+pos.x, y=size+pos.y}})
end
function tests.showBaseGrid(time)
local map = global.universe.maps[game.player.surface.index]
local chunks = map.chunkToBase
for chunk in pairs(chunks) do
local count = chunkPropertyUtils.getEnemyStructureCount(map, chunk)
chunkUtils.mapScanEnemyChunk(chunk, map, game.tick)
local newCount = chunkPropertyUtils.getEnemyStructureCount(map, chunk)
if newCount ~= count then
constants.gpsDebug(chunk.x+16,chunk.y+16, "f2:" .. tostring(count) .. "/" .. tostring(newCount))
chunkUtils.colorChunk(chunk, game.player.surface.index, {0.3, 0.1, 0.1, 0.6}, time and tonumber(time))
else
chunkUtils.colorChunk(chunk, game.player.surface.index, nil, time and tonumber(time))
end
end
end
-- function tests.showMovementGrid()
-- local chunks = global.map.processQueue
-- for i=1,#chunks do
-- local chunk = chunks[i]
-- local color = "concrete"
-- if (chunkPropertyUtils.getPassable(global.map, chunk) == constants.CHUNK_ALL_DIRECTIONS) then
-- color = "hazard-concrete-left"
-- elseif (chunkPropertyUtils.getPassable(global.map, chunk) == constants.CHUNK_NORTH_SOUTH) then
-- color = "concrete"
-- elseif (chunkPropertyUtils.getPassable(global.map, chunk) == constants.CHUNK_EAST_WEST) then
-- color = "stone-path"
-- end
-- chunkUtils.colorChunk(chunk.x, chunk.y, color, game.get_surface(global.natives.activeSurface))
-- end
-- end
-- function tests.colorResourcePoints()
-- local chunks = global.map.processQueue
-- for i=1,#chunks do
-- local chunk = chunks[i]
-- local color = "concrete"
-- if (chunk[constants.RESOURCE_GENERATOR] ~= 0) and (chunk[constants.NEST_COUNT] ~= 0) then
-- color = "hazard-concrete-left"
-- elseif (chunk[constants.RESOURCE_GENERATOR] ~= 0) then
-- color = "deepwater"
-- elseif (chunk[constants.NEST_COUNT] ~= 0) then
-- color = "stone-path"
-- end
-- chunkUtils.colorChunk(chunk.x, chunk.y, color, game.get_surface(global.natives.activeSurface))
-- end
-- end
function tests.entityStats(name, d)
local playerPosition = game.players[1].position
local chunkX = math.floor(playerPosition.x * 0.03125) * 32
local chunkY = math.floor(playerPosition.y * 0.03125) * 32
local a = game.get_surface(global.natives.activeSurface).create_entity({name=name, position={chunkX, chunkY}})
if d then
a['direction'] = d
end
print(serpent.dump(a))
a.destroy()
end
local function lookupIndexFaction(targetFaction)
for i=1,#constants.FACTION_SET do
if constants.FACTION_SET[i].type == targetFaction then
return i
end
end
return 0
end
local function scoreResourceLocationKamikaze(_, neighborChunk)
local settle = neighborChunk[constants.RESOURCE_PHEROMONE]
return settle
- (neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
- neighborChunk[constants.ENEMY_PHEROMONE]
end
local function scoreSiegeLocationKamikaze(_, neighborChunk)
local settle = neighborChunk[constants.BASE_PHEROMONE]
+ neighborChunk[constants.RESOURCE_PHEROMONE] * 0.5
+ (neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
- neighborChunk[constants.ENEMY_PHEROMONE]
return settle
end
local function scoreResourceLocation(map, neighborChunk)
local settle = (neighborChunk[constants.RESOURCE_PHEROMONE])
return settle
- (neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
- neighborChunk[constants.ENEMY_PHEROMONE]
end
local function scoreSiegeLocation(map, neighborChunk)
local settle = neighborChunk[constants.BASE_PHEROMONE]
+ neighborChunk[constants.RESOURCE_PHEROMONE] * 0.5
+ (neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
- neighborChunk[constants.ENEMY_PHEROMONE]
return settle
end
local function scoreAttackLocation(map, neighborChunk)
local damage = neighborChunk[constants.BASE_PHEROMONE] +
(neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
return damage
end
local function scoreAttackKamikazeLocation(_, neighborChunk)
local damage = neighborChunk[constants.BASE_PHEROMONE] + (neighborChunk[constants.PLAYER_PHEROMONE] * constants.PLAYER_PHEROMONE_MULTIPLER)
return damage
end
function tests.exportAiState()
local printState = function ()
local map = global.universe.maps[game.players[1].surface.index]
local chunks = map.processQueue
local s = ""
for i=1,#chunks do
local chunk = chunks[i]
local base = chunk.base
local alignmentCount = 0
if base then
if (#base.alignment == 2) then
alignmentCount = (math.abs(base.x) * 10000) + (math.abs(base.y) * 10000) + (lookupIndexFaction(base.alignment[1]) * 100) + lookupIndexFaction(base.alignment[2])
else
alignmentCount = (math.abs(base.x) * 10000) + (math.abs(base.y) * 10000) + lookupIndexFaction(base.alignment[1])
end
end
s = s .. table.concat({chunk.x,
chunk.y,
chunkPropertyUtils.getCombinedDeathGeneratorRating(chunk),
chunk[constants.BASE_PHEROMONE],
chunk[constants.PLAYER_PHEROMONE],
chunk[constants.RESOURCE_PHEROMONE],
chunk[constants.ENEMY_PHEROMONE],
chunkPropertyUtils.getPassable(chunk),
chunk[constants.CHUNK_TICK],
chunkPropertyUtils.getPathRating(chunk),
chunk.nestCount or 0,
chunk.turretCount or 0,
chunkPropertyUtils.getRallyTick(chunk) or 0,
chunkPropertyUtils.getRetreatTick(chunk) or 0,
chunk.resourceGenerator or 0,
chunk.playerBaseGenerator or 0,
chunkPropertyUtils.getCombinedDeathGenerator(chunk),
scoreResourceLocationKamikaze(map, chunk),
scoreResourceLocation(map, chunk),
scoreSiegeLocationKamikaze(map, chunk),
scoreSiegeLocation(map, chunk),
scoreAttackKamikazeLocation(map, chunk),
scoreAttackLocation(map, chunk),
game.get_surface(game.players[1].surface.index).get_pollution(chunk),
(chunkPropertyUtils.isActiveNest(chunk) and 1) or 0,
(chunkPropertyUtils.isActiveRaidNest(chunk) and 1) or 0,
table_size(chunk.squads or {}),
alignmentCount,
chunk.hiveCount or 0,
chunk.trapCount or 0,
chunk.utilityCount or 0,
global.universe.chunkToVictory[chunk.id] or 0,
chunk[constants.KAMIKAZE_PHEROMONE]
}, ",") .. "\n"
end
game.write_file("rampantState.txt", s, false)
end
return function(interval)
if not interval then
interval = 0
else
interval = tonumber(interval)
end
printState()
if (interval > 0) then
script.on_nth_tick(interval, printState)
end
end
end
function tests.dumpEnvironment(x)
print (serpent.dump(global[x]))
end
return tests