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
3iff
Tycoon
Tycoon
Posts: 983
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

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

Post by 3iff » 11 Jan 2013 10:32

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.

bokkie
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 19 Jan 2007 19:26

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

Post by bokkie » 12 Jan 2013 17:33

It also builds the logic train in my game, after which it can't attach wagons. (I guess, first time playing with NUTS).

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

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

Post by Brumi » 13 Jan 2013 00:07

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.

bokkie
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 19 Jan 2007 19:26

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

Post by bokkie » 13 Jan 2013 08:31

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 150 times

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

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

Post by Brumi » 13 Jan 2013 14:28

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 :)

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

Re: SimpleAI v7 - trying to remake the old AI

Post by Brumi » 19 Jan 2013 15:05

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.

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

Re: SimpleAI v8 - trying to remake the old AI

Post by Brumi » 03 Feb 2013 19:13

Triple posting to inform you that there is a new version out. It (hopefully) contains a bugfix for the problem described in this thread.

User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13188
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: SimpleAI v8 - trying to remake the old AI

Post by Hyronymus » 04 Feb 2013 21:11

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.

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

Re: SimpleAI v8 - trying to remake the old AI

Post by Brumi » 04 Feb 2013 22:18

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: )

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

Re: SimpleAI v8 - trying to remake the old AI

Post by Kogut » 17 Jul 2013 16:09

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

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

Re: SimpleAI v8 - trying to remake the old AI

Post by 3iff » 18 Jul 2013 07:58

You can change a setting to allow the AI to use more trucks. I generally have 25 road vehicles per route.

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

Re: SimpleAI v8 - trying to remake the old AI

Post by krinn » 20 Jul 2013 11:49

Hi brumi,

i got a div by zero in valuator with v8
Attachments
sv8.png
(26.33 KiB) Downloaded 4 times

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

Re: SimpleAI v8 - trying to remake the old AI

Post by Brumi » 20 Jul 2013 14:33

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?

Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: SimpleAI v8 - trying to remake the old AI

Post by Steffl » 20 Jul 2013 17:38

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));
Last edited by Steffl on 20 Jul 2013 17:53, edited 2 times in total.

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

Re: SimpleAI v8 - trying to remake the old AI

Post by krinn » 20 Jul 2013 17:42

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 ;)

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

Re: SimpleAI v9 - trying to remake the old AI

Post by Brumi » 21 Jul 2013 15:50

Thank you for the ideas, now there is a new version available with the proposed fix by Steffl :)

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

Re: SimpleAI v9 - trying to remake the old AI

Post by SirkoZ » 12 Jan 2015 22:32

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:

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

Re: SimpleAI v9 - trying to remake the old AI

Post by krinn » 13 Jan 2015 09:52

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.

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

Re: SimpleAI v9 - trying to remake the old AI

Post by Brumi » 13 Jan 2015 11:46

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.


Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests