NoAI Branch - An AI Framework

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

Locked
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

kuifware wrote:Are const and enum statements supported in Squirrel code? The Squirrel language manual describes these statements, but OpenTTD gives me a compile error ('Your script made an error: end of statement expected (; or lf)'). (..)
Const and enum are introduced with the latest Squirrel version, which we don't use. This is mostly because we have modified Squirrel quiet a bit. When I have the time, and feel like it, I might sync both versions, but the latest version introduces such few useful things, that it will take a while :) (the amount of bug fixes is smaller than the amount of new features, which isn't a good sign, if you ask me).

Currently I am also researching the option to create our own language (which will use almost the same language as Squirrel (and C++ for that matter)). This because Squirrel, code-wise, sucks big-time. Completely unreadable, lack of documentation, lack of coding style, and therefor it is really hard for a non-Squirrel-developer to modify anything. But... this is just research, nothing real :)
The only thing necessary for the triumph of evil is for good men to do nothing.
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: NoAI Branch - An AI Framework

Post by Mchl »

GeekToo wrote:
TrueLight wrote:[
Now show us your AI and let us enjoy the moment too :)
OK, here it is: Convoy (the bus loving AI)
Performs quite well actually.
It does have a tendency to buy too much buses per line. It seems that it buys as much of them, as it is necessary to transport expected passengers available. It doesn't take into account, that bus stations have limited throughput. It results in bus queues ob both ends of line, which isn't very economical i suppose.

And I got one SQ error so far:
NoAI wrote: dbg: [ai] [3] Your script made an error: the index '0' does not exist
dbg: [ai] [3]
dbg: [ai] [3] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]
dbg: [ai] [3] *FUNCTION [Start()] convoy/main.nut line [866]
dbg: [ai] [3]
dbg: [ai] [3] [@ITERATOR@] 17
dbg: [ai] [3] [line_it] INSTANCE
dbg: [ai] [3] [@INDEX@] 16
dbg: [ai] [3] [this] INSTANCE
dbg: [ai] [3] 31200
dbg: [ai] [3] [S]
  • INSTANCE
    dbg: [ai] [3] [S] [this] INSTANCE


--edit--
And another one (same game)
NoAI wrote: dbg: [ai] [4] [S] Your script made an error: the index '0' does not exist
dbg: [ai] [4] [S]
dbg: [ai] [4] [S] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]
dbg: [ai] [4] [S] *FUNCTION [Start()] convoy/main.nut line [866]
dbg: [ai] [4] [S]
dbg: [ai] [4] [S] [@ITERATOR@] 16
dbg: [ai] [4] [S] [line_it] INSTANCE
dbg: [ai] [4] [S] [@INDEX@] 15
dbg: [ai] [4] [S] [this] INSTANCE
dbg: [ai] [4] [S] 25600
dbg: [ai] [4] [S]
  • INSTANCE
    dbg: [ai] [4] [S] [this] INSTANCE


In both cases it was after '[INFO] Extra buses needed'
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin »

nice work ;)

One thing I noticed is that the AI does not correct its errors.. e.g. if some connection on a slope failed, or it was interrupted by some other player (I tried that on purpose :P)

It just plans its route from A to B, once it found a nice plan, starts to build it, but doesn't check if it actually succeeds at building it. So if you e.g. buy a piece of land somewhere on the route the AI planned, it will build the whole route, minus that tile, then build its buses and so on..

In my opinion it should after finishing building, and from time to time make a check if its route is still connected.
* @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
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NoAI Branch - An AI Framework

Post by Hirundo »

First of all I'd like to compliment everyone who has worked on NoAI so far. It's a great framework for building some Artificial Intelligence instead of the old Artifical Stupidity. With my own AI slowly on its way, I have some questions/problems:

- I use signs for development purposes. When I place a sign with AISign.BuildSign(tileindex, "sign_text"), the sign is place correctly but its text is always "Apollo"(which is the name of my AI) Am I doing something wrong or is this a bug?
- Is it possible to read the values of difficulty or patch settings? IMO Important settings to know are for example the plane speed factor, whether it is allowed to build bus stops on town roads or not, realistic cachement area and breakdowns.
- The AIDebug window doesnt refresh properly. This causes nothing but some mild inconvenience though.
Create your own NewGRF? Check out this tutorial!
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: NoAI Branch - An AI Framework

Post by Mchl »

I had no problems with signs, but I also had once a situation, when I felt like Squirrel variables got confused (President's name got added to Company name for whatever reason). This hapened only once though.

Looking at your example. If sign_text is variable identifier, then it should be AISign.BuildSign(tileindex,sign_text); (i.e. no quotes <but then, if you used quotes, all your signs should have "sign_text", not "Apollo">)
kuifware
Engineer
Engineer
Posts: 26
Joined: 17 May 2008 21:10

Re: NoAI Branch - An AI Framework

Post by kuifware »

TrueLight wrote: Const and enum are introduced with the latest Squirrel version, which we don't use. This is mostly because we have modified Squirrel quiet a bit. When I have the time, and feel like it, I might sync both versions, but the latest version introduces such few useful things, that it will take a while :) (the amount of bug fixes is smaller than the amount of new features, which isn't a good sign, if you ask me).
Ok, that explains quite a bit. Which version is used in OpenTTD? It would be useful if this were mentioned in the docs somewhere.
TrueLight wrote: Currently I am also researching the option to create our own language (which will use almost the same language as Squirrel (and C++ for that matter)). This because Squirrel, code-wise, sucks big-time. Completely unreadable, lack of documentation, lack of coding style, and therefor it is really hard for a non-Squirrel-developer to modify anything. But... this is just research, nothing real :)
Now I understand what all the MyLanguage stuff is about on the SVN repository! I didn't know the Squirrel source looked that bad... good luck with your research :D
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoAI Branch - An AI Framework

Post by Zuu »

GeekToo wrote:I thank TrueLight and Zuu: I re-used some functions of Wright and Clueless ( if that's a problem, I'll rewrite them, and yeah, I know, I should have asked beforehand :mrgreen: )
Sure, use what you find usefull. Glad you found use for some of the code I written. Even if some parts of it is rather outdated, as it was written about a year ago except for being brought up date to the extent that it runs a few times. The ManageLoan function looks familiar, do you remember any other parts you've used?


So actually its time to say happy birthday to NoAI. This thread was started 13 March last year. But then Truelight, Rubidium and possible some more of the devs have spent time on NoAI before it was announced. But I say happy late birth day NoAI :bow: :D
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

kuifware wrote:
TrueLight wrote: Const and enum are introduced with the latest Squirrel version, which we don't use. This is mostly because we have modified Squirrel quiet a bit. When I have the time, and feel like it, I might sync both versions, but the latest version introduces such few useful things, that it will take a while :) (the amount of bug fixes is smaller than the amount of new features, which isn't a good sign, if you ask me).
Ok, that explains quite a bit. Which version is used in OpenTTD? It would be useful if this were mentioned in the docs somewhere.
TrueLight wrote: Currently I am also researching the option to create our own language (which will use almost the same language as Squirrel (and C++ for that matter)). This because Squirrel, code-wise, sucks big-time. Completely unreadable, lack of documentation, lack of coding style, and therefor it is really hard for a non-Squirrel-developer to modify anything. But... this is just research, nothing real :)
Now I understand what all the MyLanguage stuff is about on the SVN repository! I didn't know the Squirrel source looked that bad... good luck with your research :D
Not SVN, but in Mercurial ;) Hehe :) But yeah, indeed. Now let me look up the version.. it was never really important ;)

"The programming language SQUIRREL 2.1.2 stable"

So if the README file is any up-to-date, that is what we use :) And the latest released is 2.2.. the patch is very small, so it should be easy to sync. I just have my doubt about enum and const support, and some other changes. Oh well.. :)
The only thing necessary for the triumph of evil is for good men to do nothing.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Swallow wrote: - I use signs for development purposes. When I place a sign with AISign.BuildSign(tileindex, "sign_text"), the sign is place correctly but its text is always "Apollo"(which is the name of my AI) Am I doing something wrong or is this a bug?
This sounds _very_ strange. Please supply us with a small piece of code that demonstrates this, and we will research it. If such code is not supplied, I dismiss this as user error (sorry :)).
The only thing necessary for the triumph of evil is for good men to do nothing.
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NoAI Branch - An AI Framework

Post by Hirundo »

attached is a zip file containing a WIP info.nut and main.nut. The sign is placed at line ~57.

After some more testing the problem doesn't seem to occur always. In a small test 10 signs were placed. 7 of them showed the correct text, while 3 incorrectly displayed "Apollo". Kinda strange ?(
Tomorrow I will do some further testing....
Attachments
Apollo.zip
(1.83 KiB) Downloaded 94 times
Create your own NewGRF? Check out this tutorial!
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

Finaldeath wrote:It just for some reason only used 3 of it's built routes and swarmed them with buses, which is a bit odd, when it had 100,000 in the bank (with still a 510,000 loan that is)
I changed the code, so half the amount of buses will go to one town, and the other half go to the other. About the issue that lines are not used, a savegame or scenario would be nice.

Mchl wrote:
Performs quite well actually.
Thanks
Mchl wrote: It does have a tendency to buy too much buses per line. It seems that it buys as much of them, as it is necessary to transport expected passengers available. It doesn't take into account, that bus stations have limited throughput. It results in bus queues ob both ends of line, which isn't very economical i suppose.
Like I said above, I've now changed the code, so buses will be sent to both towns. The queuing is alright I guess, as long as the complete road is not filled, the buses do queue the first time, but once all buses have completed their route, the distance they keep is optimal.
Mchl wrote: dbg: [ai] [3] Your script made an error: the index '0' does not exist
dbg: [ai] [3]
dbg: [ai] [3] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]


Thanks for the feedback, it was a bug, I've solved it. I'll post an update soon.

Roujin wrote:One thing I noticed is that the AI does not correct its errors.. e.g. if some connection on a slope failed, or it was interrupted by some other player (I tried that on purpose :P)

It just plans its route from A to B, once it found a nice plan, starts to build it, but doesn't check if it actually succeeds at building it. So if you e.g. buy a piece of land somewhere on the route the AI planned, it will build the whole route, minus that tile, then build its buses and so on..

In my opinion it should after finishing building, and from time to time make a check if its route is still connected.


You're right, it's not very fault tolerant at the moment. I spent this night on improving that. Should be better on the next update.
BTW, thanks for updating the wiki, nice template, and I was pleasantly surprised to see Convoy there half a day after publishing.

Zuu wrote: The ManageLoan function looks familiar, do you remember any other parts you've used?

Actually I don't. But I did remember that when I entered this project, and started programming my AI, about half a year ago, Clueless and Wright were the only AI's around, and I studied them, and learned a lot from them. Then I did a patch for the extra zoom level graphics, and did leave my AI for a while. But recently I picked it up again, that's why I don't remember exactly. But, even if my code does not contain much Clueless code any more, the 'thank you' is well deserved, cause it was one of my inspiration sources :) .
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Edit: This probably wasn't a bug. I'll do more testing, but some HQ looked like it was placed in a odd location. I'll make sure tomorrow when I am not half asleep.

Also; the Convoy AI, what I meant by "not using routes" was sometimes it'd build like, 3 entirely separate routes between towns (which as far as I could tell, completely fine and connected) then only put buses on one of them, despite having tons of cash to fill the others, which is the strange part.

I don't mind so much it spams buses for one station, that's progress in getting your rating up that is ;)
Finaldeath
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin »

GeekToo wrote:[...]BTW, thanks for updating the wiki, nice template, and I was pleasantly surprised to see Convoy there half a day after publishing.
[...]
Sure, feel free to add any information :) Actually after downloading your AI, I wanted to download more (that is, all AIs that have been made up until now) and watch them compete. So I started going back in this thread, but got fed up after some pages.. then I thought there should be a place where all released and available AIs are listed.
And the wiki seems the best place for me to do that ;)
* @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
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoAI Branch - An AI Framework

