Page 12 of 14

Re: SimpleAI v7 beta4 - trying to remake the old AI

Posted: 11 Jan 2013 10:32
by 3iff
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.

Re: SimpleAI v7 beta4 - trying to remake the old AI

Posted: 12 Jan 2013 17:33
by bokkie
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

Posted: 13 Jan 2013 00:07
by Brumi
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.

Re: SimpleAI v7 beta4 - trying to remake the old AI

Posted: 13 Jan 2013 08:31
by bokkie
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.

Re: SimpleAI v7 beta4 - trying to remake the old AI

Posted: 13 Jan 2013 14:28
by Brumi
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

Posted: 19 Jan 2013 15:05
by Brumi
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.

Re: SimpleAI v8 - trying to remake the old AI

Posted: 03 Feb 2013 19:13
by Brumi
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

Posted: 04 Feb 2013 21:11
by Hyronymus
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:
Nederlandsch Vervoersbedrijf, 23 Dec 1837.png
(424.87 KiB) Downloaded 7 times
Also, eGRVTS 2.0 is fully supporting FIRS.

Re: SimpleAI v8 - trying to remake the old AI

Posted: 04 Feb 2013 22:18
by Brumi
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 :wink: )

Re: SimpleAI v8 - trying to remake the old AI

Posted: 17 Jul 2013 16:09
by Kogut
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.

Re: SimpleAI v8 - trying to remake the old AI

Posted: 18 Jul 2013 07:58
by 3iff
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

Posted: 20 Jul 2013 11:49
by krinn
Hi brumi,

i got a div by zero in valuator with v8

Re: SimpleAI v8 - trying to remake the old AI

Posted: 20 Jul 2013 14:33
by Brumi
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:

Code: Select all

local runningcost_limit = 6000 / Banker.GetInflationRate() * 100;
So Banker.GetInflationRate must have returned zero.

Banker::GetInflationRate is:

Code: Select all

function Banker::GetInflationRate()
{
	return (100 * AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan"));
}
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?

Re: SimpleAI v8 - trying to remake the old AI

Posted: 20 Jul 2013 17:38
by Steffl
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.
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));

Re: SimpleAI v8 - trying to remake the old AI

Posted: 20 Jul 2013 17:42
by krinn
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 ;)

Re: SimpleAI v9 - trying to remake the old AI

Posted: 21 Jul 2013 15:50
by Brumi
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

Posted: 12 Jan 2015 22:32
by SirkoZ
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:

Code: Select all

local runningcost_limit = 6000 / Banker.GetInflationRate() * 100;
	local runningcost = AIEngine.GetRunningCost(engine).tofloat();
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.

Code: Select all

local runningcost_limit = 6000;
	local runningcost = AIEngine.GetRunningCost(engine).tofloat() / Banker.GetInflationRate() * 100;
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 :mrgreen:

Re: SimpleAI v9 - trying to remake the old AI

Posted: 13 Jan 2015 09:52
by krinn
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%...):

Code: Select all

return (AICompany.GetMaxLoanAmount() / AIGameSettings.GetValue("difficulty.max_loan").tofloat());
This will fix as well:

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
or

Code: Select all

local runningcost_limit = 6000;
   local runningcost = AIEngine.GetRunningCost(engine) / Banker.GetInflationRate();
Will gave equal result.

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

Posted: 13 Jan 2015 11:46
by Brumi
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.

Re: SimpleAI v9 - trying to remake the old AI

Posted: 16 Jan 2015 09:49
by SirkoZ
Well I don't care. I got it fixed. :]