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

Post Reply
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Roujin wrote:Didn't Dustin state somewhere above that he always uses ant at the last few tiles of a connection?
Dustin wrote:Yeah, that is the END. Not the start. Crow always hands over to ant at the very end.
Yes, it seems that I overlooked this sentence earlier:
Dustin wrote:Crow always hands things over to ant for the last 15 tiles.
sorry... :oops:
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 »

Rubidium wrote:
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?

My hypothesis was that I called something like

Code: Select all

AITile.LevelTiles(AIMap.GetTileIndex(1,1), AIMap.GetTileIndex(-10, -10)) 
and that had "wrapped around" rather than just failing.

I did some tests and I could not get AIMap.GetTileIndex to give me a "wrap around." So my hypothesis isn't provable and is looking dubious. I have only seen this one instance of the bug, so I don't have any other guesses. If anyone else sees it, let me know.
Rantanplan
Engineer
Engineer
Posts: 5
Joined: 27 Jul 2009 20:28

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

Post by Rantanplan »

Hello, i'd really like to give this AI a shot, but i don't know how to install it.
It isn't listed in the OTTD download list. I did not find any instructions in the OTTD wiki or anywhere else that explain how to manually install AI's.
I tried placing the .tar file in the \content_download\ai folder but that didn't seem to be enough :oops: .
Please excuse my noobness, and I hope you can help me.


edit: typo
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 »

I just gave it a try to see if I could find out where you get stuck. But both placing it in

My Documents\OpenTTD\content_download\ai
and
My Documents\OpenTTD\Installations\Last Nightly\ai

works for me.


Mind that I use r16982 (last nightly) and not 0.7.x.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Rantanplan
Engineer
Engineer
Posts: 5
Joined: 27 Jul 2009 20:28

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

Post by Rantanplan »

Now it's working :D thanks
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 »

Rantanplan wrote:Now it's working :D thanks
Good to hear! I will have it up on bananas soon-ish. Let me know what you think.
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 »

RC12 test results and my oh my, are they interesting - I took quite a few pics.
The game ran from 1950 to 2050, temperate hilly terrain.
First descriptions of errors/odd behaviour in pics:
_1_ : AI building station parts with no railway connections between them at the same two industries (iron mine, steel mill) at least three times (each time deleted because of no profit of course),
_2_ : overflow line/sideline is not properly connected to mainline because of rails being on a hillside (lack of terraforming where really needed?),
_3_ : at least two station blocks without station but with rails instead of it built at one steel mill,
_4_ : same as _1_, this time at a coal mine,
_5_ : when AI has enough money to build it terraforms a big square (some 16x16 tiles) around a industry, not just what is needed for station block,
_6_ : same as _5_, but it actually connected that mine,
_7_ : wiggly rail with 90° turn next to my diagonal rail due to lack of very little necessary terraforming to make it more straight,
_8_ : stranded train on a piece of rail that couldn't get deleted because of train being there.

EDIT: Corrected _6_ : "same as _6_" to "same as _5_". S/Z
Attachments
1, 2, 3
1, 2, 3
Dusty_R12_1_2_3.png (180.25 KiB) Viewed 803 times
4, 5, 6
4, 5, 6
Dusty_R12_4_5_6.png (236.05 KiB) Viewed 797 times
7, 8
7, 8
Dusty_R12_7_8.png (141.76 KiB) Viewed 797 times
Last edited by SirkoZ on 02 Aug 2009 01:55, 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 »

SirkoZ wrote:RC12 test results and my oh my, are they interesting - I took quite a few pics.
The game ran from 1950 to 2050, temperate hilly terrain.
Thanks for taking it for a spin and the bug reports.

