trAIns: An AI that plays only with trains (v2)

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

lhrios
Engineer
Engineer
Posts: 22
Joined: 28 Dec 2008 00:16

trAIns: An AI that plays only with trains (v2)

Post by lhrios »

Newest post here!

Description: trAIns is based on a previous work reported in this post. It is a competitive AI that plays only with trains. It creates and manages railroad routes that connects industries and railroad routes that connects two towns. The last can transport passengers. It is also partially compatible with NARS and 2CC.

The list of features and more details can be found here.

Bugs and/or suggestions: Please, use this thread.
Last edited by lhrios on 03 Aug 2014 23:29, edited 11 times in total.
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: trAIns: An IA that play only with trains

Post by Xander »

An IA, you say? Interesting... :P
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: trAIns: An AI that play only with trains

Post by lawton27 »

From the screenshots this looks quite good, I'll be shure to test it out and give you some feedback later :mrgreen:
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: trAIns: An AI that play only with trains

Post by Zutty »

Wow, very impressive. I like the neat double rails.

Keep up the good work.
PathZilla - A networking AI - Now with tram support.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: trAIns: An AI that play only with trains

Post by Lord Aro »

i got this when i started it up

i'm on 0.7.2 if it matters
Attachments
Unnamed, 28th Jan 1950.png
Unnamed, 28th Jan 1950.png (207.4 KiB) Viewed 1039 times
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
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: trAIns: An AI that play only with trains

Post by lawton27 »

I got that too on 7.1, I thought upgrading to 7.2 would fix it; I haven’t been able to test it on 7.2 yet due to and unexpected error.
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: trAIns: An AI that play only with trains

Post by Xander »

Initial impression is very impressive.

trAIns didn't go straight to the nearest power plant but instead took the line a good distance, to earn good money on each run. The double tracking looks great.

Only 2 real niggles and they really are minor.

1) If you're not building buses yourself then is there any need to spend money on bridges over roads?

2) In the image I've attatched trAIns built two lines from coal mines to power plants. The second line stopped at the power plant in the bottom of the image when all it needed was a little more investment to connect to the existing tracks and go to a power plant even further away, netting more money. It's really not an issue, just a refinement you might want to investigate.

Otherwise, 9/10 - looks great, plays great. An excellent debut onto the AI scene :)
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
lhrios
Engineer
Engineer
Posts: 22
Joined: 28 Dec 2008 00:16

Re: trAIns: An AI that play only with trains

Post by lhrios »

lawton27 wrote:I got that too on 7.1, I thought upgrading to 7.2 would fix it; I haven’t been able to test it on 7.2 yet due to and unexpected error.
I think I have solved this problem.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: trAIns: An AI that play only with trains

Post by Dustin »

Xander wrote: 1) If you're not building buses yourself then is there any need to spend money on bridges over roads?
I can think of some reasons:
  • Pathfinding is hard.
  • Roads are a special case of AITile.IsBuildable() == false. So just treating them as "bridgeable" along with rails is easier in some respects.
  • The Ai might want to add busses in the future. (Doubtful based on the name and mission statement, but D&RG has bus plans in V2).
  • Trains hit busses and that's not very nice. :D
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: trAIns: An AI that play only with trains

Post by lawton27 »

Very good work, downloaded your new version and all works fine :mrgreen:
it builds tracks nice, in fact similar to how a human would, (well at least me).
I found one problem it got stuck trying to find a path and just stood their doing nothing for ages, maybe add a pathfinder timeout, i resorted to doing some teraforming for it to get it to find a path, (see pic).
Later on it got stuck again for a rather obvious reason, it was trying to build efectivly over a station and then across a huge sea.

Besides from the pathfinder I've had no other problems and I'm very impressed by this ai.

A few ideas:

it likes coal, but coal can get a bit boring all of the time, does it do anything else? some passengers too would be nice.

Work on the pathfinder, I look forward to a new release, I don't know the ai script but I can imagine pathfinding is hard keep working at it and you'll have a great ai here.
Attachments
Cunnbury Transport, 16th Dec 1951.png
Cunnbury Transport, 16th Dec 1951.png (81.02 KiB) Viewed 1033 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: trAIns: An AI that play only with trains

Post by SirkoZ »

Nice to see your development of AI now in noAI-AI form, Ihrios.

