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

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

Post by planetmaker »

well... isn't "forbid 90° turns = on" the default setting?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

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

Post by Zuu »

planetmaker wrote:well... isn't "forbid 90° turns = on" the default setting?
Nope, it is off by default. But it is one of the first things I do turn on at a new OpenTTD configuration.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

RC11 since I was last here... Looks like I can't keep up with testing :D Nice job!
But it seems that some major bug remained. The AI often struggles with building new routes, there were games when it failed to build anything. There is one example in the ChooChoo thread, I have a posted savegame there and your AI dind't build anything in that game. I didn't wait for a very long time, it was trying two different routes and failing all the time.
And there is another problem, I see ANTSTART and ANTGOAL signs were there are no obstacles at all, where (I think) the crow should succeed without problems.
It is nice to see the improved ant pathfinder with the {C} signs, if only I could see the brand new kink remover in action... :(
Good luck in further development!
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

I found another bug, the trains were started where there was no connection. I attached the screenshot and the savegame. Here the red player finds it hard to build new lines.
Attachments
R11 bug.png
R11 bug.png (67.23 KiB) Viewed 3854 times
Unnamed, 30th Jun 1951.sav
(100.16 KiB) Downloaded 149 times
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

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

Post by Dezmond_snz »

There is wrong something... (2cc TS)
no suitable wagons?
no suitable wagons?
Denver & Rio Grande, 1950-07-21.png (78.24 KiB) Viewed 972 times
Russia
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 »

Brumi wrote:RC11 since I was last here... Looks like I can't keep up with testing :D Nice job!
But it seems that some major bug remained. The AI often struggles with building new routes, there were games when it failed to build anything. There is one example in the ChooChoo thread, I have a posted savegame there and your AI dind't build anything in that game. I didn't wait for a very long time, it was trying two different routes and failing all the time.
And there is another problem, I see ANTSTART and ANTGOAL signs were there are no obstacles at all, where (I think) the crow should succeed without problems.
It is nice to see the improved ant pathfinder with the {C} signs, if only I could see the brand new kink remover in action... :(
Good luck in further development!
Thanks for the comments.

There is an "invisible" fence around all the cities that will cause crow to invoke the ant. It in past it was blundering into dead ends the ant could not get out of. Imagine coming diagonally into a city with roads that almost meet and just passing through the "gate". If you see the crow put down {-} signs away from obstacles and more than 10 or so tiles from a city center I would love to seen a screenshot of the signs or a savegame.

EDIT: The dekinker now prints a {K} on the whole kink so you can see what's being considered for removal.

Can you post the save here or link the thread so I can take a look? The AI isn't super smart and some games are just hard for it to get going. Usually if one bankrupts the next one does better.
Last edited by Dustin on 28 Jul 2009 06:39, edited 1 time in total.
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 »

Brumi wrote:I found another bug, the trains were started where there was no connection. I attached the screenshot and the savegame. Here the red player finds it hard to build new lines.
Interesting. That's a good report. I don't have a clue what happened there. It shouldn't make trains if the track to a consumer didn't succeed. Sometimes a city will put down a road or change a slope just in time to spoil a route. It could be something related to that.

In any case, this station should be removed in about 2 years automatically. I will keep an eye out for that sort of thing. A savegame where it happens in the first 5-10 years would be super helpful.

Edit: I checked out the save, but I still don't know why this happened. Thanks for the report!
Last edited by Dustin on 28 Jul 2009 06:21, edited 1 time in total.
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 »

Dezmond_snz wrote:There is wrong something... (2cc TS)
Denver & Rio Grande, 1950-07-21.png
Thanks for the report. 2cc hasn't been tested by me. So I am not surprised. Do you have a save game? It's trying to find a wagon to haul wood that will run on that track. I assume there is no monorail car for wood (it will refit wagons if it must). I never tested for what happens when there is no wagon to haul a good. So that's what caused the error.

I will think about how to fix this. The AI should still run, just not as well as it could.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

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

Post by planetmaker »

When playing with the 2cc Train Set, it usually is sensible to not use monorail, but stick to electrified rail in the general case. Monorail is used by that set as a dedicated commuter train track, thus only PAX transport is available - with the advantage of fast loading / unloading and high-capacity PAX wagons.
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 »

planetmaker wrote:When playing with the 2cc Train Set, it usually is sensible to not use monorail, but stick to electrified rail in the general case. Monorail is used by that set as a dedicated commuter train track, thus only PAX transport is available - with the advantage of fast loading / unloading and high-capacity PAX wagons.

My AI isn't smart enough to figure out what rail is what. It just picks a valid one and goes! In NARS it picks electric rail and that's good because it can use a variety of engines. Thanks for the explanation. I will think about how to add a "best rail picker". Probably just count the number of wagons that are valid for a rail and pick the one with the highest count.

Typically unless you start with a late date, or the original bankrupts, you won;t get maglev or monorail.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

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

Post by planetmaker »

Dustin wrote:(...)In NARS it picks electric rail(...)
Sure. NARS only provides (e)rail engines, thus monorail and maglev are de-activated automatically due to unavailability of vehicles.
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 »

RC12 posted in main post.

planetmaker wrote:
Dustin wrote:(...)In NARS it picks electric rail(...)
Sure. NARS only provides (e)rail engines, thus monorail and maglev are de-activated automatically due to unavailability of vehicles.

Well at least in NARS monorail isnt avialable for a while, but electric is always there. So when I use this code I get the current "best". When does 2cc introduce monorail?

Code: Select all

local types = AIRailTypeList();
AIRail.SetCurrentRailType(types.Begin());  
As a side note, I looked it up and there were electric "interurban" trains all over the U.S.A. in 1900! Around Seattle where I live now and in Colorado where I grew up. Victor and Cripple Creek had electric trains like a stray dog has fleas!
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

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

Post by planetmaker »

Dustin wrote: Well at least in NARS monorail isnt avialable for a while, but electric is always there. So when I use this code I get the current "best". When does 2cc introduce monorail?
Depends. If you set no NewGRF parameters monorail (or how it's called there metro tracks) are available from 1894 on. See http://users.tt-forums.net/2cc/readme.html
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Dustin wrote:Added the "{K}" sign (just for Brumi) to show rails that are kinked.
:D thanks
So I tested RC12, and it's nice to see that your AI is back on track again! :) It was building nicely, no more struggling with pathfinding.
The blank station bug occured again, but now it may be a clue that it was on a separate island. And when I spotted it, the last line in the AI Debug window was 'Build Route Waiting for more money...' You can see this in the attached savegame.
DustinAI RC12 test.sav
(119.13 KiB) Downloaded 154 times
There was a minor bug too, it should be quite easy to fix:
passinglanebug.png
passinglanebug.png (62.93 KiB) Viewed 3735 times
And here is what I was speaking about, the ant pathfinder starts where there is no obstacle or even a town nearby. (Or does it apply to industries?) It caused no problems, just a little slowdown in pathfinding.
antpathfinder.png
antpathfinder.png (181.6 KiB) Viewed 3734 times
Dustin wrote:Can you post the save here or link the thread so I can take a look? The AI isn't super smart and some games are just hard for it to get going. Usually if one bankrupts the next one does better.
If I'm not too late, it's here in this post.
There is a setting called 'Minimum transport cargo percent per industry'. Does it mean that your AI won't compete if a higher percentage is transported from the industry? (like in TransAI)
I don't want to seem like that I keep posting bugs all the time, your AI is really improving. I think it will become a really good one over time. :)
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

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

Post by Roujin »

Brumi wrote:[...]
And here is what I was speaking about, the ant pathfinder starts where there is no obstacle or even a town nearby. (Or does it apply to industries?) It caused no problems, just a little slowdown in pathfinding.
[image]
Didn't Dustin state somewhere above that he always uses ant at the last few tiles of a connection?


----
I haven't gotten around to testing your AI before, but now I've done it (as promised in another thread :)).
I really like the fresh ideas you've brought into your AI here. Also very nice is how you can really watch the AI while he's thinking, unlike other AIs that just plot and plot and plot silently and then *bang* spit out a route ;)

Anyway, here's a few things I noticed:

Image 1: I don't really know why bridge was invoked here in the first place. It should be perfectly fine to lay a straight track down there. Maybe the coast tiles are irritating crow.
DustinTest, 1955-03-13#1.png
(80.81 KiB) Downloaded 50 times
Image 2: Building a passing lane failed here.
DustinTest, 1955-03-13#2.png
(245.63 KiB) Downloaded 48 times
Image 3: The passing lane builder inadvertently connected the line to a station of another line.
DustinTest, 1955-03-13#3.png
(103.28 KiB) Downloaded 50 times
edit:typo
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

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

Post by Roujin »

Here's another thing I noticed, it's more of a design problem than a bug actually.
D&RG AI often fails building something due to its own track being in the way. Here's what I think the problem is:
DustinTest, 1957-09-02.png
(60.81 KiB) Downloaded 56 times
Often, situations like in the image above happen (if he already built some lines, or other players/AI did).
Unlike cities or industries, existing track is a kind of obstacle that is best bridged over / tunneled under, not gone around (should be obvious).
However, as far as I understand how your AI works, there's only one chance to manage that. As soon as crow has defined the start and the ending point of the path that it's not able to manage itself, it passes these two points to bridge first, then to ant.
More often than not, bridge is NOT able to handle this, because either crow was going in a diagonal, or there's a height difference between start and ending point, or something else is inbetween (a town, ...).
Of course ant also fails because it's in most cases impossible to go around an existing route.

---
You already wrote that you wanted to introduce some other sub-pathfinders (before resorting to ant at the very last), so maybe these could be able to tackle cases like in the above screenshot?

------------
EDIT: found another bug (I guess):
your AI created a big aisle through the map. Maybe it tried to level something at the border of the map and made some "modulo map border" error?
DustinTest, 1969-08-21.png
(274.12 KiB) Downloaded 56 times


Last thing said, please don't take this critique too harsh, I really like your AI. I just want to help you improve it further ;) (lol, that reminds me of "thank you for helping us help you help us all")
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
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 »

Brumi wrote:
Dustin wrote:Added the "{K}" sign (just for Brumi) to show rails that are kinked.
:D thanks
So I tested RC12, and it's nice to see that your AI is back on track again! :) It was building nicely, no more struggling with pathfinding.
The blank station bug occured again, but now it may be a clue that it was on a separate island. And when I spotted it, the last line in the AI Debug window was 'Build Route Waiting for more money...' You can see this in the attached savegame.
Excellent. Crow chokes when the station starts right next to water. If crow can't even get one tile off things go wrong.
There was a minor bug too, it should be quite easy to fix:
passinglanebug.png
Minor: yes.
Easy to fix: nope.

This is in the newest part of the code, which I rushed and worked on when I was seriously tired. In fact, the code is so bad it's riddled with infinite loop buster code. I may just start from scratch and do it over better.
The passing lanes work often enough that the AI can run a decent number of trains, so this failure is not ideal, but not a "ship stopper".


And here is what I was speaking about, the ant pathfinder starts where there is no obstacle or even a town nearby. (Or does it apply to industries?) It caused no problems, just a little slowdown in pathfinding.
Ah. Yeah, that is the END. Not the start. Crow always hands over to ant at the very end. Yes, that's messy, but the links are much cleaner.
Dustin wrote:Can you post the save here or link the thread so I can take a look? The AI isn't super smart and some games are just hard for it to get going. Usually if one bankrupts the next one does better.
If I'm not too late, it's here in this post.
There is a setting called 'Minimum transport cargo percent per industry'. Does it mean that your AI won't compete if a higher percentage is transported from the industry? (like in TransAI)
Thanks, I will look at the save when I get a chance. EDIT: I looked. Yeah, D&RG is doomed on that map. It needs enough space to place it's initial stations in a flat place near a producer and consumer. It does finnally find that, but doesn't have the cash to complete the link. I typically test in bigger maps. D&RG isn't a small map AI. :)

A new train will be built if the % transported is below this number for about 1 year. (Or actually if it's lower exactly when I check once a year.) So a coal mine at 51% would never get a new train if the setting was 50. but it would get another added if it hits 49%. Provided the AI thinks there is room for more. The producer stations name say something like (2/3) meaning that 2 out of a possible three trains are believed to be running.

EDIT: My AI won't compete if you even have a station in range of the industry. It tries to do it's own thing and not get mixed up with others. I might change that to look for underserved producers so that PAX stations won't scare it off.

I don't want to seem like that I keep posting bugs all the time, your AI is really improving. I think it will become a really good one over time. :)
My day job is Software Tester. I completely respect what you are doing here. Keep the feedback coming. It's very gratifying.
Last edited by Dustin on 29 Jul 2009 06:49, edited 1 time in total.
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 »

Roujin wrote: ----
I haven't gotten around to testing your AI before, but now I've done it (as promised in another thread :)).
I really like the fresh ideas you've brought into your AI here. Also very nice is how you can really watch the AI while he's thinking, unlike other AIs that just plot and plot and plot silently and then *bang* spit out a route ;)
Thanks so much for the kind words. This AI actually started when I read about Pathzilla and Ant Colony computing on the same day. So the AI is really just a wrapper for my custom AI. :)
Anyway, here's a few things I noticed:

Image 1: I don't really know why bridge was invoked here in the first place. It should be perfectly fine to lay a straight track down there. Maybe the coast tiles are irritating crow.
Yep, crow thinks of coast the same as water. On day Seagull will step in and understand coasts better.
DustinTest, 1955-03-13#1.png
Image 2: Building a passing lane failed here.
Yeah, that routine is just terrible. I had it working pretty nice, but then it had some infinite loops at times. I added code to fix them and the passing lanes started showing problems. Sometimes around bridges the get messed up too.
DustinTest, 1955-03-13#2.png
Image 3: The passing lane builder inadvertently connected the line to a station of another line.
DustinTest, 1955-03-13#3.png
edit:typo
That's interesting, but I don't consider it a problem. The trains don't seem to mind. If you see a link where this causes trains to get lost I would love to hear about it.

Thanks again for the tournament and the report.
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 »

Roujin wrote:Here's another thing I noticed, it's more of a design problem than a bug actually. [snip...]---
You already wrote that you wanted to introduce some other sub-pathfinders (before resorting to ant at the very last), so maybe these could be able to tackle cases like in the above screenshot?
You understand exactly. Bridge is REALLY dumb and if crow was Diagonal, it's doomed. So yes, I plan on improving bridge and I have been toying with creating Mole. (You can guess what that might do.)
------------
EDIT: found another bug (I guess):
your AI created a big aisle through the map. Maybe it tried to level something at the border of the map and made some "modulo map border" error?
DustinTest, 1969-08-21.png
Wow, nice. Looks like a legit OTTD bug. The AI is calling "AITile.LevelTiles(tile, tile + AITile.GetIndex(-10, -10))" for example. Looks like it wrapped indeed. The AI doesn't check the validity of the tiles. Just tries to flatten areas around producers to fit stations in.
Last thing said, please don't take this critique too harsh, I really like your AI. I just want to help you improve it further ;) (lol, that reminds me of "thank you for helping us help you help us all")
Not at all. I am thrilled to be getting so much thoughtful feedback. Thank you very much.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

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

Post by Rubidium »

Dustin wrote:Wow, nice. Looks like a legit OTTD bug. The AI is calling "AITile.LevelTiles(tile, tile + AITile.GetIndex(-10, -10))" for example. Looks like it wrapped indeed. The AI doesn't check the validity of the tiles. Just tries to flatten areas around producers to fit stations in.
How is OpenTTD supposed to know that leveling 'tile on one side of map' to 'tile on other side of map' means leveling till the map's border? And if so, till which map border?
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 16 guests