Page 13 of 15

Re: AIAI

Posted: 17 Jul 2013 16:23
by Kogut
This one seems to be case of "unexpectedly invalid vehicle_id, right after passing IsValidVehicle check" - result of using autorenew and autoreplace (http://www.tt-forums.net/viewtopic.php?f=65&t=66959). I need to write my own replacements and it should fix this type of bug.

Re: AIAI

Posted: 18 Jul 2013 12:07
by MagicBuzz
Hello Kogut,

I found a small "bug".

It's not a real bug, at it doesn't change the AI behaviour not it's performances, but it changes the nice looking of the roads.
And in some situations, it should result in a routing probleme for drive vehicles.

Normally, your AI will create truck station using a pass-througt station on a roundabout road layout :
station_ok.png
station_ok.png (27.7 KiB) Viewed 16079 times
But in my case, the AI built this :
station_ko.png
station_ko.png (17.62 KiB) Viewed 16079 times
It will work, but the bridge changes the road layout, so the pass-throught station isn't pass-throught anymore.

Bad looking, but not a real problem for the route, as the trucks still can find a way.

Re: AIAI

Posted: 18 Jul 2013 13:35
by Kogut
This is not a bug (it works as intended) but better looking for a place is a good idea and I created ticket for this feature request (https://github.com/Bulwersator/AIAI/issues/38). Note that it may wait quite a long time, some of my ideas are waiting entire years for a coding time.

Re: AIAI

Posted: 18 Jul 2013 18:49
by MagicBuzz
Kogut wrote:Note that it may wait quite a long time, some of my ideas are waiting entire years for a coding time.
It's not a problem : as you said, it's not a bug, the AI just works fine with this issue, nothing is hasting (hastening ? hmmm "presser" in french :D).

Re: AIAI

Posted: 18 Jul 2013 19:35
by Steffl
Hi Kogut :-)

I think I can help you with this:
Kogut wrote:
Wormnest wrote:AIAI v 89 crashes with Count does not exist.
Thanks for report - I thought that it is fixed. Can you post savegame? I have no idea what happens here, it seems to be case of weird NewGrf or my misinterpretation of API documentation. And with savegame I may check what is happening with industry number 2065.

I could reproduce the bug today:
AIAIv94, OpenTTD 1.3.1
AIAICountBug.png
AIAICountBug.png (43.75 KiB) Viewed 4307 times
And it's as you maybe expected, an industry just had closed when the AI(AI) wanted to get information about it.

Here's the code snippet of crashing function:

Code: Select all

function Builder::ValuateConsumer(industry_id, cargo, score)
{
//check: Industry still valid
	if(!AIIndustry.IsValidIndustry(industry_id)) {
		return -1;
	}
//some code...
	local industry_name = AIIndustry.GetName(industry_id);
	if(AIIndustry.GetStockpiledCargo(industry_id, cargo)==0) {
		score *= 2;
	}
	if(IsConnectedIndustry(industry_id, cargo)) {
		score *= 7;
	}
//industry invalid, industry_type_id=64 (invalid?)
	local industry_type_id = AIIndustry.GetIndustryType(industry_id);
//industry_type_name= NULL
	local industry_type_name = AIIndustryType.GetName(industry_type_id);
//list=NULL, NULL.Count()=Crash
	local list = AIIndustryType.GetProducedCargo(industry_type_id);
//CRASH!!! 	if(list.Count() == 0) {
		score /= 2;
	}
	return score;
}
Maybe it would be better to just get a empty list then NULL. But in the NOAI documentation is written, that the industry type you want to get the list of has to be valid. I don't know if there are similar cases where the behavior is the same.

A save before the crash happens is attached.

Bye, good luck with your AI.

Re: AIAI

Posted: 18 Jul 2013 19:59
by Kogut
Thanks! Lesson from this: solving potential racial condition by "it is so unlikely that it can not happen" is a poor idea. At least my debug variables worked properly and allowed to debug this problem.

Re: AIAI

Posted: 19 Jul 2013 09:03
by Kogut
Version iota95 with bugfixes provided by Steffl and mart3p is now available through BaNaNaS.

Re: AIAI

Posted: 20 Jul 2013 20:37
by mart3p
Hi Kogut,

Why has AIAI built all these "a" signs? :? I see they also appear in MagicBuzz's screenshot above.

AIAI iota95, OpenTTD 1.3.2-RC2, FIRS 1.2.0
I have a savegame if needed.
AIAI signs.png
AIAI signs.png (63.63 KiB) Viewed 15955 times
And I just noticed the AI debug window shows v94 but it's definitely v95 as I just downloaded it and then started a new game.

Re: AIAI

Posted: 21 Jul 2013 08:27
by Kogut
Short answer: it is a bug that should not appear in version 95 (please report any signs like this appearing - this AI is not supposed to use signs beyond bug report info above HQ without explicit request in settings).

Long answer: There is a library called SuperLib that contains functions usable by any AI. One may be used to delete all signs placed by a company on a selected tile and place there a new sign (to avoid situation with 1000+ signs on screen what is causing a serious lag in OpenTTD). This function is used both directly by AIAI and as debug by some other SuperLib functions. Here it was used by function looking for a place to construct road depot, near selected tile.

In older versions there was a setting in AIAI, disabled by default, hidden without enabling hidden OpenTTD setting. Enabling it allowed all kinds of debug signs to appear. I recently attempted to fully disable SuperLib debug signs and allow AIAI to use this sign function but I made mistake and I failed to block debug signs from SuperLib.

Change ( https://github.com/Bulwersator/AIAI/com ... f2c96bb2d6 ) included in iota95 should do it properly.

EDIT:
And I just noticed the AI debug window shows v94 but it's definitely v95 as I just downloaded it and then started a new game.
No idea. Maybe try to restart OpenTTD? I just tried on clean OpenTTD install (both trunk and stable) and it downloaded, used and displayed v95.

Re: AIAI

Posted: 21 Jul 2013 09:02
by mart3p
Thanks for your answer.

Having now reloaded the savegame it is showing v95 of AIAI. So for some reason, the new version I downloaded via the ingame content downloader wasn't used when I started a new game immediately afterwards.

Re: AIAI

Posted: 21 Jul 2013 09:15
by Kogut
mart3p wrote: for some reason
It may be a bug in OpenTTD. I tried to reproduce it but failed. Is it possible that you run "check online content" from started game?

Re: AIAI

Posted: 21 Jul 2013 09:52
by mart3p
Kogut wrote:Is it possible that you run "check online content" from started game?
No, I used "check online content" from the AI configuration window, which I opened from "AI/game script settings" from the start screen. I did already have AIAI selected in the AI configuration window.

I will check what happens more carefully next time there is an update. :wink:

Re: AIAI

Posted: 15 Dec 2013 13:20
by Volare013
I made a screen shot of the AI interface;
ttd1.png
(1.2 MiB) Downloaded 8 times
Thanks

Re: AIAI

Posted: 15 Dec 2013 14:33
by Kogut
It seems that problems was caused by combination of weird settings and lack of proper error reporting. Second one is fixed in https://github.com/Bulwersator/AIAI/com ... bf3b2c24a8 and will be included in next version.

Thanks for the report!

In attachment: how error reporting works in dev version.

Re: AIAI

Posted: 01 Feb 2014 16:17
by tohjo
Hello, I was advised to post this error message here.

Dunno if it's of any help, but just moments before, I got the in-game announcement that one of the companies was going bankcrupt.

Re: AIAI

Posted: 05 Feb 2014 11:32
by Kogut
Thanks for bug report! You are using old version of AIAI, I would advise to update OpenTTD (current stable is 1.3.3) and AIAI. It is likely that this bug was fixed in rewrite of relevant part of code.

As there was no page about updating on OpenTTD wiki I just created one at http://wiki.openttd.org/Updating (corrections, improvements and fixes are welcomed).

Re: AIAI

Posted: 08 Mar 2014 17:43
by HGus
hi kogut...

I found this bug long time ago in version iota 14, but forgot to post it here. I recently came back and found the same in version 95

At railbuilder.nut, lines 593-596 (was 475-478 in v14), there is...

Code: Select all

	//multiplier: for weak locos it may be possible to merge multiple trains ito one (2*loco + 10*wagon, instead of loco+5 wagons)
	//multiplier = how many trains are merged into one
	local multiplier = min(GetAvailableMoney()/costs.GetCosts(), route.station_size*16/AIVehicle.GetLength(engineId))
	multiplier--; //one part of train is already constructed
	for (local x=0; x<multiplier; x++) {
(note the lack of ; at end of line 595)

But it can trig an error when multiplier is not integer because with x being between 0 and 1 makes the for loop enter once, trying to build a multiple train longer than allowed by user setting also crash the AI (you do the checking for a single train, but forgot for multiple).

Here my suggested change:

Code: Select all

 	local multiplier = min(GetAvailableMoney()/costs.GetCosts(), route.station_size*16/AIVehicle.GetLength(engineId));
// Patch: Trains should not be longer than max_train_length setting, also check than multiplier is integer
	multiplier = multiplier.tointeger();
	while (multiplier>AIGameSettings.GetValue("max_train_length")*16/AIVehicle.GetLength(engineId))
		multiplier--;
// End of Patch
	multiplier--; //one part of train is already constructed
Regards.

Re: AIAI

Posted: 03 Apr 2014 17:05
by HGus
Hi, here another bug related to trains, AIAI was doing pretty well for about 30 years in the road/ship era, but when first train became available in 1831, it failed to build proper rail vehicles (infrastructure was right, two good connected stations with depots in right place) I was using UKRS2 train grf. You will see in the screenshot that AIAI build successfully a first train and failed at the second. The first one has six (!) engines, the second only one, with a single wagon. As the message says, both are valid consists (but rares, maybe the script tried to build one train and was splitted cause of bad calculation, settings were at 4 tiles long) BTW, I was using original v95, not my patched one (see my earlier post)

Re: AIAI

Posted: 04 Apr 2014 01:11
by beeurd
I think the Planet locomotive is quite bad at climbing hills in certain situations so that could be why it added so many engines. No idea for the other problems though!

Re: AIAI

Posted: 05 Apr 2014 00:05
by HGus
Almost flat map. (seed 643564035)

Two stations at same level, no slopes at all in the line. The first engine from UKRS2 is very weak, but it still can pull a full 4-tiles passenger consist by flat terrain. Those trains are freighters, anyway, but if a multiheaded single train was intended, the code could fail to calculate the correct length, and the game created two when the orders went beyond the limit. Maybe the checking routines triggered the error. But that still to be fixed...