Some AI questions

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

Post Reply
User avatar
Redirect Left
Tycoon
Tycoon
Posts: 6581
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Some AI questions

Post by Redirect Left » 07 May 2019 23:56

Hi there.

I'm trying to make an AI, safe to say, it is going disastrously. I'm using SimpleAI as my starting point, after giving up entirely trying to udnerstand the ChooChoo AI.

I am trying to get it to replicate my method of playing which is proving a little too complex, although anyone who has seen my method of making junctions will know even I don't4 know how I do it sometimes.

Does anyone have recommendations or thingsa to check out to make a 'proper network bot' that is not silly complex?
Is it possible to have a bot choose its own color, if the color is not taken by another company? - i looked at the API and couldn't find anything for 'colour' or 'color'.
In the NoAPI documentation there are endless versions - am i correct in saying i should be using the highest numbered one?
is it possible to select a specific manager face, ie: enter in a seed and it uses that one? - i personally have a specific manager face i used all the tim, i'd like to get the BOT to do the same thing.

I understand anything to do with 'AI' is complex, but it seems making an AI for this game is mostly focused on the elite who can understand code!

Would an AI be expected to work with any version, or do I have to make amendments for if the bot is being run with a specific patch pack? (ie: i use JGRs one)
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!

User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5391
Joined: 13 Sep 2004 13:21
Location: The Moon
Contact:

Re: Some AI questions

Post by PikkaBird » 08 May 2019 06:07

Redirect Left wrote:I'm using SimpleAI as my starting point
I would recommend starting from as close to scratch as possible.
I am trying to get it to replicate my method of playing which is proving a little too complex
I've always thought of AI coding as playing the game blindfolded. It is complex. Start simple.
Is it possible to have a bot choose its own color, if the color is not taken by another company? - i looked at the API and couldn't find anything for 'colour' or 'color'.
This was added in 1.9. Look in AICompany.
In the NoAPI documentation there are endless versions - am i correct in saying i should be using the highest numbered one?
Yes. The older versions are to maintain backwards compatibility (eg if a function is extended, changed, or removed, it won't break old AIs).
is it possible to select a specific manager face, ie: enter in a seed and it uses that one?
No. You can only set the manager gender, which generates a new random face. You could make a feature request on Github.
it seems making an AI for this game is mostly focused on the elite who can understand code!
Squirrel is about as simple a coding language as they come. You don't need to use complex "proper programming" methods to make something that works. I wrote my own AI and can't make head or tails of anyone else's.
Would an AI be expected to work with any version
Any OpenTTD version which understands the API you're using (so, no 1.9.0 AIs in 1.8.0). Of course, patched versions of OpenTTD might have their own bugs relating to AIs.

User avatar
Redirect Left
Tycoon
Tycoon
Posts: 6581
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: Some AI questions

Post by Redirect Left » 09 May 2019 00:00

Hi, thanks for those answers Pikka, very helpful.

I tried to start from scratch, but was quickly thwarted, given I do not know anything about 'Squirrel', so the syntax, formatting, functions etc are entirely alien to me, i thought SimpleAI would be a decent start. Especially since I was eager to get some train action going on.

Where can I find further details on things in AIEvents, I found https://noai.openttd.org/api/1.9.0/classAIEvent.html - but it doesn't specify the exact triggers, or perhaps exact definitions. My main wonder is ET_COMPANY_IN_TROUBLE. Does that refer to my company, another company, what are the triggers that determines if your company (or someone elses) is "in trouble".

I note numerous AIs are producing this log message, I'm a little concerned, but the messages don't seem to clarify much.
Image
I am using the default vehicles (no GRFs in that department), and vehicles never set to expire. Are you aware of what produces that, or why, given all vehicles should be available, especially given the year is now into the 2100s.

One thing I note, is that a lot of AIs seem to build speculatively, and then do not delete after itself when it changes its mind, or they leave an odd junction or depot hanging around. To avoid this happening to me, is there a way of detecting if a piece of track (or say just a 'tile') has anything scheduled to go over it or if its unused?

What would be the expected fix for a vehicle that has gotten lost (AIEvent.ET_VEHICLE_LOST), or rather, what would people consider 'sensible' option for an AI? other than panic stations, of course.

I hope you don't mind me spurting questions out, but I guess that's how you learn!
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!

User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5391
Joined: 13 Sep 2004 13:21
Location: The Moon
Contact:

Re: Some AI questions

Post by PikkaBird » 09 May 2019 03:56

I'd say "walk before you can run", but in this case you're trying to win a dance competition before your legs have grown.

Start here, with a basic main.nut and info.nut. Get an AI working that can build an HQ, set its name and colour. Then start small - experiment building things, removing things, placing signs, writing to the debug log, etc. Use the pathfinder to build a rail line between two points. The questions you're asking are good questions, but they're about five levels deeper than where you're at right now.

User avatar
Redirect Left
Tycoon
Tycoon
Posts: 6581
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: Some AI questions

Post by Redirect Left » 09 May 2019 13:05

That's normal for me, I always ask as many questions as I can think of, so I know for later on, or so I know if its worth bothering with or not at all. There's no point wasting time if its too complex or will take too long to achieve vs the end result.

Given I am working from another AI, and not the tutorial (whoever wrote that managed to write it in the slowest most boring way possible), I've already figured quite a bit out, far more than I managed to learn from staring at the tutorial for a few hours. The questions in my most recent post refer to things that are either not handled, or handled differently in each AI i've looked at, so i don't know what is 'expected' so to say, plus personal experience of playing with lots of AIs over the past 2 weeks to get a feel for how they typically behav,e and any mistakes that commonly occur with some (in the case of things getting left behind when they change their mind)
I learn much better when learning from an example I can tinker with until I have learnt enough to redo it, than starting from scratch (unless the example i was learning from can just be reworked), it's how I've learnt all the (programming) languages I know how to do to date. Not everyone can do the whole 'from scratch thing', we all learn differently.
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!

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

Re: Some AI questions

Post by HGus » 10 May 2019 06:18

Redirect Left wrote: Where can I find further details on things in AIEvents, I found https://noai.openttd.org/api/1.9.0/classAIEvent.html - but it doesn't specify the exact triggers, or perhaps exact definitions. My main wonder is ET_COMPANY_IN_TROUBLE. Does that refer to my company, another company, what are the triggers that determines if your company (or someone elses) is "in trouble".
Look at https://noai.openttd.org/api/1.9.0/clas ... ouble.html
And check the AIEventCompanyInTrouble() function.
I note numerous AIs are producing this log message, I'm a little concerned, but the messages don't seem to clarify much.
Image
I am using the default vehicles (no GRFs in that department), and vehicles never set to expire. Are you aware of what produces that, or why, given all vehicles should be available, especially given the year is now into the 2100s.
That usually happens with vehicles that don't fit the service requirements (speed, load, cargo or type of station). It depends on how do you restrict your own AI.
One thing I note, is that a lot of AIs seem to build speculatively, and then do not delete after itself when it changes its mind, or they leave an odd junction or depot hanging around. To avoid this happening to me, is there a way of detecting if a piece of track (or say just a 'tile') has anything scheduled to go over it or if its unused?
Only if it is already owned: https://noai.openttd.org/api/1.9.0/clas ... 6de7625bcd
What would be the expected fix for a vehicle that has gotten lost (AIEvent.ET_VEHICLE_LOST), or rather, what would people consider 'sensible' option for an AI? other than panic stations, of course.
It depends on type of vehicle. If it is a normal road vehicle, maybe its route was broken by other competitor, or just by your own AI. Or can be a bad constructed route. If your script cannot fix the issue, then it should send the vehicle to depot and sell it, if even it can find a route to depot! In case of trains, it can happens when a train gets stuck in a jammed junction, or waiting behind a neverchanging red light. If a ship, it usually happens when it enter a dock in a narrow bay or canal, and doesn't have enought space to turn. It will find the correct way fast and there is no concern about that, a human player can fix it by terraforming or building more space for canals, just to avoid the bothering message. Other case for ships is another player terraforming aggresively and closing exits, the only way to avoid that is building canals over sea and lakes to ensure the route is not broken (used buoys are automatically locked)

User avatar
Redirect Left
Tycoon
Tycoon
Posts: 6581
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: Some AI questions

Post by Redirect Left » 14 May 2019 03:17

Hi HGus, many thanks for your details reply it helped a lot.

I've now got a simple AI up and running, and hopefully I can improve upon it to a point i'm happy to release it. It currently makes quite poor financial choices, so i'll check out the financial stuff next time i am playing with it.

Whilst playing around with loads of AIs on BaNaNas, it's surprising how many of them they are, but then how many of them seem to be by people who haven't logged in on this forum for over a year or so, so may be abandoned :(
Image
Worst Behaved IRC Member of 2008, 2009 & 2010 - Go Me!

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest