AI pathfinder - discouraging use of foundations

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Simons Mith
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 14 Jan 2010 23:45

AI pathfinder - discouraging use of foundations

Post 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!
Attachments
I prefer foundations to be used sparingly. The road pathfinder uses them too much for my tastes.
I prefer foundations to be used sparingly. The road pathfinder uses them too much for my tastes.
Foundations.png (212.25 KiB) Viewed 1911 times
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: AI pathfinder - discouraging use of foundations

Post 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 :D
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
Simons Mith
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 14 Jan 2010 23:45

Re: AI pathfinder - discouraging use of foundations

Post 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.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AI pathfinder - discouraging use of foundations

Post 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.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: AI pathfinder - discouraging use of foundations

Post 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.
Being a retired OpenTTD developer does not mean I know what I am doing.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: AI pathfinder - discouraging use of foundations

Post 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.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests