Road Pathfinder

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
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Road Pathfinder

Post by DeletedUser6 »

Could someone tell me how the Road Pathfinder works - as I'm attempting to make my own....

Thank you!

Matthew:out
Yay! I'm back! Did you miss me?


...


I thought not.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: Road Pathfinder

Post by Alberth »

Search for "games path finding" at the Internet.
A common algorithm is A* (pronounced A-star).
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Re: Road Pathfinder

Post by DeletedUser6 »

I know how the A* graph works, (compare cost of two lines, choose the one with least cost, is the jist of it) but I want to know about the commands used for placing a node, getting that node, sectioning the route and building the road from that. Some sort of tutorial would be nice.

Matthew:out
Yay! I'm back! Did you miss me?


...


I thought not.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Road Pathfinder

Post by Lord Aro »

A read of the code would surely give you the best idea of what's going on 'inside' the pathfinder...
Then ask if you don't get it entirely ;)

(I don't get it entirely myself to be honest :lol: )
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Re: Road Pathfinder

Post by DeletedUser6 »

*cough* *cough* Already have, twice... I still see text - it's not my fault I'm rubbish at anything to do with code...

Matthew:out

EDIT: And I barely understand the Doxygen documents, so no use there.
Yay! I'm back! Did you miss me?


...


I thought not.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: Road Pathfinder

Post by Alberth »

The AI main page at the wiki has a link to documentation, which should have a link to road-related functions.
Those are your primtive operations in which you have to express road building.
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Re: Road Pathfinder

Post by DeletedUser6 »

Evidently I am being misunderstood...

AroAI already has a route builder, I need to know how to get the result from the AyStar into a route usable by the bus route builder. Which is what the Road Pathfinder does.

MAtthew:out
Yay! I'm back! Did you miss me?


...


I thought not.
Arie-
Director
Director
Posts: 593
Joined: 20 Jan 2009 16:07

Re: Road Pathfinder

Post by Arie- »

I think you are misunderstanding as well, most of the AI's available, code examples on the wiki and the doxygen comments should help you a lot. If that is not enough, several questions which you preferably answer all as clearly as possibly:
- what is the problem?
- what solutions to your problem did you find and how did you find them?
- what parts of your solutions didn't work?
- what errors did those parts generate?
Reading the code of available AI's should help you a lot, they al already tackled your problem!
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Re: Road Pathfinder

Post by DeletedUser6 »

The problem: I want to make a Road Pathfinder Library. The wiki says how to use the existing one, but not how to make one.
The solution: Ask the people who made it how it works, and copy the existing RPF.
How I got there: PM'd TrueBrain.
Problems encountered: The people haven't answered, and I have no idea how the existing Road PF works, plus the AI (AroAI)/ AI Debug isn't recognising the library I've made from the solution.
Error's generated: As above (Couldn't find library 'superpf')

The library.nut, and main.nut are attached.

Matthew:out
Attachments
library.nut
library.nut
(591 Bytes) Downloaded 45 times
main.nut
main.nut
(15.22 KiB) Downloaded 48 times
Yay! I'm back! Did you miss me?


...


I thought not.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Road Pathfinder

Post by Yexo »

Getting a "library not found" error message usually indicates an error in your library.nut. In this case:

Code: Select all

function GetVersion()		{ return "1"; }
GetVersion should return an integer, so that line of code should read:

Code: Select all

function GetVersion()		{ return 1; }
Also, while TrueBrain has helped a lot with the A* library and the road pathfinder, I wrote them originally.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: Road Pathfinder

Post by Alberth »

I still don't understand what your problem is (besides the thing yexo pointed out).

Perhaps you should simplify the problem, and learn to crawl before trying to walk.
I suggest you create a flat landscape of 64x64 tiles with a single town somewhere in the corner where it does not bother you.

Then make an AI for that scenario that builds a road from tile (10, 15) to (30, 15) or some other straight line.
(Yes, you can build stuff in the middle of nowhere, not useful in real games, but as a first step it may be useful.)

If that works, try making a road with a corner in it.
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

Re: Road Pathfinder

Post by DeletedUser6 »

@Yexo Ah, it was the fact it said:
truebrain
that threw me...

Thank you, for getting it detected, even if I still don't understand how to call nodes (I am simplifying it, to make it faster, that is assuming that each tile is a node.), or how to give AroAI a path.

It's better than nothing...

@Alberth I'll try that.
Matthew:out
Yay! I'm back! Did you miss me?


...


I thought not.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: Road Pathfinder

Post by Alberth »

OTTDmaster wrote:... how to call nodes (I am simplifying it, to make it faster, that is assuming that each tile is a node.), or how to give AroAI a path.
1. Don't bother about speed until you got it working. Optimizations only get in the way of understanding.
2. What is a node? OpenTTD has no nodes. If you mean PF algorithm nodes, then quite likely, tile == node.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Road Pathfinder

Post by Yexo »

A node can be everything you want. If I recall correctly in the default road pathfinder library it is indeed true that node==tile. In the rail pathfinder a node is a combination of a tile + a direction, because you cannot go in every direction when 90 degree turns are disabled.

Are you trying to use the A* library or not? If you want to use it, just copy the default road pathfinder and implement your own _Cost function. The return value of FindPath is an instance of AyStar.Path which is a linked list that contains the complete path.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Road Pathfinder

Post by Lord Aro »

In case anyone is wondering or cares about the excessive use of AroAI, OTTDmaster has become a sort of assistant developer with me
Just thought i'd let you know ;)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 14 guests