Page 1 of 1

[Oxyd] [1.1.48] game.map_settings.path_finder.fwd2bwd_ratio <= 1 never completes

Posted: Mon Nov 29, 2021 9:46 am
by DrButtons
Hello,

I was messing around with some pathfinding stuff and i found that setting fwd2bwd_ratio to anything less than or equal to 1 creates a loop that seems to go on forever. This could just be an error in the documentation too and maybe i'm just using it wrong..


i made a recording of this behavior. in the video i first run the pathfinder with the defaults and then I set the value to -5 and the backwards pather seems to make it, but then gets confused and continues to search

i put the scenario and code in the zip file but to make it easier i will also post the code here

i also put the video as an attachment (.mkv) if you don't like that site
https://emalm.com/?v=__yax

the code i'm running looks like this:

Code: Select all


local handler = require("event_handler")
handler.add_lib(require("freeplay"))
handler.add_lib(require("silo-script"))

Public = {}

local threat_values = {
	["small-spitter"] = 1.5,
	["small-biter"] = 1.5,
	["medium-spitter"] = 4.5,
	["medium-biter"] = 4.5,
	["big-spitter"] = 13,
	["big-biter"] = 13,
	["behemoth-spitter"] = 38.5,
	["behemoth-biter"] = 38.5,
	["small-worm-turret"] = 8,
	["medium-worm-turret"] = 16,
	["big-worm-turret"] = 24,
	["behemoth-worm-turret"] = 32,
	["biter-spawner"] = 32,
	["spitter-spawner"] = 32
}

local enemy_types = {
	"small-spitter",
	"small-biter",
	"medium-spitter",
	"medium-biter",
	"big-spitter",
	"big-biter",
	"behemoth-spitter",
	"behemoth-biter"
}


local function send_attack(threat)
	threat = tonumber(threat.parameter)
	local surface = game.surfaces[1]
	game.forces.player.chart(game.player.surface, {lefttop = {x = -2000, y = -500}, rightbottom = {x = 2000, y = 500}})
	game.forces.enemy.share_chart = true
	game.forces.player.share_chart = true

	local silo = surface.find_entities_filtered({position={0,495}, raidus=100, name="rocket-silo"})[1]
	local unit_group = surface.create_unit_group({position = {0, -470}, force = "enemy"})

	for _=1, 200, 1 do
		if threat < 0 then break end
		local enemy_type = enemy_types[math.random(1, #enemy_types)]
		threat = threat - 5*threat_values[enemy_type]
		for _=1, 5, 1 do
			local position = surface.find_non_colliding_position(enemy_type, {0, -470}, 128, 2)
			if not position then break end
			local enemy = surface.create_entity({name = enemy_type, force = "enemy", position = position})
			unit_group.add_member(enemy)
		end
	end

	local commands = {}
	commands[#commands + 1] = {
		type = defines.command.attack,
		target = silo,
		distraction = defines.distraction.by_enemy
	}
	unit_group.set_command({
		type = defines.command.compound,
		structure_type = defines.compound_command.logical_and,
		commands = commands
	})
end
Public.send_attack = send_attack
global.commands = {}
global.commands.send_attack = send_attack
commands.add_command('send', 'send attack..', send_attack)

return Public



Re: [Oxyd] [1.1.48] game.map_settings.path_finder.fwd2bwd_ratio <= 1 never completes

Posted: Mon Nov 29, 2021 2:53 pm
by Oxyd
The comment is wrong. Maybe it was right at one point and then things changed internally, I don't know.

In any case, the actual behaviour is that every fwd2bwd'th step is a backward step. So the lowest value that makes sense is 2, which means that every 2nd step is a backward one, so it's symmetric. You can't actually make it prefer the backward search over the forward search, and I don't see how that could be useful either.

I fixed the comment and added a check that won't let you set it to a value lower than 2.

Re: [Oxyd] [1.1.48] game.map_settings.path_finder.fwd2bwd_ratio <= 1 never completes

Posted: Mon Nov 29, 2021 3:53 pm
by DrButtons
Hello,

1st - thank you for fixing the documentation!
2nd - I hope you might reconsider not allowing reverse A*. In the video I posted Reverse A* is very useful, the default search takes 14 seconds, while the reverse takes only about 5. in some games, where you are often behind a wall and designing bases specifically to trap biteres in places that that abuts a lake (like in the video and like in biterbattles), pathfinding can take very long time.