Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Mon Dec 10, 2018 9:57 am

All times are UTC




Post new topic  Reply to topic  [ 340 posts ]  Go to page Previous 113 14 15 16 17
Author Message
PostPosted: Sat Sep 17, 2016 3:12 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Kogut wrote:
From "newgrf hates ChooChoo" saga


:lol:

Alas, I've been rather busy on a new project - which also includes an AI framework, inspired by OpenTTD NoAI! It's our turn based strategy game, Powargrid, and I'm shamelessly going to take this opportunity to plug it :)

Game website: www.powargrid.com
AI dev forum: https://forum.powargrid.com/phpbb/viewforum.php?f=9

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Mon May 15, 2017 5:25 pm 
Offline
Engineer
Engineer

Joined: Mon May 15, 2017 12:32 pm
Posts: 1
Hi can you make a version that doesnt choose newest aviable track because the newest aviable at me is metro and crashes


Top
   
PostPosted: Mon May 15, 2017 6:30 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
I'd love to, but I have too many projects in the works (including a kid, these days!) to continue work on ChooChoo :(

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Wed Aug 02, 2017 6:55 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Jan 22, 2005 7:31 pm
Posts: 6371
Location: Wakefield, West Yorkshire
I'm having this issue, seems to occur in all maps.
The one this occured on was a randomly generated 2048 x 2048 map, generated by TerraGenesis. The AI had been left to run by itself (so i could check if it errored when playing by itself and with me just idle)
It's also occured on smaller maps, down to 256 x 256 is what i've tried, below that it doesn't work correctly anyway from not having enough places to use.

Any ideas for what's wrong? If I know what even the basics of what is going wrong, I'll have a go at fixing it myself.
Attachment:
Unnamed, 1975-11-27.png [186.46 KiB]
Not downloaded yet

_________________
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!


Top
   
PostPosted: Thu Aug 03, 2017 4:26 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4677
Location: home
src/script/api/script_list.cpp, line 619-ish wrote:
Code:
      /* Kill the script when the valuator call takes way too long.
       * Triggered by nesting valuators, which then take billions of iterations. */
      if (ScriptController::GetOpsTillSuspend() < -1000000) {
         /* See below for explanation. The extra pop is the return value. */
         sq_pop(vm, nparam + 4);

         ScriptObject::SetAllowDoCommand(backup_allow);
         return sq_throwerror(vm, "excessive CPU usage in valuator function");
      }
In short, that function runs a function over a list, but the amount of time to run that code is too large.

Solutions can be anything to reduce the execution time. Move some code out to a second iteration, prepare some data before hand so it runs faster, or break the list in smaller pieces are all options.

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Thu Aug 03, 2017 4:01 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Jan 22, 2005 7:31 pm
Posts: 6371
Location: Wakefield, West Yorkshire
So in the screenshot, it's listing the calls (noting the file + exact line that took it there) that led up to the actual section of code that caused the error? In this case IsBuildableRectangle is the function that had an issue? (Line 97 is 'area.Valuate(AITile.IsBuildable);')

Sounds like the entire thing is a wild goose chase until you find the end thing through trial and error until you get the hang of the language and setup of AIs, need to go through the files to find out where area.Value(AITul[..] is defined and find ot what is wrong with that.

The AI worked fine <many versions ago> so I wonder if something in openTTD has changed.

_________________
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!


Top
   
PostPosted: Thu Aug 03, 2017 5:01 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4677
Location: home
Yes the list of functions + line numbers is a call-stack, it starts at the bottom where main.nut, line 75 did a function call, that led eventually to executing builder_network.nut, line 442. That line did a function call, which eventually led to executing the same file, but at line 601. There is the (long) native call, which called a function in Squirrel again, which triggered the error in builder.nut, line 97.

[ie just like you say]

You get 2 error messages for some reason. Most likely is because the native function noticed that the squirrel subroutine failed, and it passed the error + stack down for it caller to deal with it.

The other red things look like variables and their values, eg "flat" is probably a variable, and it has value "true".

Quote:
In this case IsBuildableRectangle is the function that had an issue? (Line 97 is 'area.Valuate(AITile.IsBuildable);')
Normally, yes.

However "excessive CPU usage" means the native function takes too long, and that needs some explanation first.

What you want is that the AI is not eating all processor time, or the normal game would suffer. To get that, an AI gets some number of opcodes it can execute, and then its turn has passed, and the script has to wait for its next turn.
The problem is that you can't stop halfway a native function. It's either not do it this turn, or do it fully. Since it's impossible to guess beforehand how long it will take, there is only one solution, do the native call. This is what was implemented first (probably, I never looked at the squirrel code in detail). However, as AI authors got more experienced the code got bigger and more complicated, which is fine in itself (since squirrel code can be stopped at any statement), UNTIL you run such code through a native function. At that moment, the AI can't be stopped halfway, and it can eat all CPU it wants.
Some time ago, this became too much of a problem apparently, and an additional check was added that the code is not wildly beyond its allowed number of opcodes. If it is, the interpreter now throws an error "excessive cpu usage", which mostly translates to "don't make long and complicated computations while using a native function".
So while your error triggered at "isBuildableRectangle", but it is not an error at that point, it's an arbitrary "enough, now stop it!" point.

The real culprit here is either in the function that is called from the native function (which would be too long and complicated), or it is in the list items that it received (assuming the native function does a loop of some kind), which is too long.

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Fri Aug 25, 2017 9:27 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Hi Redirect Left, thanks for giving my AI a go :) And thanks to Alberth for responding in detail.

I don't immediately see what's wrong - it should only look at a small number of tiles, and the valuator function is not trivial, but not that expensive either:

Code:
function IsBuildableRectangle(location, rotation, from, to, mustBeFlat) {
   // check if the area is clear and flat
   // TODO: don't require it to be flat, check if it can be leveled
   local coords = RelativeCoordinates(location, rotation);
   local height = AITile.GetMaxHeight(location);
   
   for (local x = from[0]; x < to[0]; x++) {
      for (local y = from[1]; y < to[1]; y++) {
         local tile = coords.GetTile([x, y]);
         local flat = AITile.GetMaxHeight(tile) == height && AITile.GetMinHeight(tile) == height && AITile.GetMaxHeight(tile) == height;
         if (!AITile.IsBuildable(tile) || (mustBeFlat && !flat)) {
            return false;
         }
         
         local area = AITileList();
         SafeAddRectangle(area, tile, 1);
         area.Valuate(AITile.GetMinHeight);
         area.KeepAboveValue(height - 2);
         area.Valuate(AITile.GetMaxHeight);
         area.KeepBelowValue(height + 2);
         area.Valuate(AITile.IsBuildable);
         area.KeepValue(1);
         
         local flattenable = (
            area.Count() == 9 &&
            abs(AITile.GetMinHeight(tile) - height) <= 1 &&
            abs(AITile.GetMaxHeight(tile) - height) <= 1);
         
         if (!AITile.IsBuildable(tile) || !flattenable || (mustBeFlat && !flat)) {
            return false;
         }
      }
   }
   
   return true;
}


It's been years since I worked on this, so I'm afraid the chance of a fix is low...

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Fri Aug 25, 2017 9:59 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Quick fix if you want to hack the source code: replace the valuator with a for loop so it can be interrupted after every call.

In builder_network.nut, replace line 601 with the following:

Code:
      // tiles.Valuate(IsBuildableRectangle, Rotation.ROT_0, [-2, -2], [Crossing.WIDTH + 2, Crossing.WIDTH + 2], false);
      for (local tile = tiles.Begin(); tiles.HasNext(); tile = tiles.Next()) {
         tiles.SetValue(tile, IsBuildableRectangle(tile, Rotation.ROT_0, [-2, -2], [Crossing.WIDTH + 2, Crossing.WIDTH + 2], false) ? 1 : 0);
      }

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Fri Aug 25, 2017 10:06 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
I think I fixed it! Even managed to upload a new version to BaNaNas :)

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Fri Aug 25, 2017 10:49 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Jan 22, 2005 7:31 pm
Posts: 6371
Location: Wakefield, West Yorkshire
You indeed appear to have fixed it. I've run a game on fast forward, i just did a few minor routes to keep me afloat during the period and not go bankrupt. Your AI built a proper network, instead of doing a junction, then crashing trying to find a path.
Huge thanks! I had a look but couldn't really find the issue, or find any reason why it suddenly stopped working as it worked flawlessly several versions of openTTD ago.


Attachments:
File comment: success!
Nelson & Co., 2004-09-09.png [389.95 KiB]
Not downloaded yet

_________________
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!
Top
   
