Denver & Rio Grande train AI (A freight train AI)

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

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Denver & Rio Grande train AI (A freight train AI)

Post by SirkoZ »

Dustin wrote:
SirkoZ wrote:
Dustin wrote:I am having terrible troubles uploading new versions to the board....
Why kind of troubles exactly are you experiencing when uploading these little files to the Forum? Why do you think it comes to this? I'm really curious now that you've metioned it at least two times. :-)

Mostly I have problems when I edit the first post.

Well, when I try to upload any file to it, I often get a message from IE that the connection to the server was broken. When I do manage to upload, I don't always see the list of previous files I uploaded. At least once I thought the upload worked and older version of the file was there.

It takes me 4 or 5 tries to upload anything. If I don't turn on compatibility mode, the edit window scrolls back to the top after each character I type. Each character takes half a second to show up and the whole edit window seems to jitter as I type.

The board probably works in IE7 and Firefox. But it's not too happy with IE8 I guess. I don't want to get another browser just to post. So I am sad.
Oh my - what an ordeal. :-(

I'd say just install Fireferret alongside Internet Exploder, you don't have to set it as default browser...
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Abenhor wrote:
Dustin wrote:
Zuu wrote:I would also suggest that debug signs are off by default, as most users would probably want to have them turned off.
I did that to get the settings to take effect so I could see the debug signs. For some reason I can see and set the settings, but the ones I pick aren't used. Whatever is defined in the Info.nut is what is used. Any hints on how to fix my settings would be appreciated.
Your settings are working well, where used. When turning off 'display_thinking' no more path signs '{.}' appears, but for the main signs (while searching good locations for stations) you aren't using these settings.
Maybe if you use some internal list to copy these signs (while placing it) and check this list instead of the real signs you could make the same job without showing signs.
The settings don't work at all for me. Wonder why? What version of OpenTTD do you have?
I was playing a bit more with DustinAI (v7) and I have some questions for you.

While removing signals, problematic points aren't removed. I don't know if it's a bug or a feature. If it's a bug, you can change
change line 535 in main.nut from

Code: Select all

 if(name == "{.}" || name == "{-}" ||name == "{A}" || name == "{B}" || name == "{+}" || name == "{=}")
to

Code: Select all

 if(name == "{.}" || name == "{-}" ||name == "{A}" || name == "{B}" || name == "{+}" || name == "{=}" || name == "{*}")
When a new route fails, the cost of building the producing station could be done later, and so some more money could be available for another route (lines 414 and 464 in main.nut), if you are checking the internal list mentioned before (instead of the real signs).
I already have a fix in my testing version for the code you mention. Thanks. I should move to an internal array instead of checking signs. I tried that and I had some bugs, so I switched to signs for now. It's not terribly spammy with the signs anymore.

I now remove producing stations that fail. You are right that I should consider not building them at all. An older revision had problems with the pathfinder. It would draw tracks under the producing station. The newer versions use the closest edge from each station, so that should not be a problem now. I will make a note to test not even making a producing station that might fail.

A bug building a new station (in the point of view, ignore the new route pathfinding):
The attachment DustinAI_0.png is no longer available
I have seen that bug, but I thought it was fixed in that version. I don't see it anymore. If you see it in A8 or above, I want to know.
And finally, a curious joke: I tried 2 DustinAI, and they are both trying the same routes at the same time, resulting in mixed lines (some tiles with tracks from Dustin1 and another with tracks from Dustin2). :lol:
LOL, that's really cool. I haven't tested side by side versions yet. Right now having the AI completely deterministic is really good for reproducing bugs. Later I will make the station selection a wieghted random function.
Attachments
DustinAI.A8.tar
(73 KiB) Downloaded 155 times
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Abenhor »

Dustin wrote:The settings don't work at all for me. Wonder why? What version of OpenTTD do you have?
Latest stable (0.7.1).

Testing v8, I see several changes, and it is much better.

A new question: Planting trees isn't working as we would like.
Dustinv8_Planting_trees.png
Planting trees
(119.47 KiB) Downloaded 79 times
Besides I don't see any tree (only clearing the zone), you need to limite the area very much. I don't know how many trees you can plant to increase rating, but surely the number can't be so big.

I think you are wrong in your approach, in StationManager.nut line 122
The game function CheckIfAuthorityAllowsNewStation (http://svn.openttd.org/trunk/src/town_cmd.cpp lines 2676-2684) checks if your rating is greater than VERYPOOR, being VeryPoor = -200 according to the enum table (http://svn.openttd.org/trunk/src/town_type.h line 26).

A bug conecting a station (point of view 3):
Dustinv8_Building_station.png
Bug conecting station
(121.61 KiB) Downloaded 73 times
And a minor question about optimizing ro-ro stations, maybe for the future: all stations have their depot in the same side, and allow the trains entering the station from the same side, independent of the side wich is conected; a third train waiting to enter the statin could block the (single) line in the case of Point of View 1, while in the case of Point of View 2 the third train can wait at the (external) side of the station. For the consumer drop-off station could be on the contrary...
User avatar
cmoiromain
Chief Executive
Chief Executive
Posts: 655
Joined: 15 Jan 2007 21:45
Location: FRANCE
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by cmoiromain »

Abenhor wrote:Besides I don't see any tree (only clearing the zone), you need to limite the area very much. I don't know how many trees you can plant to increase rating, but surely the number can't be so big.
That's because you have transparency & invisibility turned on for trees. try pressing X to change this. The clearing zone is due to the former presence of fields, which are always destroyed when trees are built instead.

Planting that much trees is no big deal, I think the amount is correct. One thing you might want to try (if it is not done yet; I have not tried your AI) is to replant the trees at the same place multiple times until an error occurs, because IIRC you can have up to four trees on one single tile.
I am little, ugly, and nasty. How do you do?
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Abenhor »

cmoiromain wrote:
Abenhor wrote:Besides I don't see any tree
That's because you have transparency & invisibility turned on for trees.
Oops! :oops: Sorry, it's true

Well, the last info for now. The depots aren't removed when stations are.
Dustinv8_weird_figure.png
A weird figure
(120.28 KiB) Downloaded 78 times
At some point, the AI enters in a loop trying the same industry.
A weird figure is formed in a line (the point of view).

Good luck and keep up the good work, Dustin. :wink:
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Abenhor wrote:
cmoiromain wrote:
Abenhor wrote:Besides I don't see any tree
That's because you have transparency & invisibility turned on for trees.
Oops! :oops: Sorry, it's true

Well, the last info for now. The depots aren't removed when stations are.
Dustinv8_weird_figure.png
At some point, the AI enters in a loop trying the same industry.
A weird figure is formed in a line (the point of view).

Good luck and keep up the good work, Dustin. :wink:
Thanks to both of you for the comments! They are very helpful. The bug with the station trying to connect through the signal is an issue known to me. I tried some fixes but nothing is working yet.

The "strange" figures are a side effect of my semi-random path finder. I need to write a post-path optimizer to get rid of kinks like that. In fact the kinks can cause the route to fail sometimes.

I am happy with my tree placer. It actually looks up all the tiles the city owns and tries to plant trees there. The problem is that you can only place so many trees before you have to wait.

I am not sure what you are saying about the value of 200 in the rating. I use the enums directly rather than a comparison.

-Dustin
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Abenhor »

Dustin wrote:I am not sure what you are saying about the value of 200 in the rating. I use the enums directly rather than a comparison.
Sorry, it was time to sleep a little and I mixed two ideas; forget the value of 200.
Today I did some more tests and returned to find the issue of planting trees. The rating rises from apalling up to very poor, and it should be enough to build the new station. The AI entered then in a loop, and 8 years (several iterations, 4 attempts each) don't improve the rating any more.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Abenhor wrote:
Dustin wrote:I am not sure what you are saying about the value of 200 in the rating. I use the enums directly rather than a comparison.
Sorry, it was time to sleep a little and I mixed two ideas; forget the value of 200.
Today I did some more tests and returned to find the issue of planting trees. The rating rises from apalling up to very poor, and it should be enough to build the new station. The AI entered then in a loop, and 8 years (several iterations, 4 attempts each) don't improve the rating any more.

Yeah, that needs some work. There are several things going on there.

1. When it gives up trying trees, it doesn't have a mechanism to report that it didn't work, so it just comes back and tries again.
2. When I level land for stations, I level more than I really need too. It levels first and asks questions later.
3. My system is single minded. Once it starts trying to build a route, it keeps at it for years. :)

It's on my list to work on, but I think I will work on passing lanes and better train management after I fix some more pathfinder bugs.

-D
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Post by Dustin »

[removed by author]
Last edited by Dustin on 20 Jul 2009 03:05, edited 1 time in total.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Post by Dustin »

[removed by author]
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

RC8 is on the first post. It seems pretty stable. Please give it a try and let me know how it works for you.
Wasila
Tycoon
Tycoon
Posts: 1498
Joined: 15 Mar 2008 07:02

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Wasila »

Would it be possible to get 2cc compatibility?
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Wasila wrote:Would it be possible to get 2cc compatibility?
Have you tried it with 2cc? It already might work. I don't even know what's in 2cc so it might be horrible as well.


This is the list features/bugs to fix for V1.5.
  • Fix paths into the backs of consumer depots
  • delete route if consumer industry fails
  • cache ant pathfinding to speed up path searches
  • speed up passing lane build outs
  • add more than one passing lane to long routes
  • Detect broken paths caused by cities building out during route building
  • Scan trains from periodic maintenance to keep train list better up to date.
  • Test and support 2cc.
Wasila
Tycoon
Tycoon
Posts: 1498
Joined: 15 Mar 2008 07:02

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Wasila »

I'll test it once I figure out how to change the settings in-game. If starting early then there are only freight RV's, so it might not work at the beginning.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Wasila wrote:I'll test it once I figure out how to change the settings in-game. If starting early then there are only freight RV's, so it might not work at the beginning.
Yeah, it's a train AI. It probably won't be happy without trains.

I think it will spin it's wheels (so to speak) waiting for a 1400+ Hp engine to become available. Then it won't start with the best industry, but wherever in the list it already made it to. Plus it will have losts a fair amount of money to loan interest.

Interesting test. I will make a note to come back and make it smarter about early trains.
Wasila
Tycoon
Tycoon
Posts: 1498
Joined: 15 Mar 2008 07:02

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Wasila »

The first train's come out, so I'll start running it.
Wasila
Tycoon
Tycoon
Posts: 1498
Joined: 15 Mar 2008 07:02

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Wasila »

Well, I've got some results. It decided that instead of building one of the few trains out, it should build a metro train. Problem is, they only carry passengers :). I might have to kill it and restart when there's some more choice.

So basically, perhaps it should take wagon availability into account?
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Denver & Rio Grande train AI (A freight train AI)

Post by SirkoZ »

Removed kinks aside - there are still some left:
Attachments
...just like the good old AI used to make them...
...just like the good old AI used to make them...
San Juan Transport, 1st Jan 2127.png (9.34 KiB) Viewed 3273 times
...some more...
...some more...
San Juan Transport, 6th Oct 2126.png (11.63 KiB) Viewed 3270 times
...and then some...
...and then some...
San Juan Transport, 8th Sep 2126.png (9.35 KiB) Viewed 3272 times
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

SirkoZ wrote:Removed kinks aside - there are still some left:

Yeah, I saw a really long switchback last night. The kink remover isn't working at all. :( In fact I commented it out on my machine because it got into an infinite loop. I need to rework that. Also the passing track routine is so slow consumers sometimes close before the first train is launched. So that needs work as well.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Wasila wrote:Well, I've got some results. It decided that instead of building one of the few trains out, it should build a metro train. Problem is, they only carry passengers :). I might have to kill it and restart when there's some more choice.

So basically, perhaps it should take wagon availability into account?

It actually starts from the wagon, finds a good engine to pull the wagons at thier top speed and goes from there. I forgot the check to see if the engine can pull the wagon. :oops:
Thanks for the report.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: AAAHogEx and 5 guests