Some suggestions:
-build some planes to get starting money :-)
(or some simple single lines with the two way depot and two trains)
two way depot - simple line for two trains
two way depot - simple line for two trains
Pinningville Transport, 4th Feb 1950.png (11.53 KiB) Viewed 14576 times
-use conditional order service at depot if reliability <50% or such, better than constant servicing - can really slow down the unloading station traffic
-perhaps 3-lane unloading station with trains from many different source going to it
-upgrading the suspension bridges to tubular (I'm not sure if it's already done)...was too sleepy to wait the game to roll some more...
-GPL2? :-)
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: trAIns: An AI that play only with trains

Post by Roujin »

I just tried you AI out and I can only say: Impressive. I really like your pathfinder. That's exactly how I would build those tracks...

edit: Maybe you'd like to make the routines you're using available as an AI library for other AI authors? They're really neat from what I see (only looked at the game, not the code though)
:bow:
* @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: trAIns: An AI that play only with trains

Post by Roujin »

Hi again,

I'm dropping back in here again to support a suggestion SirkoZ has made:
-GPL2? :-)
The reason? Well, as I wrote already I am quite amazed by your pathfinder. You wrote in several places that you hope your algorithms are useful to others, and I indeed think so - I've been collecting ideas for an own AI for some time now, and I've noticed that that the rails your pathfinder builds are very much like what I'd like my AI to build. So I'd like to reuse this part (rail building) of your AI in my AI, whereas I plan to let my AI different "bigger picture" than your AI (more emphasis on networking than being most competitive).
I read the LICENSING file of GPLv3, and understand that of course I may reuse parts of your AI (that's the spirit of GPL after all) BUT, I must also license my work under the GPLv3 or later.
On the other hand, the OpenTTD devs have constructed a project site for AI authors including all sorts of useful tools that I would like to use. Unfortunately, the use of this service is limited for works licensed under the GPLv2, which I cannot do if I use parts of your AI.

So, long story short, I would appreciate if you could make this possible somehow. I have heard about such things as licensing a work under both GPLv2 and GPLv3, so afaik it's possible - you may want to double check and/or ask someone more knowledgable about open source licenses than me though.

I'm looking forward to your answer :)
* @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: trAIns: An AI that play only with trains

Post by Dustin »

Roujin wrote: I have heard about such things as licensing a work under both GPLv2 and GPLv3, so afaik it's possible - you may want to double check and/or ask someone more knowledgable about open source licenses than me though.

I'm looking forward to your answer :)
The copywright owner (original author) in this case may license software however they see fit, and under different terms. So this shouldn't be a problem should the author decide to add a license.
lhrios
Engineer
Engineer
Posts: 22
Joined: 28 Dec 2008 00:16

Re: trAIns: An AI that play only with trains

Post by lhrios »

Roujin wrote:Hi again,

I'm dropping back in here again to support a suggestion SirkoZ has made:
-GPL2? :-)
The reason? Well, as I wrote already I am quite amazed by your pathfinder.
Thanks a lot!
Roujin wrote:You wrote in several places that you hope your algorithms are useful to others, and I indeed think so
That is true, but it needs to be improved before the creation of a library.
Roujin wrote: - I've been collecting ideas for an own AI for some time now, and I've noticed that that the rails your pathfinder builds are very much like what I'd like my AI to build. So I'd like to reuse this part (rail building) of your AI in my AI, whereas I plan to let my AI different "bigger picture" than your AI (more emphasis on networking than being most competitive).
I read the LICENSING file of GPLv3, and understand that of course I may reuse parts of your AI (that's the spirit of GPL after all) BUT, I must also license my work under the GPLv3 or later.
On the other hand, the OpenTTD devs have constructed a project site for AI authors including all sorts of useful tools that I would like to use. Unfortunately, the use of this service is limited for works licensed under the GPLv2, which I cannot do if I use parts of your AI.

So, long story short, I would appreciate if you could make this possible somehow. I have heard about such things as licensing a work under both GPLv2 and GPLv3, so afaik it's possible - you may want to double check and/or ask someone more knowledgable about open source licenses than me though.

I'm looking forward to your answer :)
Ok, I am working in a new version of trAIns. I will release it using the GPL2.
Some screenshoots of the new version:
trAIns.png
trAIns.png (67.64 KiB) Viewed 14330 times
trAIns_2.png
trAIns_2.png (57.83 KiB) Viewed 942 times
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: trAIns: An AI that play only with trains

Post by 1009 »

I really love the way it builds double rails. I have three suggestions:

- when a path is found, why not let it check the path again? It happens oftenly that another AI (I'm playing a duo game with NoCAB) builds something in the way of trAIns.
- (see attached image) -- it builds these routes quite oftenly. When trying to travel over a road with bridges or just for no reason. I don't see how it's pathfinding comes out more positive then just a straight track.
Non-straight track where straight was possible.
Non-straight track where straight was possible.
Predhead Transport, 15th Feb 1980.png (136.16 KiB) Viewed 14246 times
- EDT: it doesn't stop pathfinding. When there's a huge lake in the middle of two stations, it'll just continue for years. x_x
lhrios
Engineer
Engineer
Posts: 22
Joined: 28 Dec 2008 00:16

Re: trAIns: An AI that play only with trains

Post by lhrios »

I want to thank everyone who tested trAIns and/or suggested some modifications. It's not possible to implement all suggestion but some were used. Here is a small list of features:
  • Double railways;
  • Can create simple networks sharing part of railroads;
  • Can change the locomotive or rail type of already constructed railroads;
  • Adjusts the number of vehicles according to the production;
  • Build relative long railways (250 tiles);
  • Two kinds of arrangements for railroad stations;
  • GPLv2;
Main correction: Path finding won't freeze the AI anymore;

Source-code:
trAIns.tar
(330 KiB) Downloaded 394 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: trAIns: An AI that play only with trains

Post by SirkoZ »

List of flaws (to fix):
-mandatory servicing
-no unload (with no loading) orders
-no autorenew
-no upgrade of bridges to tubular for e.g. Lev4.

Laying tracks as before - flawless.
User avatar
cmoiromain
Chief Executive
Chief Executive
Posts: 655
Joined: 15 Jan 2007 21:45
Location: FRANCE
Contact:

Re: trAIns: An AI that play only with trains

Post by cmoiromain »

Hi

First of all, I really love your AI. Other train building AIs are nice, but none have the building style which I like to see in my games.

I just decided to run a game with only trAIns, nothing else, to see how it goes. Immediately it started to build pretty networks all over the map.

Here are a few remarks I want to point out, to make the pathfinding even better.
weird1.png
weird1.png (141.07 KiB) Viewed 926 times
Here, I think the AI is trying to link the coal mine at the bottom left to the power plant at the top. IMO it should instead link the coal mine to the power plant that is at the end of the line that disappears at the bottom of the screen (as it did with the other three coal mines already linked to is).
weird2.png
weird2.png (120.38 KiB) Viewed 13773 times
This is a closeup on where the three lines merge. I think some improvement can be made there. The bottom one could have this tight turn removed, and the top one could have been replaced by a straight line, connecting to the main line closer to where the bottom one links.
weird3.png
weird3.png (107.54 KiB) Viewed 13775 times
I think those bridges are unnecessary, it would be better tu go arround the lake rather than over it. OTOH, I don't know which of the two is cheaper.

More on the following post.
I am little, ugly, and nasty. How do you do?
User avatar
cmoiromain
Chief Executive
Chief Executive
Posts: 655
Joined: 15 Jan 2007 21:45
Location: FRANCE
Contact:

Re: trAIns: An AI that play only with trains

Post by cmoiromain »

weird4.png
weird4.png (71.86 KiB) Viewed 13764 times
This is just a little detail, but there is a bump on the line that could have been terraformed. It would look better, and be better for the trains.
weird5.png
weird5.png (102.5 KiB) Viewed 13767 times
Is the AI drunk? It can't walk straight ^^
weird6.png
weird6.png (102.18 KiB) Viewed 13754 times
Two things ot say about this one. First, the AI should have built the station to get the cargo from both coal mines. Second, and this is a global remark about the AI, using presignals there isn't IMO the best solution: if a lost train arrives here, the pathfinder doesn't know how to handle turning around. In this particular case, the train will not stop at the entrance signal, and wil block the whole station. Path signals would suit better here, because they would both prevent that problem and allow a better flow.

That's it. Hope you can improve those points, to make the AI even better.

Keep up the good work!
I am little, ugly, and nasty. How do you do?
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests