FelicitusAI v0.2.1

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

Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

FelicitusAI v0.2.1

Post by Felicitus »

Hi,

this thread is meant to inform you about the development progress on the FelicitusAI, and also to get new ideas which can be implemented during the development progress.

Introduction
The FelicitusAI is an AI which tries to beat you using trains. It models a high-performance AI (similar to the players on Kurt's hard goal servers). Basically, it starts off with a simple line, which is aimed to be as long as possible, and then extends that line to a dual-track line and eventually builds a grid-based main line network to connect everything on the map. It is also planned that the AI can build new industries as needed, to optimize the existing delivery of cargo.

Latest Version
Version 0.2.1
Last edited by Felicitus on 01 Mar 2009 10:51, edited 3 times in total.
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

FelicitusAI - Development Progress: Stations

Post by Felicitus »

In order to keep the AI flexible, the engine allows an on-the-fly upgrade of existing stations. I'm currently working on the basic station builder, which has generic methods to build stations. The station builder allows to extend and to upgrade stations. Extending a station means that stations extend the platform length to meet new requirements. Upgrading a station means that the station layout itself is updated, for example, converting a simple station to a RORO station.

Right now I've got two stations: A basic station in two lengths, a RORO station, a simple terminus station and a terminus station with two platforms.

You can see the stations which the station builder can build in the attachment.
Attachments
MacDonald & Co., 1st Nov 1952.png
(39.32 KiB) Downloaded 330 times
Wold
Transport Coordinator
Transport Coordinator
Posts: 318
Joined: 03 Aug 2006 19:32
Skype: woldy_bg
Location: Bulgaria

Re: FelicitusAI - Development Progress

Post by Wold »

A thing I don't like about Kurt's "game type" is the RoRo sleek station. You lose about 15% of the rating by forcing the train to a depot since no points are awarded for the speed part.

Nice idea. I hope you realize it
Image
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

Yes, I know :) I don't know if the sleek roro will ever be built by the FelicitusAI, let's see what development brings.
User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: FelicitusAI - Development Progress

Post by Timitry »

The ideas for your AI sound promising, i hope you can realize that!

I like the idea of using those roro-sleek stations, however, i have a suggestion. See my attached picture to see what it looks like.
Advantages: Two trains can load at the same time, which will give you a higher rating (first train is full ---> second train starts loading immediately) in comparison to the one-platform version (first train is full ---> leaves station ---> second train enters station ---> second train starts loading).
It does not occupy much more space than the single-platform layout and is easy to build. The depot can hold an infinite amount of trains, and they will only leave the depot if one of the platforms is free. This might especially be useful if you plan to let your ai build big networks, where one jammed up station could block the whole traffic. With this kind of station, your excess trains are always out-of-the-way, plus you could probably easily check whether a platform has too many trains by "looking" into the depots - ideally there is always one train waiting in it :)
I hope i can convince you of that layout, and good luck with your ai!
Attachments
RoRo_Sleek.PNG
RoRo_Sleek.PNG (14.38 KiB) Viewed 6782 times
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

Believe it or not, I just implented that station for my parseStation function - basically I'm a lazy developer and after implementing the first two stations by hand, I got bored and so I wrote a function which parses an existing station, and writing the output to the console, so I can just copy the commands and put them into the station code. The station builder even supports rotation now :)

By the way, there's a little mistake in your station. You have no signals between your depot and the station, so the train would only leave the depot if both platforms are free :( Or does the new depot have a PBS signal in it? EDIT: Oh yes, it does! That's brilliant - so we can save one more tile space :) FelicitusAI is happy now, as it doesn't need so much space ;)

So its pretty easy for me and other developers to add new station types. Of course, if the station has a variable amount of platforms, a littlebit of manual coding is required. Looks good for now, it's time for bed then ;)
Attachments
MacDonald & Co., 15th Jun 1969.png
(140.21 KiB) Downloaded 199 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: FelicitusAI - Development Progress

Post by SirkoZ »

Wow - Felicitus - I'm impressed by your AI plan - I've been to Kurt's server many times and people there really build neat networks.

It will be great to have such a capable and smart AI.

I wish you success with this project. ;-)
User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: FelicitusAI - Development Progress

Post by Timitry »

Felicitus wrote:Believe it or not, I just implented that station for my parseStation function
...
FelicitusAI is happy now, as it doesn't need so much space ;)
Glad to hear that :)
I made a little example of how your AI could evolve a two-way-railway track with that station. I know that you probably have your own agenda for your ai, but i'm just in a kind of idea-rush which i need to share with someone, and you're unlucky to be that one :D, so never mind :)

If there's a lot of cargo being generated at the coal mine station, you might need three platforms!

(2 more pictures following...)
Attachments
Step1.PNG
Step1.PNG (24.09 KiB) Viewed 6707 times
Step2.PNG
Step2.PNG (29.23 KiB) Viewed 6720 times
Step3.PNG
Step3.PNG (30.63 KiB) Viewed 2000 times
User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: FelicitusAI - Development Progress

Post by Timitry »

(The last 2 pictures)
Attachments
Step4.PNG
Step4.PNG (33.11 KiB) Viewed 2123 times
Step5.PNG
Step5.PNG (34.39 KiB) Viewed 2116 times
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

Yes, that's the plan. Basically, the AI starts off with a stage 1 platform (which is a simple, short platform, length 4) and sends the train then. After the train delivered, it extends the train and the platform to be longer (length 10 or shorter, if the allowed station spread is lower), then sends the platform for a second run. After that is done, it upgrades the platform to a basic roro platform, and if enough money is left, a second train is bought and the track is converted to a (partial) dual line track.
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

A little status update: My AI got its first train running - and well, it already made a good profit :) (see attachment)

Altough it sounds very unspectacular, the AI engine already does A LOT of things:

- Calculating which industries are best to connect in the first place
- Estimating the line and train costs
- Rating all available engines by reliability, speed, power and cost and picks the best one
- Picking the correct wagons for the cargo
- Automatic placement of a depot
- Keeps a map of all lines in memory, so the AI can connect these lines later using junctions
- Calculation of the optimal station placement, and tries to place the two stations as far as possible from each other

Unfortunately, it's currently not possible to use this AI (or probably any AI) with NewGRF trains which have specific checks, for example, the North American Train Set. This is due to the fact that the NewGRF itself decides wether a wagon can be attached to an engine, and this data is currently not (or probably never?) accessible by the AI. So the only way for an AI to support NewGRFs is trial and error: Buy the engine, try to attach the wagons, and see if it fails or not.

Next step will be to automatically buy wagons until almost all money is used (up to a maximum length), and extending the station before the first train arrives, in order to optimize the first run of the train.
Attachments
Darnway Transport, 15th Oct 2005.png
(99.46 KiB) Downloaded 185 times
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: FelicitusAI - Development Progress

Post by planetmaker »

Hi,
I'm quite impressed by the speed of your progress and I'm really looking forward to a first playable version of your AI :)
Felicitus wrote:Unfortunately, it's currently not possible to use this AI (or probably any AI) with NewGRF trains which have specific checks, for example, the North American Train Set. This is due to the fact that the NewGRF itself decides wether a wagon can be attached to an engine, and this data is currently not (or probably never?) accessible by the AI.
Reading that, I wonder whether AIEngine Class shouldn't support that (quote from NoAI API docs):

Code: Select all

static bool 	CanPullCargo (EngineID engine_id, CargoID cargo_id)
 	Check if the engine can pull a wagon with the given cargo. 
I see that it is a query for a cargo and not for a specific wagon, but cargo is the more important thing, isn't it?
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

Unfortunately, CanPullCargo is only reliable if it returns false - if it returns true, it doesn't mean that it is reliable. Example: You can build a train with the North American Train Set which can pull only light cargo. In my tests, the Engine was built, CanPullCargo returned true, but I was only able to attach ONE wagon. Subsequent wagons couldn't be attached - that's a check implemented in the NewGRF.
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

This doesn't work as expected (see attachment :))
Attachments
Wudworth Transport, 14th Sep 1969.png
(75.47 KiB) Downloaded 185 times
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: FelicitusAI - Development Progress

Post by planetmaker »

It doesn't compile here...

for simplicity I moved it also to content_download. I also replaced the library folder therein by the one you supplied as instructed:

Code: Select all

Error /Users/ingo/Documents/OpenTTD/content_download/ai/FelicitusAI/info.nut:1/8: expression expecteddbg: [misc] [squirrel] Failed to compile '/Users/ingo/Documents/OpenTTD/content_download/ai/FelicitusAI/info.nut'
Morloth
Transport Coordinator
Transport Coordinator
Posts: 378
Joined: 07 Feb 2008 14:06
Location: Glasgow

Re: FelicitusAI - Development Progress

Post by Morloth »

Hi Felicitus,

Great to see you working on your AI! I'll be following your progress with great interest as I haven't implemented trains as of yet in my own AI. I really like your incremental approach to station building and I curious what solutions you find to building train connections and how it compares to AdmiralAI's approach. Best of luck and I look forward play testing your AI :).

Bram
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI - Development Progress

Post by Felicitus »

The first release is here!

Features:
- Builds quite distant source and target stations
- Automatically buys new trains if there's too much cargo waiting
- Tries to connect everything on the map

Right now there are still quite a lot of issues:
- FelicitusAI currently only builds dual track mainlines. This is due to a problem where it doesn't build trains when doing single line tracks, I don't know why this happens, so I disabled all stations using a 1 track layout (which only makes one station type remaining ;))
- No connecting of lines possible at the moment
- Doesn't use terraforming at all
- Sometimes it cannot build a train or finish the line, the whole process will be broken apart so that it can resume the partial building later. Maybe I will also introduce some kind of cash management (where different parts of the AI can "reserve" money so that other parts don't use the money needed).

Next Release will include:
- Fixing the bugs above
- Terraforming for stations

If you try this out, please leave comments and of course, if something looks wrong or if the AI crashes for some reason.

Download:
Felicitus AI v0.2

Thanks,
Felicitus
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: FelicitusAI v0.2

Post by GeekToo »

Real nice work.

I've tested it for a while now, and so far it looks pretty stable.

Just a few remarks:
-Early in the game, the long trains are really slow, as the engines are not so powerful. I like how it looks, but I doubt it gives optimal income.
-It uses a lot of level crossings with roads. When the roads are busy, the road vehicles stop for a train in one direction, and block the track in the other direction, just waiting to crash one of your trains.

But overall, keep going, I think this AI shows big potential.
railnut
Engineer
Engineer
Posts: 4
Joined: 11 Feb 2009 19:03

Re: FelicitusAI v0.2

Post by railnut »

Congrats on getting it out there ...

Am having problems playing it on my favorite scenario ... see screenshot below ...

Secondly, which rail pathfinder library version does it need ? 'main.nut' says v2 - but only v1 available ?
Attachments
Unnamed, 2nd Jan 1946.png
Unnamed, 2nd Jan 1946.png (40.02 KiB) Viewed 2049 times
Felicitus
Engineer
Engineer
Posts: 29
Joined: 17 Feb 2009 06:35

Re: FelicitusAI v0.2

Post by Felicitus »

The version 2 is bundled, if you get the error that you get, everything is alright. I think it fails to find a route, can you send me that scenario for testing?

By the way, the AI will NOT work with OpenTTD beta 1. You need at least the nightly r15553 or later.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Baidu [Spider] and 5 guests