Page 1 of 1
AI pathfinder - discouraging use of foundations
Posted: 15 Sep 2015 21:53
by Simons Mith
I was looking at how the road pathfinder chooses its routes, and how /I/ would do it in the same circumstances.
(I want to teach an AI to copy my building style.)
I find that AIs will often build roads on the edges of slopes where I would prefer not to. Can an AI (particularly, the
pathfinder) tell if building on a particular tile requires foundations?
AFAICS, it can't.
Is it possible to influence how eager the pathfinder is to use tiles on the edge of a slope? I want a setup where
routes marked 'OK' are given preference to routes marked 'Needs foundations', and I'm not sure if the pathfinder
can be directed to do this. I can't just forbid sloped tiles, because up-and-down a slope in those cases would be
fine, but I would like a way to avoid roads running along the edges of slopes and up corner tiles.
BTW I'm still doing my own investigations anyway, but in the meantime I would be grateful for pointers. I'm not
at all familiar with AI-writing yet.
Addendum: Another BTW, and a probable bug; if the pathfinder hits an existing road, but that road is one-way
and pointing in the wrong direction, is it clever enough to realise that? I haven't finished looking at the code yet,
but I very much doubt it!
Re: AI pathfinder - discouraging use of foundations
Posted: 16 Sep 2015 06:14
by Alberth
Simons Mith wrote:Can an AI (particularly, the
pathfinder) tell if building on a particular tile requires foundations?
AFAICS, it can't.
Oh really?
You're saying it is impossible to implement an A* path finding algorithm, and examine each tile carefully for slope before deciding whether or not to allow building a road onto it?
Interesting conclusion.
Simons Mith wrote:Is it possible to influence how eager the pathfinder is to use tiles on the edge of a slope? I want a setup where
routes marked 'OK' are given preference to routes marked 'Needs foundations', and I'm not sure if the pathfinder
can be directed to do this. I can't just forbid sloped tiles, because up-and-down a slope in those cases would be
fine, but I would like a way to avoid roads running along the edges of slopes and up corner tiles.
Perhaps you should read about the A* path finding algorithm, and how it incrementally tries to build a path.
You of course can code to not offer road directions that lead to foundations, but it may be too limiting. Probably it's better to give road with foundation a heavy penalty. The path finder will try to avoid them, but if the detour is too big, still have the option available.
Simons Mith wrote:Addendum: Another BTW, and a probable bug; if the pathfinder hits an existing road, but that road is one-way
and pointing in the wrong direction, is it clever enough to realise that? I haven't finished looking at the code yet,
but I very much doubt it!
Just code the option in the path finder (and in this case really don't offer the option to drive on a road with an arrow in the wrong direction
Good luck with your adventure

Re: AI pathfinder - discouraging use of foundations
Posted: 16 Sep 2015 13:40
by Simons Mith
My question was whether any of the pathfinders
the game currently provides can do it! Particularly, this one:
http://wiki.openttd.org/AI:RoadPathfinder
As I said, it seems not, but not being familiar with the API maybe I've missed something.
Besides, even if I wrote my own A* implementation from scratch, I suspect there may still be some info the game doesn't expose.
Re: AI pathfinder - discouraging use of foundations
Posted: 16 Sep 2015 13:43
by planetmaker
Simons Mith wrote:My question was whether any of the pathfinders
the game currently provides can do it! Particularly, this one:
http://wiki.openttd.org/AI:RoadPathfinder
As I said, it seems not, but not being familiar with the API maybe I've missed something.
Besides, even if I wrote my own A* implementation from scratch, I suspect there may still be some info the game doesn't expose.
Neither the game is static, nor its script API nor the script libraries. Each is open to patches. Your desire to get information about slopes doesn't sound unreasonable to me.
Re: AI pathfinder - discouraging use of foundations
Posted: 16 Sep 2015 14:57
by Alberth
The game itself doesn't provide any path finder:
http://noai.openttd.org/api/trunk/
So in all cases, you are running a path finder in Squirrel.
Re: AI pathfinder - discouraging use of foundations
Posted: 17 Sep 2015 12:38
by krinn
You can alter how the pathfinder is working yourself.
if you just want like you said "discouraging use of foundations", add a cost penalty to the A*
if you want like you seems to think in real "prevent any road on them", add an exception to it.
Look at AI other has done to see howto do something that appears complex/impossible when everyone has done it already.
simpleAI implement itself a "level crossing penalty". This will teach you how to overload a squirrel function (and happy you, it do it on the roadpathfinder, just what you are looking for) with your own cost penalty.
And if you want implement it as a "prevent any road on them", you can overload the Road::_Neighbours with a to check if tile is slope bad
But like Alberth said, you will endup with pathfinding always fail to find a path if not on a flat map.