EDIT: By the way, no one has called me "Dusty" for 20 years or more!
First descriptions of errors/odd behaviour in pics:
_1_ : AI building station parts with no railway connections between them at the same two industries (iron mine, steel mill) at least three times (each time deleted because of no profit of course),
_2_ : overflow line/sideline is not properly connected to mainline because of rails being on a hillside (lack of terraforming where really needed?),
_3_ : at least two station blocks without station but with rails instead of it built at one steel mill,
1. Thanks. I know of this bug. It's when the start station is close to water or some other obstacle. The pathfinder can't handle failing from square 1 in some instances.
2. Known bug, been working on it for days. Re-wrote the code 3 times from scratch. It's much cleaner now, but still has this exact bug!
3. New bug. Good job, but I don't have any idea yet what causes it.
(edit: I think this is due to local authority rejecting the station but not the rails).
...
_5_ : when AI has enough money to build it terraforms a big square (some 16x16 tiles) around a industry, not just what is needed for station block,
_6_ : same as _6_, but it actually connected that mine,
5. It's not very smart about that. Level first, ask questions later. That's a poor design, but it's working for now.
6. ? Let X = X; 6 is the same as 6. OK. :)


_7_ : wiggly rail with 90° turn next to my diagonal rail due to lack of very little necessary terraforming to make it more straight,
_8_ : stranded train on a piece of rail that couldn't get deleted because of train being there.
[/quote]

7. Hmm, the de-kinker shoulda fixed that. I am seeing some kinks in other games now that should have been removed. My router won't terraform at all, but it should have seen the flat tiles adjacent to each other where that could have been cleaned up.
8. I thought I fixed that too. I will look into it.

Can you double check you really ran RC12? :) I will look for more instances of 7 and 8.


Thanks for the help!
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:EDIT: By the way, no one has called me "Dusty" for 20 years or more!
Sorry - I save my test-games with at least a part of AI name and as there wasn't enough room after Garningwell Ridge I truncated it from "DustinAI test" to "dustytest".
Besides - I somehow had the song Dusty Skies (Hank Thompson) on my mind. :)
_6_ : same as _6_, but it actually connected that mine,
...should read "same as _5_" :oops:

As for terraforming - perhaps just the amount of x*y (tiles) of a station block.

Yep, it's RC12 alright. :)
Thanks for the help!
You're welcome. It's nice to see a good-to-be AI being developed. :)
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 338
Joined: 13 Jul 2008 00:57
Contact:

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

Post by Michiel »

2. Known bug, been working on it for days. Re-wrote the code 3 times from scratch. It's much cleaner now, but still has this exact bug!
LOL, that's actually quite an achievement :P
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 »

Michiel wrote:
2. Known bug, been working on it for days. Re-wrote the code 3 times from scratch. It's much cleaner now, but still has this exact bug!
LOL, that's actually quite an achievement :P
I fixed it! It's because I walk the path from front to back looking for a good place to the join the tracks. Then I walk if from back to front. Of course I just copy-pasted the code and changed the sort order and all the variables. Well, except one. Really should have made it a method rather than copy-paste re-use.

I still have a bug where the passing lanes don't handle bridges on the main line correctly. Once I fix that I think I will be ready for RC13.

Here is a preview. I added the ability to randomize industry picks so that if you run my AI twice it won't interfere with itself so much.
  • Added setting to randomize industry selection. Uses a weighted random function, so top producers are likely to get picked sooner than others.
  • Better track type selection. Might fix some issues with 2cc and late starts.
  • Changed the main loop to wait less when an industry doesn't have a suitable place to put a station.
  • Changed logging a little so "waiting for money" and "is alive <date>" messages only happen every 90 days at most.
  • Changed how AI picks stations. Rather than just looking for stations around industries, it looks for low cargo delivery rates. Should make it more competitive with other AI's. Also has the side effect of allowing it to build more than one route for really big producers.
  • Added a limit to the amount of time the AI will wait for more money if it runs out while building a route. In the case this is the first route, it will keep it from going bankrupt and it will try other routes. It still might be doomed, but it won't just give up.
  • Changed threshold where routes will be removed to be less agressive.
Attachments
DustinAI.RC12.5.tar.zip
(20.85 KiB) Downloaded 161 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Hi Dustin,
It's nice to see that your pathfinder is getting stronger and stronger. :)
I was mistaken a 'little' when I said that the passing lane bug should be easy to fix... :oops:
So now I'm not coming with a pathfinder issue, rather something different. I know there is some problem with path signals and servicing, and for your AI it often causes that your trains don't get serviced at all. So I think you should introduce a 'go to/service at depot' order for your trains.
Good work! :)
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 »

