SimpleAI v14 - trying to remake the old 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
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: SimpleAI v1 - trying to remake the old AI

Post by Dustin »

Yexo wrote:
Kogut wrote:Is it OK to reuse code from other AIs (for example improved road pathfinder from SimpleAI)?
That depends on how an AI is licensed. Currently all AIs uploaded to bananas (with the exception of Denver & Rio Grande) are licenced under GPL v2. That means you're free to reuse code as long as you make your AI available under the GPL v2 licence too (in effect making your code available for reuse too).
Just a note: Denver & Rio Grande uses the BSD license wich is less restrictive even then the GPL v2. Basically, feel free to use any of the code however you wish. If you take code I wrote word-for-word then please mark those sections with my name and copyright information in the code file. But that's the only restriction.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Version 4 is out on Bananas and the first post.
It contains two minor bugfixes (well, two lines of code were changed :) ):
  • The bug reported by Raider, now the AI should load properly if the game is saved between the construction of two stations.
  • A bug was fixed which prevented the AI from getting started if inflation had already done its effect. (Thanks to Zuu for running that test :) )
Maybe I will have more time in the summer to add plane support as well.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

Test: latest nightly + v4 + inflation - the biggest interest rate (4%) - in 1990, with USD 900,000 available (diluted from the starting USD 200,000), SimpleAI won't build anything - of course with road vehicles set to max. 0. I think it could easily build a short goods or passenger train. Perhaps set it so it buys a bit slower locomotive at first (e.g. Gresley A3 instead of A4 or EE'37' instead of BR'87') so it can get the starting money even if started late...
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Yes, that's quite a corner case. Fixing it is not just 1 extra line of code, because the currently the AI always chooses the fastest train engine available. So a little work in engine selection would be useful... :?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SimpleAI v4 - trying to remake the old AI

Post by Kogut »

There is very good train finder in Denver & Rio Grande, with newgrf support. (But designed for freight trains)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: SimpleAI v4 - trying to remake the old AI

Post by Dustin »

Kogut wrote:There is very good train finder in Denver & Rio Grande, with newgrf support. (But designed for freight trains)
Thanks for the kind words Kogut! Please do feel free to use it. It should work for PAX. As I recall you pass in the desired cargo type and it works out an engine that can haul it.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

Another (little) annoyance: sometimes when AI has got enough trains (lets say 15) and it's late in the game and inflation has had its way, so to speak, I get messages if I want to buy the said SimpleAI company. Of course - before that it gets some bankruptcy warnings.

Now from my observation - this happens because AI is too "obsessed" to repay even the smallest amount of loan.
I propose it taking as much loan as possible when in the building mode if it doesn't have at least 3x the amount of the maximum loan money prior to going into building mode.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Inflation again... :( The problem is that I don't play with inflation myself so I'm not used to it.
The interesting thing is that the AI nearly always tries to keep some cash (at least the loan interval) at hand. In the pathfinding loop it doesn't, so that might be the problem. If you experience this again, please post a savegame or a screenshot of the log!
Anyway, did the company survive or it was bought by someone else?
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

Oh - that's a frequent situation in my games - in that same game yesterday I saw that message at least 3 more times and one company even went bankrupt - all because locomotives are expensive in 2020+ and that dear sweet AI just had to repay every single USD 100,000. It just so happened that the result of its repayin' was that it was in red (-cash) when just the right month came by (= end of Dec/March/June/September). This happened 3 times and it was out/offered to me to buy it, I didn't want, it was still micro-managing the repayments, so it went bye-bye. Oh well. :-)

The funniest thing aboot it all is that it says in its debug log "I'm in trubel, I don't know what to do!" (those two "typos" are intentional). :mrgreen:

P.S.: You can perhaps add a condition that only if inflation=1 it repays money only when it's got 3 or 4 times the max_loan and not before. :idea:
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

I smell some miscalculation in my code there, because as I said, the AI checks whether it has less than the loan interval, and loans if needed. Or maybe it lost the money during pathfinding. The AI cannot get into negative by its own actions, so paying back loans shouldn't be a problem. The problem comes when it doesn't loan when it should...
So I would need a screenshot or a savegame to check where the miscalculation is. I'm almost certain that this is a bug (because of my lack of knowledge about inflation-enabled games) and not a bad algorithm.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: SimpleAI v4 - trying to remake the old AI

Post by planetmaker »

A small comment dedicated to this AI as based from my (short) competitive run with a number of other AIs: you did very well, this is the AI which did best when considering the use of trains.

Best areas of improvements now seem to be from this brief test: you might consider to also add some basic plane support; they might in some situations make a good money maker. The train support could build more tracks and connections. Long-distance routes might give big(ger) profit. With 5 million on the bank, there's sufficient space to start some serious building, even with 2cctrainset in place.

Attached a screenshot which compares this AI with the best AI (AIAI) and the best train-using AI (simpleAI)

All in all: kudos, you did a great job :-) I love to see real rail tracks being built!
Attachments
simpleAI.png
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Thank you for the test :) Plane support is already on the to-do list, but I don't know when I will have enough motivation to code that. I intend to do it this summer.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

One suggestion - for experimenting a bit if nothing else - Brumi, would you please make the rail station and train length (in squares/tiles) configurable - up to let's say 7 tiles trains and stations and passing lanes (single and double rail).
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Sorry for the late reply, I was away for a week :)
Surely not the easiest thing to do with the current code, but not impossible. I still don't know when I will continue the development of SimpleAI (plane support should be the first thing to do), but maybe I'll give it a try when I feel like coding.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

Here's another one - it would be more truck-friendly if one-way path-signals were choose-able for rail lines. :)
AI can't always make a rail bridge over the road...
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi »

Sure, there's already a setting to build two-way signals, I will add PBS signals as a third option.
I really owe you the next version, it's been a long time since the last one :?
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

No need for confusion.

Another thing - aesthetically pleasing mostly, but for towns, functional. When AI is building a new road it could perhaps check for already existing road and not build one on the neighboring square but 2 squares/tiles apart. Pic:
Attachments
Camana Transport, 20th Feb 1950.png
Camana Transport, 20th Feb 1950.png (20.09 KiB) Viewed 2775 times
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: SimpleAI v4 - trying to remake the old AI

Post by FooBar »

The left situation is something that the old AI could've done. So for a remake of the old AI... :)
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v4 - trying to remake the old AI

Post by SirkoZ »

Indeed. :-)

Anyway - another thing - functionality improvement - the AI should consider upgrading the suspension bridges (max. 70mph) to tubular when they are available...
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: SimpleAI v4 - trying to remake the old AI

Post by Lord Aro »

Again, the old ai would have made huge long wooden bridges, and certainly never upgrade them
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
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 33 guests