Page 1 of 14

SimpleAI v14 - trying to remake the old AI

Posted: 19 Aug 2009 09:26
by Brumi
Hi all,
Let me join this wave of new AIs. I'm trying to remake the old AI in the NoAI framework, of course with some changes. It uses road vehicles, trains and aircraft. As it is intended to be similar to the old AI, it is a weak competitor, so don't expect too much from it. I did not remake the road/rail building style of the old AI, I'm using the library pathfinder. I have to compensate that the AI cannot cheat anymore with terraforming.
SimpleAI.png
SimpleAI.png (98.61 KiB) Viewed 40205 times
Features:
  • Uses road vehicles, trains and aircraft
  • Supports all non-NewGRF cargo, and most NewGRF cargo as well
  • Goes for subsidies
  • If there are no subsidies, it chooses the cargo and the industries/towns randomly.
  • It uses the library pathfinder.
  • It corrects the route if it's interrupted while building.
  • It electrifies existing rail lines when the first electric engine is introduced.
  • It sells unprofitable vehicles and removes the route if all vehicles are sold.
  • Save/load compatibile
  • The handling of old vehicles is similar to the old AI, instead of using autorenew.
  • It upgrades existing bridges to newer ones if they're available.
Changelog:
v14
  • Fixed running cost calculation in the train engine valuator (fix by SirkoZ)
  • More fault tolerance when building road stations: the AI now should not leave C-shaped road pieces when failing to build a road station.
v13
  • Fixed possible division-by-zero error in cBuilder::GetLastMonthTransportedPercentage().
  • Capped the maximum amount of routes at 1000 to prevent "Took too long to save" errors.
v12
  • The AI now correctly calculates the minimum amount of money needed to invest in aircraft
v10
  • Alternate naming system for the company by 3iff
  • The inflation rate is now correctly handled as a float, possibly avoiding some bugs
v9
  • Fixed an overflow bug which could cause division by zero
v8
  • Fixed a bug related to saving games right after loading
v7
  • Updated to NoAI API version 1.2
  • Support for NewGRF trainsets
  • Support for range-limited aircraft
  • Avoid railtypes that do not support all cargoes
  • Fixed a crash when the game was saved between the construction of two stations
  • A more advanced road vehicle selection algorithm (from DictatorAI)
  • Fixed a rare road building bug
  • The AI now uses Road Pathfinder v4 and AyStar v6
v6
  • Added comments to the code
  • Written this readme
  • Refitting train wagons
  • Fix a bug when some old vehicles didn't get replaced at all
  • Support for NewGRF train stations
  • An option to use path signals at single rail stations
  • Avoid going bankrupt because of station maintenance costs
v5
  • Plane support
  • Upgrading existing bridges
  • An option to use PBS signals instead
  • Bugfixes
v4
  • Bugfixes again
v3
  • Bugfix
v2
  • Bugfixes
  • Updated to NoAI API version 1.0
  • Changeable settings in-game
  • An option to use two-way signals (like in TTO)
v1
  • First Bananas release
  • A little change in pathfinder penalties
beta3
  • Bugfixes
  • Checking vehicles which are sitting in the depot
beta2
  • Improvements in save/load
  • Adding wagons to existing trains
  • An option to make the AI slower as the time progresses
  • Bugfixes
beta1
  • Basic save/load support
  • Adding road vehicles to an existing route, up to a limit chosen by the user
  • Replacing older models with newer ones
  • Added setting to specify the number of days to wait between building two routes
  • Flipping passing lane sections
  • A bit more consistency with the HQ builiding behaviour of the old AI, added a setting to build the HQ in a town
alpha5
  • Double railway lines (in the style of the old AI)
  • One more wagon is added to a train if the engine has only one unit
  • Combined passenger/mail trains, no more pure mail trains
  • Minor bugfixes
alpha4.1
  • A little bugfix
alpha4
  • Correcting the rail line if the AI gets interrupted while building
  • Basic money handling, paying loan back
  • Support for other railtypes, electrifying existing lines
  • Detection of "Disable trains/roadvehicles for computer" under Advanced Settings
  • Bugfixes
alpha3
  • Train support (single point-to-point routes so far)
  • Added settings to use trains or road vehicles only
alpha2
  • Added setting to configure the chance of going for a subsidy
  • Added setting to configure competition level based on the last month transported percentage
  • Basic event handling
  • Selling unprofitable vehicles and deleting empty routes
  • Refitting road vehicles
alpha1
  • Basic version, road vehicles only
Dependencies:
  • Pathfinder.Road v4
  • Pathfinder.Rail v1
  • Graph.Aystar v4 (a dependency of the rail pathfinder)
  • Graph.Aystar v6 (a dependency of the road pathfinder)
  • Queue.BinaryHeap v1 (a dependency of Graph.Aystar)
These sould be installed in content_download\ai\library if you download the AI from here.

I'd like to say thanks to the writer(s) of the library pathfinder, I couldn't have done without it!
Also thanks to 3iff for his contribution which enables the AI to use custom company names instead of the default names.
The AI contains code from PAXLink, NoCAB and DictatorAI, so thanks for Zuu, Morloth and krinn for writing that.
I'd also like to say thanks to all those who tested this AI.

Version 14 is downloadable here.

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 19 Aug 2009 11:10
by Xander
Brumi wrote:I'd like to say thanks to the writer(s) of the library pathfinder, I couldn't have done without it! :bow:
Here here! :bow:

Also - why no NewGRF support? It's dead simple to integrate, just use the lists rather than any hard-coded values ?(

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 20 Aug 2009 18:45
by Brumi
Xander wrote:why no NewGRF support?
Well, it's not totally true that it has no NewGRF support at all. If I teach the AI tho refit its vehicles it will be fairly compatibile with some basic NewGRFs that doesn't change the game too much. The current version shouldn't have problems with the Generic Tram Set, for example. What I want to avoid is the more 'radical' GRFs, which change costs or even the economy. Currently the AI can't cope with them.
My primary goal is to remake the old AI in some way (which didn't have NewGRF support), so let me concentrate on that first. OK I will introduce refitting compatibility, but I don't want to deal with the ECS vectors for now.
I will change that notification in the first post. Sorry if that is too harsh.

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 20 Aug 2009 19:10
by Dustin
Brumi wrote:
Xander wrote:why no NewGRF support?
Well, it's not totally true that it has no NewGRF support at all. If I teach the AI tho refit its vehicles it will be fairly compatibile with some basic NewGRFs that doesn't change the game too much. The current version shouldn't have problems with the Generic Tram Set, for example. What I want to avoid is the more 'radical' GRFs, which change costs or even the economy. Currently the AI can't cope with them.
My primary goal is to remake the old AI in some way (which didn't have NewGRF support), so let me concentrate on that first. OK I will introduce refitting compatibility, but I don't want to deal with the ECS vectors for now.
I will change that notification in the first post. Sorry if that is too harsh.
2cc seems to be the most popular train set. You might want to make a priority list of NewGrfs and support them in that order. NARS is easy. 2cc is slightly harder. ECS I haven't even considered.

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 20 Aug 2009 20:49
by SirkoZ
Really nice effort, Brumi.
I have similar thing planned to do when I have the time and perhaps when the framework is made easier to cope with (one such effort being the Library)... :-)

By the way - Dustin - is it really necessary to support 2cc/NARS, etc. by some special way - I mean doesn't the AI author only have to take care of vehicle handling through comparing costs/HP/speed and then choose based on that?

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 20 Aug 2009 21:43
by Dustin
SirkoZ wrote:Really nice effort, Brumi.
I have similar thing planned to do when I have the time and perhaps when the framework is made easier to cope with (one such effort being the Library)... :-)

By the way - Dustin - is it really necessary to support 2cc/NARS, etc. by some special way - I mean doesn't the AI author only have to take care of vehicle handling through comparing costs/HP/speed and then choose based on that?
I had some suprises when I switched between default to NARS. I had actaul crashes.

I think the logic to join the wagons to the engine was a problem. When I switched to 2cc my AI never built a train. The "best" locomotive costs more than the starting loan. So I had to add some logic to buy the best, yet affordable engine. So in the AI was code compatible, but needed some tweaks to actually run a profitable route. D&RG still goes bankrupt often with 2cc on a rough map.

With D&RG if you run the default set it runs best with a low "fiscal restraint". If you run 2cc it will go bankrupt with anything less than super "fiscal restraint". So I added that as a setting to the AI.

So, just because you work in default doesn't mean you will work with the other sets.

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 21 Aug 2009 08:24
by Brumi
Thank you for the replies.
It's true that my biggest fear is the 2cc set with its high prices, but I didn't mention it because I have no train support yet. The other part is engine selection, as with the default set it is quite good to choose the strongest and fastest engine. The current code sorts the vehicles by maximum speed, and excludes articulated vehicles. NewGRF road vehicle sets (at least the more well-known ones) should be fairly easy to support, refitting should do the trick. Another thing I should do is to handle the case when there are no suitable vehicles available (e. g. the eGRVTS at early dates, when all vehicles are articulated).
Train engine selection will be much harder with NewGRF sets. I rarely play with NewGRF sets, and even I have trouble with choosing the right engine. But first the railway construction will be a pretty hard task for me. Those single lane point-to-point routes should not be so difficult to do, but I will certainly have lots of difficulties with the old AI-like double rails. (you know, two stations first, then two passing lane sections, then connecting them) I will surely have to deal with some terraforming.
Anyway, how do you decide if you will have enough money to build a route? Currrently the AI tries to build a new route if it has more than 90,000 pounds. But that is certainly not the correct routine.

Re: SimpleAI alpha1 - trying to remake the old AI

Posted: 21 Aug 2009 18:06
by Dustin
Brumi wrote:Thank you for the replies.
It's true that my biggest fear is the 2cc set with its high prices, but I didn't mention it because I have no train support yet. The other part is engine selection, as with the default set it is quite good to choose the strongest and fastest engine. The current code sorts the vehicles by maximum speed, and excludes articulated vehicles. NewGRF road vehicle sets (at least the more well-known ones) should be fairly easy to support, refitting should do the trick. Another thing I should do is to handle the case when there are no suitable vehicles available (e. g. the eGRVTS at early dates, when all vehicles are articulated).
Train engine selection will be much harder with NewGRF sets. I rarely play with NewGRF sets, and even I have trouble with choosing the right engine. But first the railway construction will be a pretty hard task for me. Those single lane point-to-point routes should not be so difficult to do, but I will certainly have lots of difficulties with the old AI-like double rails. (you know, two stations first, then two passing lane sections, then connecting them) I will surely have to deal with some terraforming.
Anyway, how do you decide if you will have enough money to build a route? Currrently the AI tries to build a new route if it has more than 90,000 pounds. But that is certainly not the correct routine.
DR&G decides to build a new route if it has some fraction of the max loan available as cash. With low restraint it's 50%+ with super restraint it 100%+. So it's automatically scaled for inflation.

Re: SimpleAI alpha2 - trying to remake the old AI

Posted: 22 Aug 2009 12:00
by Brumi
I posted the alpha2 version in the main post. You can see the changelog there.
Now the AI supports basic road vehicle sets, so it should work with (e)GRVTS. It doesn't use articulated vehicles, so it won't do anything if there are only horse carriages available.
I added event handling, from now on the AI will sell its unprofitable vehicles. It's quite a slow process, it only happens when the AI gets the 'vehicle unprofitable' notification from the game engine.
Still no progress was made in the field of money handling, I'm thinking about that. :oops: Please report it if the AI runs out of money while building the route!
Thank you for testing,
Brumi

Re: SimpleAI alpha2 - trying to remake the old AI

Posted: 22 Aug 2009 14:11
by 1009
I've been testing SimpleAI. I like how it works, really fast, no difficult calculations (as far as I can see in the log)
Suggestion: try to re-use stations. It built a drop off for iron ore and a pick up for steel. I don't know whether that's necessary.

Re: SimpleAI alpha2 - trying to remake the old AI

Posted: 22 Aug 2009 14:54
by planetmaker
Eliandor wrote:Suggestion: try to re-use stations. It built a drop off for iron ore and a pick up for steel. I don't know whether that's necessary.
It's actually good practise to not mix drops and pickups together in one station. It saves you jams... especially that situation where nothing can be delivered anymore due to all slots being taken by pickup trains thus that no delivery can happen.

Re: SimpleAI alpha2 - trying to remake the old AI

Posted: 22 Aug 2009 15:04
by 1009
planetmaker wrote:It's actually good practise to not mix drops and pickups together in one station. It saves you jams... especially that situation where nothing can be delivered anymore due to all slots being taken by pickup trains thus that no delivery can happen.
Hm OK, point taken XD

Re: SimpleAI alpha2 - trying to remake the old AI

Posted: 23 Aug 2009 18:17
by Brumi
Thank you for testing. :)
It's a good idea that the AI should re-use stations (at least drop-off stations), but I'm afraid I won't be able to do it in the early alpha stage. First I'd like to get done with emulating the old AI (at least trains), then I can concentrate on some advanced features. Re-using stations would need station expanding to be implemented, which is not an easy task for me. So I'll se what I can do, but don't expect it to be implemented too soon.
Thanks again for testing.

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 16:43
by Brumi
I uploaded alpha3 to the first post.
The most visible change is the train support, from now on the AI will use trains as well. 8) So far I only implemented single point-to-point routes. I will have a hard time getting those old AI style double railways to work... :?
It is supposed to remove the rail line if the train is unprofitable, so please report it if it doesn't do so!
Currently it chooses between trains and road vehicles based on pure chance, I will do something about that until the next release. It also doesn't notice if it gets interrupted while building the railway.
Thanks for testing.

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 16:53
by fanioz
Good Job :D

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 16:57
by Brumi
fanioz wrote:Good Job :D
Thank you :)

Oops... I forgot to remove a line from the code that was there just for debug reasons. I updated the .tar file in the main post. Nothing serious, it just removed unused rails very slowly.

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 18:20
by 1009
Congrats on the new version. I tried it with 0.7.2 but it crashed. Just downloaded the latest nightly and that worked perfectly fine. Maybe you should add that as a note to your first post, to avoid confusion.

By the way, it builds lovely tracks. I know it's just the default pathfinder, but it really suits your simple AI. It's nice to play against because of it's "clean"-ness. :)

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 19:00
by Brumi
Thank you for the kind words. :)
Eliandor wrote:I tried it with 0.7.2 but it crashed. Just downloaded the latest nightly and that worked perfectly fine.
Really? ?( I've always tested it with 0.7.2 so far, never tried the nightly. In fact, I'm developing it for 0.7.2, and I'll try to fit it for the latest stable release. In the nightly it may have minor problems (or even crash) because of the new subsidy management, but that's really a small issue. It should work just the other way round :D
Anyway, please post it here if you encounter that crash again. Probably it's a bug in the code.

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 19:06
by 1009
Brumi wrote: Really? ?( I've always tested it with 0.7.2 so far, never tried the nightly. In fact, I'm developing it for 0.7.2, and I'll try to fit it for the latest stable release. In the nightly it may have minor problems (or even crash) because of the new subsidy management, but that's really a small issue. It should work just the other way round :D
Anyway, please post it here if you encounter that crash again. Probably it's a bug in the code.
Alright... this is just weird. I downgraded to 0.7.2 again and tried once more, it didn't crash this time. It crashed two times before though o__0; well, I guess everything's cool then. I'll keep on the lookout for it though.

Re: SimpleAI alpha3 - trying to remake the old AI

Posted: 29 Aug 2009 19:11
by 1009
Wanted to add another teaser to what you have in your first post, something illustrating it's typical behaviour:
simpleAI_teaser.png
simpleAI_teaser.png (50.41 KiB) Viewed 40620 times
I can confirm that SimpleAI tries (and succeeds) to re-pathfind roads when blocked unexpectedly. Congrats once again :D
When the pathfinding fails completely, though, it does remove the stations, but not the route. Oh well.

Suggestions:
= make it build larger stations when the route is longer. In cities it's mostly not possible to build 4 tile stations at reasonable places, but close to industries, it may be.

Edt: removed bug report because it was already in your first post (train error correction)