Dusty Rails 12.5 :mrgreen: :
Problems _1_ (trains on unconnected rail blocks), _5_ (huge square terraforming) persist, however tracks are much nicer now with all passing lanes properly connected.
Also - it could start with some simple 1-train services, so it is able to start with low loan ($200-300k).
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:Hi Dustin,
It's nice to see that your pathfinder is getting stronger and stronger. :)
I was mistaken a 'little' when I said that the passing lane bug should be easy to fix... :oops:
So now I'm not coming with a pathfinder issue, rather something different. I know there is some problem with path signals and servicing, and for your AI it often causes that your trains don't get serviced at all. So I think you should introduce a 'go to/service at depot' order for your trains.
Good work! :)
Good catch. I have been testing with auto-servicing and no breakdowns. I will look into it soon.
I STILL have a bug with passing lanes and bridges. It's due to the hacky way I try to jam in passing lanes after the path is found. So those bugs are harder than they need to be.
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:Dusty Rails 12.5 :mrgreen: :
Problems _1_ (trains on unconnected rail blocks), _5_ (huge square terraforming) persist, however tracks are much nicer now with all passing lanes properly connected.
Also - it could start with some simple 1-train services, so it is able to start with low loan ($200-300k).

I am not seeing _1_ in my tests. Can you let me know what newgrfs and settings you are using?

_5_ is not on the list to fix until after V1.0.

Low Loan starts should work better in RC13 (coming soon). I am testing with 2cc and the higher engine costs make getting started harder. So I refactored that system some. There is still some wasted money, but the AI now starts more than it fails in 2cc.
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 »

13 is a lucky number in my family. RC13 is posted.
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 »

I couldn't reply earlier.
I use plain OpenTTD, no new .grf's. I tested with nightly build (r17030).
Looks like to achieve _1_ AI just somehow skips building rails between rail blocks. I don't know what else to say - the sure way to achieve it start a hilly map with original map generator.

By the way - fancy seeing R13 out already. As for the number - it's all good - again - odd and even are a good way to separate non-stable and stable releases as with Linux kernel...
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

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

Post by Roujin »

Hi dustin,
congratulations on your new release.

One thing I'd like to know is how exactly the passing lane building works and in which cases it fails. I'm encountering quite a few cases where there aren't any passing lanes for a looong piece of the track, or even the whole track (which of course makes it effectively a one-train-route), where I as a human see no difficulty in building a passing lane at all.
See example: very long route with no passing lane at all.
D&RG 1.png
(68.47 KiB) Downloaded 42 times
D&RG 2.png
(70.43 KiB) Downloaded 39 times
D&RG 3.png
(72.04 KiB) Downloaded 38 times
Another thing I've been wondering is that in the console your AI is described as the "Denver & Santa Fe Railroad", are you renaming your AI to that? Or is it an old name you've forgotten to remove?
* @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
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 »

Roujin - if you read the beginning of this thread - you'll see that the name is AI's correct/intended as Dustin will confirm, I'm sure.

Anyhow - no more _1_ observed in R13, just some passing problems as Roujin described. There was also a case when I think it couldn't build a passing lane further and it built signals on the rail connecting two passing lanes. This no doubt cause a big jam with 4 trains on that route what with path signals, their reserved tracks and all. :-)
Attachments
problems in passing
problems in passing
Unnamed, 1st Jun 1958.png (13.78 KiB) Viewed 3074 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 »

Roujin wrote:Hi dustin,
congratulations on your new release.

One thing I'd like to know is how exactly the passing lane building works and in which cases it fails. I'm encountering quite a few cases where there aren't any passing lanes for a looong piece of the track, or even the whole track (which of course makes it effectively a one-train-route), where I as a human see no difficulty in building a passing lane at all.
See example: very long route with no passing lane at all.
D&RG 1.png
D&RG 2.png
D&RG 3.png
Another thing I've been wondering is that in the console your AI is described as the "Denver & Santa Fe Railroad", are you renaming your AI to that? Or is it an old name you've forgotten to remove?
Thanks for the report. When there isn't much enough money to make passing lanes, the AI skips them. So the first route or two sometimes don't have them on purpose. Never fear, if the route loses money, the AI will remove it and try again later.

Denver & Sante Fe is the Railroad my grandfather worked on. So the name is on purpose. If you start a lot of DustinAI they will all have different historic North American railroad names in the future. :)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests