Page 9 of 14

Re: SimpleAI v4 - trying to remake the old AI

Posted: 18 Sep 2010 20:23
by Zuu
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.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 20 Sep 2010 18:28
by Brumi
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.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 20 Sep 2010 21:50
by Zuu
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 02 Oct 2010 13:11
by Brumi
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

Re: SimpleAI v5 - trying to remake the old AI

Posted: 03 Oct 2010 17:59
by Zuu
What is the definition of non-english characters?

Everything not in ASCII? (7 bit or the extended 8 bit characterset?)

Re: SimpleAI v5 - trying to remake the old AI

Posted: 03 Oct 2010 18:09
by Brumi
Most probably it is the right definition :)
In my tests, characters like á, é, ő, all Cyrillic letters, etc. counted as two characters.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 04 Oct 2010 14:32
by Michi_cc
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

Re: SimpleAI v5 - trying to remake the old AI

Posted: 04 Oct 2010 21:00
by SirkoZ
Thank you Brumi for another installment of your Simple-yet-beautiful-AI. :mrgreen:

Re: SimpleAI v5 - trying to remake the old AI

Posted: 09 Nov 2010 22:22
by Samu
SimpleAI goes bankrupt for no reason. This is the last autosave before it happens.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 10 Nov 2010 10:08
by Brumi
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 3884 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

Re: SimpleAI v5 - trying to remake the old AI

Posted: 11 Nov 2010 00:02
by Michiel
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!

Re: SimpleAI v5 - trying to remake the old AI

Posted: 11 Nov 2010 11:01
by 3iff
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 11 Nov 2010 13:38
by Brumi
The problem was this, wasn't it?
Unnamed, 17th Jan 1950.png
Unnamed, 17th Jan 1950.png (21.84 KiB) Viewed 3829 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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 11 Nov 2010 14:14
by 3iff
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 11 Nov 2010 15:18
by Michiel
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 12 Nov 2010 08:14
by 3iff
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 12 Nov 2010 08:43
by Kogut
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 12 Nov 2010 17:30
by Brumi
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 15 Nov 2010 12:54
by 3iff
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.

Re: SimpleAI v5 - trying to remake the old AI

Posted: 20 Nov 2010 14:29
by SirkoZ
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 3673 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 3673 times