SimpleAI v14 - trying to remake the old AI
Moderator: OpenTTD Developers
Re: SimpleAI v4 - trying to remake the old AI
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.
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)
Junctioneer (a traffic intersection simulator)
Re: SimpleAI v4 - trying to remake the old AI
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
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.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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SimpleAI v5 - trying to remake the old AI
Version 5 is available on Bananas!
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!
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!
Re: SimpleAI v5 - trying to remake the old AI
What is the definition of non-english characters?
Everything not in ASCII? (7 bit or the extended 8 bit characterset?)
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)
Junctioneer (a traffic intersection simulator)
Re: SimpleAI v5 - trying to remake the old AI
Most probably it is the right definition
In my tests, characters like á, é, ő, all Cyrillic letters, etc. counted as two characters.
In my tests, characters like á, é, ő, all Cyrillic letters, etc. counted as two characters.
Re: SimpleAI v5 - trying to remake the old AI
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
-- Michael Lutz
Re: SimpleAI v5 - trying to remake the old AI
Thank you Brumi for another installment of your Simple-yet-beautiful-AI.
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Re: SimpleAI v5 - trying to remake the old AI
SimpleAI goes bankrupt for no reason. This is the last autosave before it happens.
- Attachments
-
- autosave5.sav
- (155.4 KiB) Downloaded 167 times
Re: SimpleAI v5 - trying to remake the old AI
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:
Thank you Samu for the report, now I'm one step closer to resolving a long-standing problem.
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.
Re: SimpleAI v5 - trying to remake the old AI
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!
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
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.
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
The problem was this, wasn't it?
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.
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
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.
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
I think so, yes.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.
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
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.
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
It can be avoided by building place to reverse.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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v5 - trying to remake the old AI
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...3iff wrote:That amended builder.nut works fine...except for one crash. Line 1009, a problem with DIR_NE not existing.
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
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).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...
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
Brumi - the algorithm for bankrupting a company is in a file named economy.cpp - for version r21266 of trunk - it is line 465:
.
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: 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.
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: 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.
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Who is online
Users browsing this forum: No registered users and 21 guests