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

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

Re: SimpleAI alpha3 - trying to remake the old AI

Post by Brumi »

Eliandor wrote:When the pathfinding fails completely, though, it does remove the stations, but not the route. Oh well.
That's because it costs money to remove the route, and since roads are 'public domain', someone may use them later :)
Eliandor wrote: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.
That will come with time, but not simply longer stations, they will be 2x3. It will be the emulation the old AI's double rail, which handles two trains. Until then I'll have to introduce a better money handling algorithm, as these routes will be pretty expensive.
Otherwise, it shouldn't be too hard to introduce a setting to enable longer stations.

Thank you again for testing. :)
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: SimpleAI alpha3 - trying to remake the old AI

Post by 1009 »

Fatal error somewhere after the year 2000
SimpleAI_fatal.png
SimpleAI_fatal.png (13.56 KiB) Viewed 1079 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha3 - trying to remake the old AI

Post by Brumi »

Thank you for the report. The problem appears to be that there was no train engine available for the normal (non-electrified) rail. Support for other railtypes is not done yet.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha3 - trying to remake the old AI

Post by SirkoZ »

One thing that's been bugging me for a while - Brumi please set the amount of loan and also the amount of money (as a pre-condition to even start building) to max_loan/2 this way the AI will be able to actually build the whole track instead of just stations in the latter years of an inflation-enabled game.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha3 - trying to remake the old AI

Post by Brumi »

Actually my intention is to include a money check in the building loop, which loans more money if the cash on hand is less than 10k pounds. The problem here is avoiding super-expensive bridges and tunnels.
Sorry but I'making very slow progress at the moment, it is my first week at university... I've implemented exception handling for the rail builder, and now the AI can pay back its loan. This weekend I'll try to do something, it will be a general update for rails (and maybe money handling), so the double rails will only come later. That hardcoded 90k minimum money to build a new route needs to be removed, I'll have to do a quick estimation based on the inflation and engine costs.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: SimpleAI alpha3 - trying to remake the old AI

Post by Dustin »

Brumi wrote:Actually my intention is to include a money check in the building loop, which loans more money if the cash on hand is less than 10k pounds. The problem here is avoiding super-expensive bridges and tunnels.
Sorry but I'making very slow progress at the moment, it is my first week at university... I've implemented exception handling for the rail builder, and now the AI can pay back its loan. This weekend I'll try to do something, it will be a general update for rails (and maybe money handling), so the double rails will only come later. That hardcoded 90k minimum money to build a new route needs to be removed, I'll have to do a quick estimation based on the inflation and engine costs.
Just looking at the current maximum loan available is an easy way to scale to inflation. It worked for me anyway.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha3 - trying to remake the old AI

Post by SirkoZ »

I now fixed the alpha3 to build quite avidly and also repay the loan when time is right - through these 3 simple conditions:

Code: Select all

If money > $190,000 (Ł95,000) => carry on then:
    if money < max_loan / 2 => increase loan to max_loan;
    if however money >= max_loan x 4 => loan is set to zero (repaid);
    build something (been here before - not changed).
Here is main.nut with these three changes (if Brumi doesn't mind :-) ):
main.nut
(2.41 KiB) Downloaded 161 times
.
I'm running a game even now - testing this (in r17500) and it's working very nicely - with hilly original terrain the SimpleAI (only one) since 1950 to 1985 has built 20 trains and 63 road vehicles (72 stations => 36 services) with yearly train income of ~$3,800,000 and road veh. income of ~$1,100,000 and bank balance of ~$22,300,000 (May 1985). Oh and of course with loan at $0. :mrgreen:
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha3 - trying to remake the old AI

Post by Brumi »

Thanks for that :)
Actually I already have some code for that, I'm working on money handling. I've written a banker.nut which has some more money handling functions. There is also a money check in the route building loop. I'll add support for the other three railtypes and then alpha4 will be release-ready.
Anyway, thank you again for your interest :)
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha3 - trying to remake the old AI

Post by SirkoZ »

You're very welcome.
Thank you for implementing such a nice and simple yet very enjoyable AI. :))
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha4 - trying to remake the old AI

Post by Brumi »

I've posted alpha4 in the main post, the changelog is also there.

It is a general improvement release, I must admit that I didn't work very much in the last few weeks. Now the fatal crash that Eliandor posted shouldn't occur again, the AI is capable of handling the other railtypes as well. Basic money handling includes the detection of inflation based on the current maximum loan amount and the 'original' maximum loan amount.

Code: Select all

function Banker::GetInflationRate()
{
	return (AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan"));
}
Tell me if this function is not correct. :)
The AI will still have a hard time getting started if you start it in the era of maglevs, but at least it shouldn't get into an infinite loop now.
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: SimpleAI alpha4 - trying to remake the old AI

Post by 1009 »

Good job on another release. I'll bug test it today and tomorrow, I hope you won't hear back from me :D.

Edit: welll... xD your AI was a bit ambitious. Is the behaviour building a route from Henington (top left) to Suston (bottom right) intended?
simpleAI-ambitiousRoute.png
(26.29 KiB) Downloaded 66 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha4 - trying to remake the old AI

Post by Brumi »

Eliandor wrote:Edit: welll... xD your AI was a bit ambitious. Is the behaviour building a route from Henington (top left) to Suston (bottom right) intended?
That'll surely have something to do with the changes to the subsidy system in trunk. Most likely the length of subsidies has been changed, and now there is no maximum distance check for subsidies in the AI beacause they tend to be very short in 0.7.2. I'll have to include that maximum distance check. Maninthebox has a similar issue in this thread.
Thank you for the report. :)
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha4 - trying to remake the old AI

Post by SirkoZ »

Another thing - I know that old AI didn't build all vehicles if it hadn't had the money, however it would be nice if SimpleAI would wait till it builds all the vehicles required per route before it gives up and/or starts building another service. With profitable routes it really makes a difference (pays to be patient). :-)
Vehicles per service as with old AI:
a) Short train service: 2 or 3 wagons (1 loco) - 1 train
b) Shorter train service: 4 or 5 wagons - 1 train
c) Longer dual train service 2 trains (4 or 5 wagons each)
(LORRY/BUS:)
d) Short passenger route (in town) - 2 busses
e) Long passenger route (between towns) - 4 busses
f) Short industry route - 3 lorries
g) Long industry route - 5 lorries
________________________________

Savegame for the next posting:
Ronfinghill Transport, 16th Nov 1980.sav
SimpleSave
(478.74 KiB) Downloaded 169 times
.
Last edited by SirkoZ on 16 Sep 2009 22:37, edited 1 time in total.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha4 - trying to remake the old AI

Post by SirkoZ »

A crash - don't ya know.
Looks like as if it crashed when it wanted to build a bridge and failed (both cases).
A savegame is in the previous post of mine due to 3 attachments limit.
Attachments
1st SimpleAI crashes take 1
1st SimpleAI crashes take 1
Ronfinghill Transport, 24th Dec 1969.png (51.77 KiB) Viewed 4395 times
1st SimpleAI crashes take 2
1st SimpleAI crashes take 2
Ronfinghill Transport, 12th Jan 1970.png (49.83 KiB) Viewed 4392 times
2nd SimpleAI crashes at the exact same place in builder and main.nut
2nd SimpleAI crashes at the exact same place in builder and main.nut
Ronfinghill Transport, 2nd Oct 1980.png (91.49 KiB) Viewed 4390 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha4.1 - trying to remake the old AI

Post by Brumi »

SirkoZ wrote:Looks like as if it crashed when it wanted to build a bridge and failed (both cases).
You're absolutely right. :) The problem was that I forgot to add 'AIError' before 'ERR_ALREADY_BUILT'. Then I realised that the check was useless, so I removed it. I posted alpha4.1 with this little fix. I wonder how you got this 2 times in one game, because this one is quite hard to reproduce manually, so that particular part of the code remained untested.
I didn't include the maximum distance check for subsidies, as it seems that it was a bug in trunk.

To the lorries, I have an intention to make the AI able to add vehicles later to a route. I'd like to add a configurable limit to the vehicles on one route, so the AI won't add more if the limit is reached. But that one will only come later.

Thank you for reporting. :)
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha4.1 - trying to remake the old AI

Post by SirkoZ »

Thank you for such a quick update/fix. :D

It wasn't really much effort to get those two crashes - I just ran a new game with 3 SimpleAI's and an AdmiralAI and then when I built a few simple services myself I just let it run with fast forward and looked from time to time what's going on.

I'm looking forward to further enhancements of this AI. :))
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SimpleAI alpha5 - trying to remake the old AI

Post by Brumi »

alpha5 has come, it is there in the main post.

The most visible change is that the AI now builds double railway lines. 8) You can see the other changes in the first post.
I'm planning to implement adding new road vehicles to a given route. My problem is that the effect of that new vehicle is seen much later, so I must prevent my AI from building a new vehicle on every loop. How do you do that in your AIs? I already have some ideas, I'm only interested how you do it.
With this release I'm getting closer to the first major release (which will be uploaded to Bananas as well), but I'd like to get done with save/load support and other management stuff by then.

Thank you for your interest! :D
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SimpleAI alpha5 - trying to remake the old AI

Post by Zuu »

I check the age of the youngest vehicle of all the vehicles of a given connection and then don't build new buses if the youngest one is too young. I'm not sure how I did it with selling of vehicles though. Might be a variable for that, but the problem is that I don't have a connection object or anything to store that information in.

I was thinking about using some ideas from automatic control theory to get a more systematic approach to it than just adding different threshold values to when to increase/decrease the capacities.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: SimpleAI alpha5 - trying to remake the old AI

Post by 1009 »

Awesome, congrats on another release.
I think there's a flaw in the logging. It says "I got the subsidy: PASS from (null: 0x00000000) to (null: 0x00000000)". It's a subsidy obtained by the use of Double Rail. The routes themselves have been built perfectly fine.

Suggestion: you only have two types of passing lanes in your library, right? One for North-South and one for East-West. You could try adding two more, for the same directions. If you're building passing lanes, check whether the station is more to the East of to the West, or to the North / the South (depending on the direction of the track), and flip the passing lane when applicable.
Mm complicated to explain. I'll add a screenshot of a situation where that would be a great thing to do in a second...

Edt: there we are. Since the destination is more to the north (or the east, idk.), you can flip the passing lane.
SimpleAI_passinglane_flip.png
SimpleAI_passinglane_flip.png (106.54 KiB) Viewed 998 times
Oh and also: you could consider adding even more passing lanes: for diagonal tracks as well :P but that's not really a big thing.

Another suggestion: let the number of passing lanes be dependent on the manhattan distance. At the moment it always builds two, that falls short for some routes.
Last edited by 1009 on 28 Sep 2009 04:53, edited 2 times in total.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI alpha5 - trying to remake the old AI

Post by SirkoZ »

Brumi wrote:alpha5 has come, it is there in the main post.

The most visible change is that the AI now builds double railway lines. 8) You can see the other changes in the first post.
I'm planning to implement adding new road vehicles to a given route. My problem is that the effect of that new vehicle is seen much later, so I must prevent my AI from building a new vehicle on every loop. How do you do that in your AIs? I already have some ideas, I'm only interested how you do it.
With this release I'm getting closer to the first major release (which will be uploaded to Bananas as well), but I'd like to get done with save/load support and other management stuff by then.

Thank you for your interest! :D
There goes the night. :lol:

J/K

Thanks so much for the addition. Preeshadydit. :))

EDIT: After some rigorous testing - all I can say is - simply beautiful! :]
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 35 guests