Post by Zuu »

Roujin wrote:And the wiki seems the best place for me to do that ;)
I've already started on a list "User AIs" at the bottom of the main NoAI page, thought no one have continued on it. But it would be nice if more people added their AIs there with simply the name and a link to the forum post with download. If you want to do something more than just a simple list with forum links your free from my point of view to reorganize it.

So yea, good idea hopefully more will add their AIs there. :)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: NoAI Branch - An AI Framework

Post by Mchl »

GeekToo: I've found you a theme song for Convoy ;)
http://www.youtube.com/watch?v=r-VcU89usjM
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NoAI Branch - An AI Framework

Post by Hirundo »

After some more testing on the signs problem, its seems that the problem doesn't always occur. In the picture for example, one can see that two of the signs showed the correct text. Four incorrectly showed "Apollo". The last one is the strangest however. "Town is too small" is a string I only use in AILog.Info("Town is too small"); How it ends up as a sign is a mystery to me ?(
Swallow wrote:Is it possible to read the values of difficulty or patch settings? IMO Important settings to know are for example the plane speed factor, whether it is allowed to build bus stops on town roads or not, realistic cachement area and breakdowns.
Any comments on this?
Attachments
weird signs.png
weird signs.png (72.77 KiB) Viewed 1260 times
Create your own NewGRF? Check out this tutorial!
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoAI Branch - An AI Framework

Post by Zuu »

Try writing an AI that simply places signs on perhaps town center tiles.

If that gives you correct signs, then there is something wrong with your AI. Try removing parts one by one from it to localize the problem.

If however your minimal sign placing AI also gives you bad signs, post it here so we can have a look at it.

By posting a minimal AI that demonstrates something you think might be a bug you'll faster get help than if you simply publish your WIP AI and ask people to debug the entire thing.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

I've updated Convoy ( download in my previous post: http://www.tt-forums.net/viewtopic.php?p=693171#p693171)

-solved the bug reported by Mchl ( btw nice theme, we should build an AVI player in OTTD :D )
-improved the way buses take their initial route: one half to one station, the others to the other station. This improves the queing
(reported by Mchl and FinalDeath)
-improved the loan management, it continues building when it has money, instead of waiting a couple of hundred ticks
-added some improvements to the pathfinding
-added error handling during pathfinding, so the trick Roujin reported ( buying land, while the AI is building roads, should be solved).
I've not worked on the route checking yet, so football stadiums still are a problem. I have to find a way to solve this elegantly.

Overall, the performance is about 30 percent better, I ran a test against wright, and managed to stay ahead of it at least 3 years (
then I stopped the test)

Thanks for the feedback guys, keep it coming! There's a lot to improve still
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NoAI Branch - An AI Framework

Post by Hirundo »

Zuu wrote:Try writing an AI that simply places signs on perhaps town center tiles.
The AI I posted few posts back did just that. (Actually I labeled it WIP because it did nothing else but placing signs on town centers) I do realize that less code = better when it comes to bugfixing. So I cut away some unneccessary parts and added comments to (hopefully) explain what's going on.

The problem still happens though, albeit less frequently. Sometimes all the signs are correct, sometimes almost half of them are wrong. I also output the strings to the AI Debug window, but they always show correctly there.

The sign placing code can be found in main.nut, line ~30
Attachments
Apollo_stripped.zip
(1.65 KiB) Downloaded 103 times
Create your own NewGRF? Check out this tutorial!
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Odd, I've never had a problem with signs, and I've been testing the AIList stuff with regards to finding locations to build, placing the coordinates, and it did thousands on the same map fine (sometimes many on one tile, heh) although it was slow :)

Had a quick look and I've no idea why the signs don't place right (or rather, they randomly are Apollo...hmmm).
Finaldeath
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests