1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-03 22:52:20 +02:00

benchmarking

This commit is contained in:
veden 2016-09-12 15:33:00 -07:00
parent a711893fa0
commit 039bfa10d1
3 changed files with 46 additions and 44 deletions

View File

@ -21,7 +21,7 @@ local scanMap = mapProcessor.scanMap
local accumulatePoints = aiBuilding.accumulatePoints
local removeScout = aiBuilding.removeScout
local scouting = aiBuilding.scouting
-- local scouting = aiBuilding.scouting
local playerScent = pheromoneUtils.playerScent
local deathScent = pheromoneUtils.deathScent
@ -46,24 +46,7 @@ local temps
-- hook functions
function onInit()
-- print("init")
global.regionMap = {}
global.pendingChunks = {}
global.natives = {}
global.pheromoneTotals = {}
global.temps = {}
regionMap = global.regionMap
natives = global.natives
pendingChunks = global.pendingChunks
pheromoneTotals = global.pheromoneTotals
temps = global.temps
onConfigChanged()
end
function onLoad()
local function onLoad()
-- print("load")
regionMap = global.regionMap
natives = global.natives
@ -72,7 +55,15 @@ function onLoad()
temps = global.temps
end
function onConfigChanged()
local function onChunkGenerated(event)
-- queue generated chunk for delayed processing, queuing is required because some mods (RSO) mess with chunk as they
-- are generated, which messes up the scoring.
if (event.surface.index == 1) then
pendingChunks[#pendingChunks+1] = event
end
end
local function onConfigChanged()
-- print("reprocess")
if (global.version == nil) then
@ -122,18 +113,13 @@ function onConfigChanged()
end
end
function onChunkGenerated(event)
-- queue generated chunk for delayed processing, queuing is required because some mods (RSO) mess with chunk as they
-- are generated, which messes up the scoring.
if (event.surface.index == 1) then
pendingChunks[#pendingChunks+1] = event
end
end
function onTick(event)
local function onTick(event)
if (event.tick % 20 == 0) then
local surface = game.surfaces[1]
local surface = game.surfaces[1]
processPendingChunks(regionMap, surface, pendingChunks)
scanMap(regionMap, surface)
if (event.tick % 40 == 0) then
accumulatePoints(natives)
@ -148,24 +134,20 @@ function onTick(event)
squadBeginAttack(natives, game.players, game.evolution_factor)
squadAttack(regionMap, surface, natives, temps)
end
processPendingChunks(regionMap, surface, pendingChunks)
-- scanMap(regionMap, surface)
processMap(regionMap, surface, natives, game.evolution_factor, temps)
processMap(regionMap, surface, natives, game.evolution_factor, temps)
end
end
function onBuild(event)
local function onBuild(event)
addRemoveEntity(regionMap, event.created_entity, natives, true)
end
function onPickUp(event)
local function onPickUp(event)
addRemoveEntity(regionMap, event.entity, natives, false)
end
function onDeath(event)
local function onDeath(event)
local entity = event.entity
local surface = entity.surface
if (surface.index == 1) then
@ -196,13 +178,31 @@ function onDeath(event)
end
end
function onPutItem(event)
local function onPutItem(event)
-- local player = game.players[event.player_index]
-- if (player.surface.index==1) then
-- aiBuilding.fillTunnel(global.regionMap, player.surface, global.natives, event.positions)
-- end
end
local function onInit()
-- print("init")
global.regionMap = {}
global.pendingChunks = {}
global.natives = {}
global.pheromoneTotals = {}
global.temps = {}
regionMap = global.regionMap
natives = global.natives
pendingChunks = global.pendingChunks
pheromoneTotals = global.pheromoneTotals
temps = global.temps
onConfigChanged()
end
-- hooks
script.on_init(onInit)

View File

@ -113,7 +113,7 @@ end
function aiBuilding.formSquads(regionMap, surface, natives, chunk, evolution_factor, temps)
if (natives.points > AI_SQUAD_COST) then
local score = chunk[PLAYER_BASE_PHEROMONE] + chunk[PLAYER_PHEROMONE] + chunk[PLAYER_DEFENSE_PHEROMONE] + surface.get_pollution({chunk.pX, chunk.pY})
if (score > 20) and (chunk[ENEMY_BASE_GENERATOR] ~= 0) and (#natives.squads < (AI_MAX_SQUAD_COUNT * evolution_factor)) and (math.random() < 0.03) then
if (score > 70) and (chunk[ENEMY_BASE_GENERATOR] ~= 0) and (#natives.squads < (AI_MAX_SQUAD_COUNT * evolution_factor)) and (math.random() < 0.03) then
local squadPosition = temps[constants.SQUAD_POSITION]
local squadPath, squadScore = scoreNeighbors(chunk,

View File

@ -53,7 +53,7 @@ function unitGroupUtils.membersToSquad(squad, members, overwriteGroup, temps)
for i=1,#members do
local member = members[i]
if member.valid and (overwriteGroup or (not overwriteGroup and (member.unit_group == nil))) then
member.set_command(groupCmd)
member.set_command(groupCmd)
end
end
end
@ -120,7 +120,7 @@ function unitGroupUtils.regroupSquads(natives, temps)
unitGroupUtils.membersToSquad(squad, mergeGroup.members, true, temps)
mergeGroup.destroy()
end
end
end
end
end
@ -133,15 +133,17 @@ function unitGroupUtils.regroupSquads(natives, temps)
elseif (#squad.group.members == 0) then
squad.group.destroy()
tableRemove(squads, i)
else
else
if (squad.status == SQUAD_RETREATING) and ((squad.cycles == 0) or (squad.group.state == GROUP_STATE_FINISHED)) then
squad.status = SQUAD_GUARDING
squad.cycles = 0
elseif (squad.cycles > 0) then
squad.cycles = squad.cycles - 1
end
end
end
end
return unitGroupUtils