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!
AI pathfinder - discouraging use of foundations
Moderator: OpenTTD Developers
- Simons Mith
- Transport Coordinator
- Posts: 326
- Joined: 14 Jan 2010 23:45
AI pathfinder - discouraging use of foundations
- Attachments
-
- I prefer foundations to be used sparingly. The road pathfinder uses them too much for my tastes.
- Foundations.png (212.25 KiB) Viewed 2184 times
Re: AI pathfinder - discouraging use of foundations
Oh really?Simons Mith wrote:Can an AI (particularly, the
pathfinder) tell if building on a particular tile requires foundations?
AFAICS, it can't.
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.
Perhaps you should read about the A* path finding algorithm, and how it incrementally tries to build a path.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.
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.
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 directionSimons 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!

Good luck with your adventure

Being a retired OpenTTD developer does not mean I know what I am doing.
- Simons Mith
- Transport Coordinator
- Posts: 326
- Joined: 14 Jan 2010 23:45
Re: AI pathfinder - discouraging use of foundations
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.
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.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: AI pathfinder - discouraging use of foundations
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.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.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: AI pathfinder - discouraging use of foundations
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.
So in all cases, you are running a path finder in Squirrel.
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: AI pathfinder - discouraging use of foundations
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.
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.
Who is online
Users browsing this forum: No registered users and 11 guests