Option to use built-in AI...

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Option to use built-in AI...

Post by maxorator »

I think there should be an option to use built-in AI (nightlies) for two reasons:
1) NoAI AIs that I've tested so far lag heavily. I have to create the save in 0.6.3 and play in nightly to get rid of that awful lag.
2) Not every average player is interested in scripting.

:shock:
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Option to use built-in AI...

Post by Zutty »

maxorator wrote:I think there should be an option to use built-in AI (nightlies) for two reasons:
1) NoAI AIs that I've tested so far lag heavily. I have to create the save in 0.6.3 and play in nightly to get rid of that awful lag.
2) Not every average player is interested in scripting.

:shock:
1) You can change the setting "Competitors" > "Computer Players" > "#opcodes before AI is suspended" to improve performance
2) You dont HAVE to write your own AI. Just download one that someone else has written (hint hint - see my sig :lol: ).
PathZilla - A networking AI - Now with tram support.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Option to use built-in AI...

Post by Yexo »

3) There is no built-in AI anymore.
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

Yexo wrote:3) There is no built-in AI anymore.
How does it handle my 0.6.3 saves properly then?
Zutty wrote:
maxorator wrote: 1) NoAI AIs that I've tested so far lag heavily. I have to create the save in 0.6.3 and play in nightly to get rid of that awful lag.
1) You can change the setting "Competitors" > "Computer Players" > "#opcodes before AI is suspended" to improve performance
If AI fails to update once per frame and needs to be halted, then the system is a no-no in my opinion. :wink:
Last edited by maxorator on 02 Feb 2009 20:28, edited 1 time in total.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Option to use built-in AI...

Post by CommanderZ »

maxorator wrote:
Yexo wrote:3) There is no built-in AI anymore.
How does it handle my 0.6.3 saves properly then?
I guess the AI does nothing, it just runs what was build before.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Option to use built-in AI...

Post by Yexo »

maxorator wrote:
Yexo wrote:3) There is no built-in AI anymore.
How does it handle my 0.6.3 saves properly then?
A random AI is loadedto take the place of the original AI.
Zutty wrote:
maxorator wrote: 1) NoAI AIs that I've tested so far lag heavily. I have to create the save in 0.6.3 and play in nightly to get rid of that awful lag.
1) You can change the setting "Competitors" > "Computer Players" > "#opcodes before AI is suspended" to improve performance
If AI fails to update once per frame and needs to be halted, then the system is a no-no in my opinion. :wink:
Are you sure you know what you're talking about?Why should the AI call some suspend function eveytime if it can be halted by openttd instead? It makes sure an AI can't cause openttd to halt and it takes away the difficulty of deciding when to stop from the AIs.
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

Yexo wrote:
Zutty wrote:1) You can change the setting "Competitors" > "Computer Players" > "#opcodes before AI is suspended" to improve performance
If AI fails to update once per frame and needs to be halted, then the system is a no-no in my opinion. :wink:
Are you sure you know what you're talking about?Why should the AI call some suspend function eveytime if it can be halted by openttd instead? It makes sure an AI can't cause openttd to halt and it takes away the difficulty of deciding when to stop from the AIs.
If AI cycle is infinite, that means there is an infinite loop. In that case, the loop part of it can simply be removed to get one frame's code. You see, there's actually LESS code involved (unless AI runs in many threads).

And why can't there be an option to use built-in AI? Tell me at least one downside (let's assume the AI is well coded).
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Option to use built-in AI...

Post by Yexo »

maxorator wrote:If AI cycle is infinite, that means there is an infinite loop. In that case, the loop part of it can simply be removed to get one frame's code. You see, there's actually LESS code involved (unless AI runs in many threads).
Yes, the AIs run in an infinite loop. That does not mean that you can simply remove the outer loop to just run one "frame". Actually, you could, but you don't want that, because "frame" can sometimes take as long as one in-game year. Now image you want to do the same in one tick, see why it doesn't work?
And why can't there be an option to use built-in AI?
What built-in AI? There is none anymore.
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

Yexo wrote:
maxorator wrote:If AI cycle is infinite, that means there is an infinite loop. In that case, the loop part of it can simply be removed to get one frame's code. You see, there's actually LESS code involved (unless AI runs in many threads).
Yes, the AIs run in an infinite loop. That does not mean that you can simply remove the outer loop to just run one "frame". Actually, you could, but you don't want that, because "frame" can sometimes take as long as one in-game year. Now image you want to do the same in one tick, see why it doesn't work?
In that case it either uses sleep functions (which are less efficient than timer checks) or is very badly written.
Yexo wrote:
And why can't there be an option to use built-in AI?
What built-in AI? There is none anymore.
The one that can be easily copied back in.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Option to use built-in AI...

Post by Yexo »

maxorator wrote:
Yexo wrote:...
Yes, the AIs run in an infinite loop. That does not mean that you can simply remove the outer loop to just run one "frame". Actually, you could, but you don't want that, because "frame" can sometimes take as long as one in-game year. Now image you want to do the same in one tick, see why it doesn't work?
In that case it either uses sleep functions (which are less efficient than timer checks) or is very badly written.
Am I right you're saying "Sleep functions are less efficient than timer checks"? If so, the current code should be kept.
Yexo wrote:
And why can't there be an option to use built-in AI?
What built-in AI? There is none anymore.
The one that can be easily copied back in.
1) It can't be "easily" copied back in.
2) Why should the old, stupid AI be integrated in the code when there is a working framework with several AIs that are a lot better then the old AI?
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

Yexo wrote:Am I right you're saying "Sleep functions are less efficient than timer checks"? If so, the current code should be kept.
By timer checks I mean something like this:

Code: Select all

if(dwLastThing1Check+THING1_FREQUENCY < dwTimer){
    dwLastThing1Check=dwTimer;
    /* something here */
}
if(dwLastThing2Check+THING2_FREQUENCY < dwTimer){
    dwLastThing2Check=dwTimer;
    /* something here */
}
/* etc, note that this is one frame and frames of this type
    are supposed to execute in microseconds (rather than a game-year) */
Yexo wrote:1) It can't be "easily" copied back in.
2) Why should the old, stupid AI be integrated in the code when there is a working framework with several AIs that are a lot better then the old AI?
Thanks for an idea. You just reminded me I can take a scripting AI, rewrite it in C, add it to the code and compile. Problem solved... almost - I have to do this every time I download the new nightly code. :P
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Option to use built-in AI...

Post by Roujin »

...eh?

Are you trying to tell us that you think the NoAI framework is done in a bad way and it would be faster to just hardcode the AI into the C(++) code than like how it's done currently?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

Roujin wrote:...eh?

Are you trying to tell us that you think the NoAI framework is done in a bad way and it would be faster to just hardcode the AI into the C(++) code than like how it's done currently?
I'm telling you it would be nice to be able to choose between them. NoAI is great, but I like hardcoded AI more. Why not just add a "Original" to the list of AIs and if that is used, then it uses built-in AI?

Plus I like writing/editing C more than scripting languages (as a C programmer I'm a control maniac). :P
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Option to use built-in AI...

Post by planetmaker »

maxorator wrote:If AI cycle is infinite, that means there is an infinite loop. In that case, the loop part of it can simply be removed to get one frame's code. You see, there's actually LESS code involved (unless AI runs in many threads).
Sorry to be blunt: Are you're aware that you don't talk much sense? If you really want to make improvement proposals I strongly suggest to make yourself familiar with the current implementation, the previous implementation, their pros and cons and the arguments for the change you see. But then you won't see the need for the old AI anymore, I guess...
And why can't there be an option to use built-in AI? Tell me at least one downside (let's assume the AI is well coded).
What's the difference to getting one AI from the content download and use that? They're far superior to the old AI - and there's nothing which a PC cannot handle (no, I don't have gaming PCs, I only have usual office PCs with average CPUs). Have you actually tested it?!
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Option to use built-in AI...

Post by TrueBrain »

maxorator wrote:(..)
I'm telling you it would be nice to be able to choose between them. NoAI is great, but I like hardcoded AI more. Why not just add a "Original" to the list of AIs and if that is used, then it uses built-in AI?
(..)
You clearly have no idea how OpenTTD works and behaves, let alone how NoAI is implemented and how it is operated, let alone how the AI worked, and how it was hooked into the system. So before you start saying any other wrong (read: stupid) things, I suggest you first make yourself known with OpenTTD inner works. After that, I strongly suggest that you start asking things in a nice way, like we all do, and not just open that big mouth and start shouting all kinds of (strange) things. In general it is better to ask like: how did the old AI work? How does the NoAI framework work? Instead of saying: THIS IS ALL WRONG AND I KNOW HOW IT SHOULD BE DONE BETTER. We have enough of those people around here, and they rarely contribute anything sane to the progress of OpenTTD. So please, for everyones sake, first read up on how things worked, how things work, and how things might be improved, before talking any more. Also it might be a good idea to read up on the developement of NoAI (see wiki), to read why some decisions were made. And please, don't think like: because application A, which I happen to have written, works like plan D, OpenTTD for sure works like that plan too. Please please first make yourself known with the code you are making assumptions on. It is not the first day on the job for us too, and it might suprise you, but we did think about aspects of the game. NoAI is no exception to that.

Don't take this the wrong way, but currently you are (sorry) babbling. We would love any input and contribution you can make, but PLEASE read the code you are trying to comment on. Thank you :)

planetmaker: sorry I have repeated you ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
maxorator
Engineer
Engineer
Posts: 10
Joined: 02 Feb 2009 20:11

Re: Option to use built-in AI...

Post by maxorator »

I agree I don't know really anything about how NoAI operates. All my assumptions were made following the claims of the previous poster. I did not mean to ask in a impolite manner, I am just used to saying what's on my mind and if I am wrong, then someone will correct me (learning by making harmless mistakes). That's just my style. :)

The reason I don't like using NoAI could be either that I've never liked scripting languages or emulated stuff and I always try to find a way around using them. IMO lagging is the one unforgivable thing a game can do - I got a 1sec lag once in every 4-5 seconds when I had 2 NoAI companies on a 256x256 map and the opcode limit was 10000 - assuming a line of code is about 1-5 opcodes and I have to cut that limit down maybe to 800-1000, I'd prefer using a hardcoded AI.

Now, correct my mistakes so I could learn what's really going on. I didn't search very much, but after a few quick searches on the wiki, I could only find pages showing how to use NoAI, none which tell how it works exactly.

Edit: I realise I may have downloaded a bad AI too.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Option to use built-in AI...

Post by TrueBrain »

maxorator wrote:I agree I don't know really anything about how NoAI operates. All my assumptions were made following the claims of the previous poster. I did not mean to ask in a impolite manner, I am just used to saying what's on my mind and if I am wrong, then someone will correct me (learning by making harmless mistakes). That's just my style. :)
It might not be the best style ;) Just a hint ..

maxorator wrote: The reason I don't like using NoAI could be either that I've never liked scripting languages or emulated stuff and I always try to find a way around using them.
Feel free; just know that 'ways' around such things break when you talk cross-platform (which OpenTTD does); see below.
maxorator wrote: IMO lagging is the one unforgivable thing a game can do - I got a 1sec lag once in every 4-5 seconds when I had 2 NoAI companies on a 256x256 map and the opcode limit was 10000 - assuming a line of code is about 1-5 opcodes and I have to cut that limit down maybe to 800-1000, I'd prefer using a hardcoded AI.
And in which world do you think using a 'hardcoded' AI solves that problem? I am very sure that if someone would make a stupid AI like the old AI in Squirrel, it wouldn't 'lag' either. Just the new AIs are much more advanced and do much more pre-calculations before building anything. This has a penalty, of course. But I think most of the lag comes from the fact your CPU is a bit out-dated ;) The '10000' limit is set by testing the framework on a 1.8 GHz (single core, L2 of 1 MB), on a 256x256 map with 7 AIs running (in an infinite loop, hitting as much CPU as they can possibly can), and checking when the moment comes the game starts to 'lag' (no longer able to make 1 frame every 30ms without fastforwarding). So if your system 'lags' with just 2 AIs on a normal map, I think it is more a problem of your CPU than it is of the AI. Any AI of the advancement of, say, AdmiralAI would lag in your case. Even hardcoded ones. Simply because they are much much much much more advanced than the old AI was. Which was, for the record, not thinking. It just picked 2 locations and connected them. Not thinking if it is a good route, if it would be profitable, nothing. Just connect (and worse: connect with cheats: don't pay for terraforming)
maxorator wrote: Now, correct my mistakes so I could learn what's really going on. I didn't search very much, but after a few quick searches on the wiki, I could only find pages showing how to use NoAI, none which tell how it works exactly.
If you would have read the AI:Main_Page you would have seen a topic which states C++ support for the NoAI framework is removed. Clearly we once had C++ support. This was removed for reasons stated in that page, but because you might be lazy, the summary: C++ support was removed because after a few months it turned out that only one person attempted to use the C++ part of the NoAI framework. He also very much failed to share his code with others, as it means that either the person he shared it with had to know how to compile OpenTTD on its own (which 95% of our users don't), or the AI creator had to make a pre-compiled binary for all platforms on every change of his AI. This is undoable. Also, it was very easy to break out of the NoAI framework, and 'cheating' in a way we wanted to prevent with this whole API. This framework is a fair API, which makes AIs only do what humans can do too. Either way, one might say, use libraries. Nice idea, but very much not cross-platform. It would mean every AI author would need to publish his AI in various of types (one for Windows, one for Linux, one for ..). This is undoable, and the reason most AI plugin systems of other game projects fail (for example, read up around the problems with TA Spring AIs, which uses such system). So, the only logic, safe, simple and fair solution is using an embed script. Feel free to dislike that, but so far many more people like it. So I guess you either have to adjust your like or dislike, or not bother using the framework at all :) Either way, 'hardcoded' AIs is not the way, and by the current lack of threads in the NoAI framework, even impossible (and no, your 'frame' idea is a very very very bad one, and very much undoable for any AI programmer. But that is a whole other subject).
maxorator wrote: Edit: I realise I may have downloaded a bad AI too.
The fact that you can download AIs, you can thank to the fact they are created in an embed script :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: Option to use built-in AI...

Post by Ralph »

Maybe someone could take the last revision that contained the original AI and reimplement it in the NoAI framework for this chap. May need another game option 'AIs do not pay for terraforming' though if you don't want it to go bankrupt quickly.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Option to use built-in AI...

Post by TrueBrain »

Ralph wrote:Maybe someone could take the last revision that contained the original AI and reimplement it in the NoAI framework for this chap. May need another game option 'AIs do not pay for terraforming' though if you don't want it to go bankrupt quickly.
If only .. it cheated in so many more ways ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
wozzar
Transport Coordinator
Transport Coordinator
Posts: 331
Joined: 27 Dec 2002 09:25

Re: Option to use built-in AI...

Post by wozzar »

I agree the lag is unacceptable with the NoAi in OTTD and needs to be addressed.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 5 guests