PostPosted: Fri Aug 25, 2017 10:54 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Thanks for the test run!

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Sat Aug 26, 2017 2:00 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Jan 22, 2005 7:31 pm
Posts: 6371
Location: Wakefield, West Yorkshire
As it turns out, it does still error, just takes a lot longer to reach that place.


Attachments:
Nelson & Co., 2051-01-06.png [357.17 KiB]
Not downloaded yet

_________________
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!
Top
   
PostPosted: Sat Aug 26, 2017 9:15 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Bugger! OK, lemme check... Looks like I was using a similar "too expensive" Valuate call in three more places. I've applied the same fix there. Updated in BaNaNas!

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Sat Aug 26, 2017 9:15 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Gonna let it run for a while to see if anything else pops up. Thanks for the bug report!

_________________
Building Powargrid: a turn based strategy game


Top
   
PostPosted: Sat Aug 26, 2017 9:52 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Sun Jul 13, 2008 12:57 am
Posts: 313
Looks like it's back in business!

Image


Attachments:
File comment: Map after 30 years
choochoo-412.png [110.06 KiB]
Not downloaded yet

_________________
Building Powargrid: a turn based strategy game
Top
   
PostPosted: Sun Dec 31, 2017 2:55 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Thu Feb 26, 2015 12:52 am
Posts: 240
ChooChoo crash.

I post the log text file, a save before crash and a save after crash.

Quote:
dbg: [script] [0] [W] 2081-05-18: Selling: XT0D39065
dbg: [script] [0] [W] 2081-05-18: Selling: XT0D75452
dbg: [script] [0] [W] 2081-05-18: Selling: XT0D134797
dbg: [script] [0] [S] Your script made an error: the index 'find' does not exist
dbg: [script] [0] [S]
dbg: [script] [0] [S] *FUNCTION [Cull()] choochoo-412\manager.nut line [51]
dbg: [script] [0] [S] *FUNCTION [HandleEvents()] choochoo-412\main.nut line [146]
dbg: [script] [0] [S] *FUNCTION [Start()] choochoo-412\main.nut line [62]
dbg: [script] [0] [S]
dbg: [script] [0] [S] [name] NULL
dbg: [script] [0] [S] [vehicle] 11
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [vehicle] 11
dbg: [script] [0] [S] [converted] INSTANCE
dbg: [script] [0] [S] [e] INSTANCE
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [year] 2080
dbg: [script] [0] [S] [minMoney] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] The script died unexpectedly.
One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window


Attachments:
openttdCore3log.txt [20.79 KiB]
Downloaded 59 times
ChooChoo, 1st May 2081.sav [376.7 KiB]
Downloaded 66 times
ChooChoo, 1st Jun 2081.sav [376.24 KiB]
Downloaded 57 times

_________________
Formerly known as Samu
Top
   
PostPosted: Sat Sep 29, 2018 9:02 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Thu Feb 26, 2015 12:52 am
Posts: 240
the index 'find' does not exist. OpenTTD 1.8.0


Attachments:
Unnamed, 1981-08-18.sav [4.76 MiB]
Downloaded 17 times
Unnamed, 1981-08-20.png [165.02 KiB]
Not downloaded yet

_________________
Formerly known as Samu
Top
   
PostPosted: Mon Nov 26, 2018 3:34 am 
Offline
Tycoon
Tycoon

Joined: Sun Feb 23, 2014 10:02 pm
Posts: 1292
The Trudhattan & Frinford R.R. has just been offered a chance to purchase a ChooChoo (at times its most formidable competitor) in bankruptcy...and on looking it over,it appears that your manager Mr. Gordon has invested heavily into monorails in the early 1950s,which may seem forward-looking to him but has plunged the company deeply into debt.These track tiles are useless to the company when its only tracked vehicles are profitable steam engines.Perhaps my NewGRF choices caused this but if it can't use tracks maybe there's a way to make it not buy them?


Attachments:
Trudhattan&FrinfordR.R.Co.,19thDec1952.sav [4.13 MiB]
Downloaded 3 times
Top
   
PostPosted: Mon Nov 26, 2018 11:57 am 
Offline
Engineer
Engineer

Joined: Fri Oct 07, 2016 4:14 am
Posts: 7
Half the rail=half the cost. Every artifical intelligent manager knows this. 8)

ChooChoo would have built the second rail soon, but unfortunately aliens kidnapped a train full of valuables and it had not enough money to pay the bank for the lost value. That's why the bank sold the company to you. I analysed the savegame, it's true.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 340 posts ]  Go to page Previous 113 14 15 16 17

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.