AIAI

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

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

Re: AIAI

Post by Kogut » 17 Jul 2013 16:23

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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1158
Joined: 15 Feb 2003 17:32
Location: Paris, France
Contact:

Re: AIAI

Post by MagicBuzz » 18 Jul 2013 12:07

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 5320 times
But in my case, the AI built this :
station_ko.png
station_ko.png (17.62 KiB) Viewed 5320 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.

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

Re: AIAI

Post by Kogut » 18 Jul 2013 13:35

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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1158
Joined: 15 Feb 2003 17:32
Location: Paris, France
Contact:

Re: AIAI

Post by MagicBuzz » 18 Jul 2013 18:49

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

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

Re: AIAI

Post by Steffl » 18 Jul 2013 19:35

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
(43.75 KiB) Downloaded 8 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.
Attachments
CountBug.sav
almost forgot the save
(690.59 KiB) Downloaded 111 times

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

Re: AIAI

Post by Kogut » 18 Jul 2013 19:59

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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

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

Re: AIAI

Post by Kogut » 19 Jul 2013 09:03

Version iota95 with bugfixes provided by Steffl and mart3p is now available through BaNaNaS.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
mart3p
Tycoon
Tycoon
Posts: 1032
Joined: 31 Oct 2005 21:00
Location: UK

Re: AIAI

Post by mart3p » 20 Jul 2013 20:37

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 5196 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.
Image

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

Re: AIAI

Post by Kogut » 21 Jul 2013 08:27

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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
mart3p
Tycoon
Tycoon
Posts: 1032
Joined: 31 Oct 2005 21:00
Location: UK

Re: AIAI

Post by mart3p » 21 Jul 2013 09:02

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.
Image

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

Re: AIAI

Post by Kogut » 21 Jul 2013 09:15

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?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
mart3p
Tycoon
Tycoon
Posts: 1032
Joined: 31 Oct 2005 21:00
Location: UK

Re: AIAI

Post by mart3p » 21 Jul 2013 09:52

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

Volare013
Engineer
Engineer
Posts: 6
Joined: 12 Dec 2013 21:25

Re: AIAI

Post by Volare013 » 15 Dec 2013 13:20

I made a screen shot of the AI interface;
ttd1.png
(1.2 MiB) Downloaded 8 times
Thanks

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

Re: AIAI

Post by Kogut » 15 Dec 2013 14:33

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.
Attachments
Przechwytywanie.PNG
(67.03 KiB) Downloaded 8 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

tohjo
Engineer
Engineer
Posts: 1
Joined: 01 Feb 2014 16:12

Re: AIAI

Post by tohjo » 01 Feb 2014 16:17

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.
Attachments
open-ttd.PNG
(44.92 KiB) Downloaded 8 times

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

Re: AIAI

Post by Kogut » 05 Feb 2014 11:32

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).
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

HGus
Engineer
Engineer
Posts: 94
Joined: 12 May 2013 22:28
Location: Argentina

Re: AIAI

Post by HGus » 08 Mar 2014 17:43

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.

HGus
Engineer
Engineer
Posts: 94
Joined: 12 May 2013 22:28
Location: Argentina

Re: AIAI

Post by HGus » 03 Apr 2014 17:05

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)
Attachments
HGus Transport, 1832-03-20#1.png
AIAI iota 95 crash
(85.61 KiB) Downloaded 5 times

User avatar
beeurd
Engineer
Engineer
Posts: 67
Joined: 03 Dec 2005 02:30
Location: United Kingdom
Contact:

Re: AIAI

Post by beeurd » 04 Apr 2014 01:11

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!
Long time TT addict, long time forum lurker.
Oh, and I run a Star Wars fan site.

HGus
Engineer
Engineer
Posts: 94
Joined: 12 May 2013 22:28
Location: Argentina

Re: AIAI

Post by HGus » 05 Apr 2014 00:05

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...

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests