MogulAI

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
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4554
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: MogulAI

Post by Zuu »

Hmm, yea now I see Selling an aircraft causes a DoCommand which is not allowed in a Valuator call. So your loop is still needed, but you can use a foreach loop whenever you don't need the extra power of a regular loop.

Code: Select all

function AIAI::DeleteVehiclesInDepots()
{
   local list = AIVehicleList();
   list.Valuate(AIVehicle.IsStoppedInDepot);
   list.KeepValue(1);
   foreach(q, _ in list)
   {
       AIVehicle.SellVehicle(q);
   }
   return list.Count();
}
Note that the ", _" is absolutely needed in order for the foreach to work as wanted. The underscore is a second looping variable that will contain the AIList values. If only one looping variable is provided, it will contain the values, not the keys.

An alternative in case you're desire is to minimize the amount of code:

Code: Select all

function AIAI::DeleteVehiclesInDepots()
{
   local list = AIVehicleList();
   foreach(q, _ in list)
   {
       AIVehicle.IsStoppedInDepot(q) && AIVehicle.SellVehicle(q);
   }
   return list.Count();
}
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: MogulAI

Post by Kogut »

I returned to playing with AIs and started from comparing startup performance. In my tests (flat terrain, infrastructure maintemance killing aircraft) MogulAI was wonderfully quick. I will look around to check is it possible to reuse your ideas/code in my AI.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

xarick
Transport Coordinator
Transport Coordinator
Posts: 291
Joined: 26 Feb 2015 00:52

Re: MogulAI

Post by xarick »

When distant join is turned off, the AI builds roads like in this screenshot.

Image
Formerly known as Samu

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 18 guests