SimpleAI v14 - trying to remake the old AI
Moderator: OpenTTD Developers
Re: SimpleAI v7 beta4 - trying to remake the old AI
I have just tried the NUTS trainset and was disappointed (but not surprised) that this AI couldn't handle it. I'll give this a try.
The PASS/MAIL wagons in NUTS are tricky for me to handle as I usually have 1 mail wagon on a passenger train and it's awkward to get one built easily.
The PASS/MAIL wagons in NUTS are tricky for me to handle as I usually have 1 mail wagon on a passenger train and it's awkward to get one built easily.
Re: SimpleAI v7 beta4 - trying to remake the old AI
It also builds the logic train in my game, after which it can't attach wagons. (I guess, first time playing with NUTS).
Re: SimpleAI v7 beta4 - trying to remake the old AI
The logic train should immediately get blacklisted because it's not compatibile with any wagon. The AI usually builds one at the start of the game, but never anymore as it gets blacklisted.
Are you sure that you are using v7-beta4? It's not on Bananas yet, it's only available in the first post. A savegame or simply some instructions to reproduce would be useful.
Are you sure that you are using v7-beta4? It's not on Bananas yet, it's only available in the first post. A savegame or simply some instructions to reproduce would be useful.
Re: SimpleAI v7 beta4 - trying to remake the old AI
Sorry I wasn't more complete It's on Hard Game Pack 0.7 (viewtopic.php?f=33&t=49359) with 'latest' SimpleAI as of Bananas. That seems to be v6.
- Attachments
-
- Nedtown Transport, 28 Aug 1957.sav
- (112.98 KiB) Downloaded 290 times
Re: SimpleAI v7 beta4 - trying to remake the old AI
The current Bananas version doesn't support NUTS, which also means that it will try to use the logic train as well. Try the beta version for NUTS compatibility
Re: SimpleAI v7 - trying to remake the old AI
After the longest beta phase of SimpleAI so far, I think version 7 is ready for release. It's available in the first post and on Bananas.
Because Bananas doesn't support having Road Pathfinder v3 as a dependency, the AI now uses Road Pathfinder v4 and AyStar v6.
Because Bananas doesn't support having Road Pathfinder v3 as a dependency, the AI now uses Road Pathfinder v4 and AyStar v6.
Re: SimpleAI v8 - trying to remake the old AI
Triple posting to inform you that there is a new version out. It (hopefully) contains a bugfix for the problem described in this thread.
Re: SimpleAI v8 - trying to remake the old AI
Brumi I'm using v7 of your AI and I noticed a peculiar thing when assessing available vehicles. I made an early start in 1800 and with eGRVTS 2.0 it is possible to buy road vehicles right from that date. Your AI seems to think differently though:
Also, eGRVTS 2.0 is fully supporting FIRS.
Re: SimpleAI v8 - trying to remake the old AI
That's because all road vehicles are articulated at that date. The AI doesn't use articulated vehicles because it uses terminus style stations (being a remake of the old AI after all )
Re: SimpleAI v8 - trying to remake the old AI
I know that it is intentional, but it quite sad to see 300+ tonnes of cargo that slowly disappears from station and AI refusing to use more than 5 trucks.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v8 - trying to remake the old AI
You can change a setting to allow the AI to use more trucks. I generally have 25 road vehicles per route.
Re: SimpleAI v8 - trying to remake the old AI
Hi brumi,
i got a div by zero in valuator with v8
i got a div by zero in valuator with v8
- Attachments
-
- sv8.png (26.33 KiB) Viewed 2628 times
Re: SimpleAI v8 - trying to remake the old AI
Oops...
Thanks for the report, I will look into it.
EDIT:
Okay, this error is weird. The line on which the division by zero happened:
So Banker.GetInflationRate must have returned zero.
Banker::GetInflationRate is:
I still wonder how this could possibly return zero... Did you change the maximum loan beforehand? Was inflation on in your game? And if yes, what year was it?
Thanks for the report, I will look into it.
EDIT:
Okay, this error is weird. The line on which the division by zero happened:
Code: Select all
local runningcost_limit = 6000 / Banker.GetInflationRate() * 100;
Banker::GetInflationRate is:
Code: Select all
function Banker::GetInflationRate()
{
return (100 * AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan"));
}
Re: SimpleAI v8 - trying to remake the old AI
Hi Brumi,
the numbers in your formula can get very big, maybe they are too high and overflow. Just a guess, but I thought I should write it.
Asuming the max. size of a variable in squirrel is not bigger than 2 ³² (2.147.483.648).
Then the first part of your calculation (100 * AICompany.GetMaxLoanAmount()) can get too big, and overflows before doing the divide calculation.
I loaded a game with over 110 years of playtime and the loan amount was 14.000.000 there. It needed ca.21.500.000 to overflow, so you have to play long but maybe it's possible to reach this.
Fix would be easy
the numbers in your formula can get very big, maybe they are too high and overflow. Just a guess, but I thought I should write it.
return (100 * AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan"));
Asuming the max. size of a variable in squirrel is not bigger than 2 ³² (2.147.483.648).
Then the first part of your calculation (100 * AICompany.GetMaxLoanAmount()) can get too big, and overflows before doing the divide calculation.
I loaded a game with over 110 years of playtime and the loan amount was 14.000.000 there. It needed ca.21.500.000 to overflow, so you have to play long but maybe it's possible to reach this.
Fix would be easy
return (AICompany.GetMaxLoanAmount() / (AIGameSettings.GetValue("difficulty.max_loan")/100));
Last edited by Steffl on 20 Jul 2013 17:53, edited 2 times in total.
Re: SimpleAI v8 - trying to remake the old AI
I have look at it too, year was like 2080 or so (the game was running alone as a test bed). inflation on, maximum loan wasn't change.
I think it overflow, i will check it later as i'm using this one too
I think it overflow, i will check it later as i'm using this one too
Re: SimpleAI v9 - trying to remake the old AI
Thank you for the ideas, now there is a new version available with the proposed fix by Steffl
Re: SimpleAI v9 - trying to remake the old AI
Brumi - another problem with the version 9 is selection of railway locomotive when inflation is at its highest (4% interest).
In railbuilder.nut lines 1286 and 1287 look like this:
But that means that once inflation_rate reaches 6000% (which is quite soon),
the whole runningcost_limit becomes zero. So rather than dividing 6000 by inflation_rate,
let's turn the second line (= runningcost) into its non-inflated state, so it is immune to inflation.
This way your complex formulas for choosing the optimal engine work as intended even in most inflated scenarios.
Anyhow - I only got to this now because when version 5 was out I made my slightly modified version of it, named StupidAI
and I was happy with it till now - sometimes there are AI loading issues regarding "null".
So I decided to make "StupidAI-9" and with it also to rectify the engine choice issue.
S/Z
In railbuilder.nut lines 1286 and 1287 look like this:
Code: Select all
local runningcost_limit = 6000 / Banker.GetInflationRate() * 100;
local runningcost = AIEngine.GetRunningCost(engine).tofloat();
the whole runningcost_limit becomes zero. So rather than dividing 6000 by inflation_rate,
let's turn the second line (= runningcost) into its non-inflated state, so it is immune to inflation.
Code: Select all
local runningcost_limit = 6000;
local runningcost = AIEngine.GetRunningCost(engine).tofloat() / Banker.GetInflationRate() * 100;
Anyhow - I only got to this now because when version 5 was out I made my slightly modified version of it, named StupidAI
and I was happy with it till now - sometimes there are AI loading issues regarding "null".
So I decided to make "StupidAI-9" and with it also to rectify the engine choice issue.
S/Z
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 v9 - trying to remake the old AI
I think the real problem is because of the use of integer.
One way you overflow, the overway, when the value goes below 1, the integer roundup gave you 0 (that of course use in / will cause problem)
To ease calcs and prevent this GetInflationRate should be set as (it will return value of 1.00 for basecost, 1.1 when inflation reach 10%...):
This will fix as well:
or
Will gave equal result.
It mean a lot of code review to handle the change, and some tointeger() typecast might be need.
One way you overflow, the overway, when the value goes below 1, the integer roundup gave you 0 (that of course use in / will cause problem)
To ease calcs and prevent this GetInflationRate should be set as (it will return value of 1.00 for basecost, 1.1 when inflation reach 10%...):
Code: Select all
return (AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan").tofloat());
Code: Select all
local runningcost_limit = 6000 * Banker.GetInflationRate();
local runningcost = AIEngine.GetRunningCost(engine); // don't think it's even need to typecast it to float now that GetInflationRate return itself a float
Code: Select all
local runningcost_limit = 6000;
local runningcost = AIEngine.GetRunningCost(engine) / Banker.GetInflationRate();
It mean a lot of code review to handle the change, and some tointeger() typecast might be need.
Re: SimpleAI v9 - trying to remake the old AI
Yes, using integers is definitely the problem here. Surely I didn't know how Squirrel handled integers and floats when this piece of code was written
The most simple solution is to make GetInflationRate() return a float, like krinn advised.
The most simple solution is to make GetInflationRate() return a float, like krinn advised.
Re: SimpleAI v9 - trying to remake the old AI
Well I don't care. I got it fixed.
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 5 guests