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

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4552
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SimpleAI v4 - trying to remake the old AI

Post by Zuu » 18 Sep 2010 20:23

I have not used Groups, but for vehicles (and stations) the uniqueness limitation is not for each company, but for all vehicles. So if company A has a vehicle "abc", then company B can't also have an "abc" named vehicle.

I would recommend looking into the OpenTTD source code for this. Running OpenTTD in a debugger with clever placed break points might also be useful.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: SimpleAI v4 - trying to remake the old AI

Post by Brumi » 20 Sep 2010 18:28

Well, I didn't think of it being a bug in the OpenTTD code, only my poor knowledge about Squirrel strings or something related. As far as I know other AIs do not have this problem. I'll try to find out what the cause is.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4552
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SimpleAI v4 - trying to remake the old AI

Post by Zuu » 20 Sep 2010 21:50

Brumi wrote:Well, I didn't think of it being a bug in the OpenTTD code, only my poor knowledge about Squirrel strings or something related. As far as I know other AIs do not have this problem. I'll try to find out what the cause is.
I didn't recommend the OpenTTD source code because I though it was a bug, but rather because it will give you the answer of exactly which conditions that a name has to fulfil. I can only extrapolate on the information I know from vehicle names and station names. The source code will give you The answer.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: SimpleAI v5 - trying to remake the old AI

Post by Brumi » 02 Oct 2010 13:11

Version 5 is available on Bananas! :D
There were no bug reports for the latest beta, so I decided to upload the latest version to Bananas (and the first post as well). I've also fixed the bug concerning the group names. The problem was that the maximum length of group names is 30, but non-English characters count twice, so calling slice(0, 30) is not always enough.
Now that the functionality of the old AI is basically done, I hope SimpleAI will be good enough for players who preferred the old AI :)
Thank you for your feedback! :D

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4552
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SimpleAI v5 - trying to remake the old AI

Post by Zuu » 03 Oct 2010 17:59

What is the definition of non-english characters?

Everything not in ASCII? (7 bit or the extended 8 bit characterset?)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: SimpleAI v5 - trying to remake the old AI

Post by Brumi » 03 Oct 2010 18:09

Most probably it is the right definition :)
In my tests, characters like á, é, ő, all Cyrillic letters, etc. counted as two characters.

Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 591
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: SimpleAI v5 - trying to remake the old AI

Post by Michi_cc » 04 Oct 2010 14:32

A character can even be longer, e.g. for Chinese. UTF-8 characters can be up to 6 bytes long. (Code points actually, of which one or more form the actual character. So a character could be even longer, but OpenTTD only really knows about code points IIRC.)

-- Michael Lutz

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1501
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v5 - trying to remake the old AI

Post by SirkoZ » 04 Oct 2010 21:00

Thank you Brumi for another installment of your Simple-yet-beautiful-AI. :mrgreen:

Samu
Traffic Manager
Traffic Manager
Posts: 236
Joined: 17 Apr 2007 14:28

Re: SimpleAI v5 - trying to remake the old AI

Post by Samu » 09 Nov 2010 22:22

SimpleAI goes bankrupt for no reason. This is the last autosave before it happens.
Attachments
autosave5.sav
(155.4 KiB) Downloaded 100 times

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

Re: SimpleAI v5 - trying to remake the old AI

Post by Brumi » 10 Nov 2010 10:08

Curious... It looks like I don't know something about the bankruptcy process. SimpleAI gets the warning at the start of October 2012, and then goes bankrupt by April 2013. I took a screenshot of its finances on the last day before it went bankrupt:
Unnamed, 31st Mar 2013.png
Unnamed, 31st Mar 2013.png (10.36 KiB) Viewed 3860 times
The company is doing well, but it seems that the loan payments at the start of the month make it go into negative for a while, just before the bankruptcy check. I should make it a bit tighter with its budget. Where do I find the precise algorithm for bankruptcy?

Thank you Samu for the report, now I'm one step closer to resolving a long-standing problem. :D

User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 13 Jul 2008 00:57
Contact:

Re: SimpleAI v5 - trying to remake the old AI

Post by Michiel » 11 Nov 2010 00:02

I think it's three strikes and you're out: even if you have millions in the bank or in available loans, if you're in the red three times in a row when it checks (first day of each quarter?) you're dead. It also makes you pay maintenance before it checks, so if you're good at spending all your money, it's quite likely to happen. In your case, I think it was negative in October, Januari and then April.

What I've done with ChooChoo is to leave some money unloaned (enough for 3 months of maintenance), do your building/buying/etc., then when you run out of money, max out the loan so you can pay maintenance while keeping a positive bank balance, and wait until you have enough to resume - after stashing some away again by paying back some of your loan first, so you can't accidentally spend it!

User avatar
3iff
Tycoon
Tycoon
Posts: 982
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v5 - trying to remake the old AI

Post by 3iff » 11 Nov 2010 11:01

Brumi,

I'm trying to make a change or two to your scripts...purely for personal use...

I've converted road stations into drive through stations, but sometimes the road building phase misses the station/depot block bu half a tile. This leaves vehicles looping around in their block unable to drive the route. There's also some road and a depot left standing if the AI decides to scrap the station.
I can provide screenshots if required.

At the moment, I can't quite fathom out the roadbuilding part of the script. It seems that it starts and ends at the wrong places, possibly because it thinks the rear of the station is actually the front (or maybe not). Occasionally too it adds a half section of road past the drive through.

Just wondering if you (or anyone) can point me in the right direction?


Actually, just discovered there's a line of code that checks that a road connection exists from the tile infront of each station... and it behaves differently for drive throughs anyway. So, I've modified it to check that a road connection exists from the station tile of source and destination...and it appears to work. The AI can now also buy articulated vehicles...

Maybe this code can be incorporated in a later version...if wanted.

Great little AI that does just what I want.

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

Re: SimpleAI v5 - trying to remake the old AI

Post by Brumi » 11 Nov 2010 13:38

The problem was this, wasn't it?
Unnamed, 17th Jan 1950.png
Unnamed, 17th Jan 1950.png (21.84 KiB) Viewed 3805 times
You're right, AIRoad::GetRoadStationFrontTile isn't good here, as it may return the other end of the station as the front tile. So I wrote my own cBuilder::GetRoadStationFrontTile, and it is called by the AI instead of the one in AIRoad. It's not the nicest solution, as it searches for a depot pointing in the right direction next to the station. Also I commented out two lines which excluded the use of articulated vehicles. So here's the modified builder.nut, it should work, but I haven't tested it thoroughly.
builder.nut
(35.32 KiB) Downloaded 110 times
And about the bankruptcy: the monthly loan payment is the amount of the loan times the given percentage in the difficulty settings? It should be quite easy to increase the minimum cash on hand by this value.

User avatar
3iff
Tycoon
Tycoon
Posts: 982
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v5 - trying to remake the old AI

Post by 3iff » 11 Nov 2010 14:14

Brumi,

Thanks for that. I'll give it a try. I'm able to understand a bit of code but I'm sometimes not sure if a command is a default one or a custom built one.

Thanks.

User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 13 Jul 2008 00:57
Contact:

Re: SimpleAI v5 - trying to remake the old AI

Post by Michiel » 11 Nov 2010 15:18

Brumi wrote:And about the bankruptcy: the monthly loan payment is the amount of the loan times the given percentage in the difficulty settings? It should be quite easy to increase the minimum cash on hand by this value.
I think so, yes.
Keep in mind the station maintenance as well. I don't think you can find the value anywhere in game, but it seems to be hardcoded so I've just declared a constant for it.

User avatar
3iff
Tycoon
Tycoon
Posts: 982
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v5 - trying to remake the old AI

Post by 3iff » 12 Nov 2010 08:14

Brumi,

That amended builder.nut works fine...except for one crash. Line 1009, a problem with DIR_NE not existing. The AI was trying to remove an unwanted station/depot. Unfortunately I don't have any more details but I'll try to get info on it.

Discovered a serious drawback of drive throughs though. Stations built later often stack up, causing a truck driving (say) south into a truck stop having to exit south and getting entangled in another truck stop from another company. This can lead to horrible traffic snarl-ups or vehicles driving miles to find a turn-round point. Nothing that can be done to avoid this but that's a hazard of drive throughs rather than your code.

Thanks for your assistance.

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SimpleAI v5 - trying to remake the old AI

Post by Kogut » 12 Nov 2010 08:43

3iff wrote:Discovered a serious drawback of drive throughs though. Stations built later often stack up, causing a truck driving (say) south into a truck stop having to exit south and getting entangled in another truck stop from another company. This can lead to horrible traffic snarl-ups or vehicles driving miles to find a turn-round point. Nothing that can be done to avoid this but that's a hazard of drive throughs rather than your code.
It can be avoided by building place to reverse.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

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

Re: SimpleAI v5 - trying to remake the old AI

Post by Brumi » 12 Nov 2010 17:30

3iff wrote:That amended builder.nut works fine...except for one crash. Line 1009, a problem with DIR_NE not existing.
DIR_NE not existing? That is a constant defined in the cBuilder class, along with DIR_NW, DIR_SE and DIR_SW. I wonder what was the problem there...
And certainly, to use drive-through stations properly a station pattern like in AIAI would be good. But that would need quite a lot of modification in the existing code (although not impossible), at least you would have to change things at least in BuildRoadStation, CanBuildRoadStation and DeleteRoadStation.

User avatar
3iff
Tycoon
Tycoon
Posts: 982
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v5 - trying to remake the old AI

Post by 3iff » 15 Nov 2010 12:54

Brumi wrote:DIR_NE not existing? That is a constant defined in the cBuilder class, along with DIR_NW, DIR_SE and DIR_SW. I wonder what was the problem there...
I thought that odd too. I suspect it was trying to find a station/depot (?) to delete and couldn't find it. Possibly some problem with the drive through being perceived as reversed (I'm guessing here).

As drive throughs are not at all working properly, especially with them chaining when multiple AIs build them, I've abandoned the idea and returned to the normal version of simpleAI.

I have had a couple of instances where a train station 'disappears' after being taken over by me but I have no data. I suddenly find a train has a void order. It may be an error on my part. If I find anything I'll pass on the details.

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1501
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v5 - trying to remake the old AI

Post by SirkoZ » 20 Nov 2010 14:29

Brumi - the algorithm for bankrupting a company is in a file named economy.cpp - for version r21266 of trunk - it is line 465:

Code: Select all

/**
 * Check for bankruptcy of a company. Called every three months.
 * @param c Company to check.
 */
static void CompanyCheckBankrupt(Company *c)
.

Plus I've got another idea; if path-signals are selected for railway it would be beneficial for lorry drivers to build one on each end of single-rail station assembly such as this:
Whittown Transport, 10th Feb 1950.png
better
Whittown Transport, 10th Feb 1950.png (33.66 KiB) Viewed 3649 times
or going a bit further and placing two two-way path a few squares before and after each road crossing - the ultimate road traveler protection. :-)
Abercombe Rivers Transport, 29th Jan 1950.png
the best
Abercombe Rivers Transport, 29th Jan 1950.png (21.14 KiB) Viewed 3649 times

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests