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

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin »

reylas wrote:Oh, cool. I understand completely. It totally escaped me that it would be Pounds. I use Dollars.

So, the reason being was that I was trying to do something like - If I have more than 50,000 dollars, then look to build. I showed 70,000 dollars in the game screen, but the AI function showed ~35000. So my function would not look to build even though the company info screen showed way more.

May I ask what the conversion rate is the game uses? Is it exactly double?

Sorry for such basic questions.

MarkS.
Hm, I wanted to direct you to the wiki page, but it turns out that page doesn't have the information at all :? http://wiki.openttd.org/index.php/Currency

So, I'll test it myself:

Code: Select all

Pounds: 1x
Dollars: 2x
Euro: 2x
Yen: 220x
ATS: 20x
BEF: 59x
CHF: 2x
CZK: 41x
DEM: 3x
DKK: 11x
ESP: 245x
FIM: 9x
FRF: 10x
GRD: 500x
HUF: 378x
ISK: 130x
ITL: 2850x
NLG: 3x
NOK: 12x
PLN: 6x
ROL: 5x
RUR: 50x
SIT: 352x
SEK: 13x
YTL: 3x
SKK: 52x
BRL: 4x
Maybe you could add it to that wiki page? I got no time right now, gotta go..
* @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
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Added to Wiki page. Thanks!.

Marks
User avatar
paullb
Traffic Manager
Traffic Manager
Posts: 129
Joined: 19 May 2008 13:11

Re: NoAI Branch - An AI Framework

Post by paullb »

TrueLight wrote:
Zutty wrote:
Still though, a good idea.

What do you think of a "AI:Library" page for the AI section? There could be a different section for each type of algorithm or code snippet, and then each developer could add their own take on the problem, in a standard format. Im thinking something like, authors name, a short description, maybe some stats, and a link to a page with the full details and the actual code.

Thoughts?
Sounds like a plan! Make a draft, and we see how it goes :)
Draft page created.

http://wiki.openttd.org/index.php/AI:Library
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Quick request; does doxygen allow a downloadable API documentation to be created? (like a zip or tar of the HTML files). After not being able to connect to the API doc just a little while tonight (which might be my ISP, who knows) I thought an offline version would be nice for offline work :)

(Wiki pages would be worth having as offline versions, only if we added a lot more to them :) ).

This is pretty please :D and would also save some bandwidth, and is faster for us too :) so benefits all round, apart from the "redownloading when it's updated" part ;)

(I also have no idea if it is possible, sorry, never used doxygen!)
Finaldeath
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

Not sure if this is a bug, or just how valuators behave, but you can't do this

Code: Select all

//set up a class with a valuator function
class foo
{

number = null;

constructor(bar)
{
number = bar;
} 

function compare(index)
{
if(index > number) return true;
return false;
}
}//finish class

//now create an instance of foo and use the function

local fooinstance = foo(10);
local towns = AITownList();

towns.Valuate(fooinstance.compare);
The vaulator line will fail with index number does not exist. It seems when you call an instance function as a valuator, the class function (foo.compare) is called rather than the instance one (fooinstance.compare), hence it cannot access instance variables, I guess a workaround is to pass the instance in as a parameter, but its not very neat.

Forgive me if this has come up before/is just the way things work.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Ralph wrote:Not sure if this is a bug, or just how valuators behave, but you can't do this

(...)

The vaulator line will fail with index number does not exist. It seems when you call an instance function as a valuator, the class function (foo.compare) is called rather than the instance one (fooinstance.compare), hence it cannot access instance variables, I guess a workaround is to pass the instance in as a parameter, but its not very neat.

Forgive me if this has come up before/is just the way things work.
Too bad this can't work. If you call 'fooinstance.compare', on the stack really is pushed foo.compare, and the instance it belongs to is lost (for ever). Therefor, the Valuator function has no way of knowing which instance 'fooinstance' is. To avoid strange crashes and other Squirrel related stuff, the 'list' instance is sent as 'this' (yes, VERY bad, I know, but there is no other way for now). I looked at the code, looked in the stack, and in many other places, but I see no way to solve this problem now or in the near future ... so for now I suggest not using such functions, and give the 'number' as extra param (like in the examples). The function in the Valuator is STATICly called, and should be handled as such :)
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 »

Finaldeath wrote:Quick request; does doxygen allow a downloadable API documentation to be created? (like a zip or tar of the HTML files). After not being able to connect to the API doc just a little while tonight (which might be my ISP, who knows) I thought an offline version would be nice for offline work :)

(Wiki pages would be worth having as offline versions, only if we added a lot more to them :) ).

This is pretty please :D and would also save some bandwidth, and is faster for us too :) so benefits all round, apart from the "redownloading when it's updated" part ;)

(I also have no idea if it is possible, sorry, never used doxygen!)
Doxygen comes with a tool called doxywizard. It is quite easy to use, as you only need to load 'Doxyfile' which comes with OTTD source (when checked out from SVN), and click on 'Start'. Be warned: there are two Doxyfiles in NoAI branch. One for general OTTD docs, and one for NoAI API (you'll need to dig into directory structure a little more for this one).
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Yeah, it's a request to have it automated, I knew I could do it myself somehow (hell, if I had to I could manually look at the games source code right?). At some point it'd nice to have it automated into some downloadable version whenever the online version is rebuilt.

Saying the AI developer must download the game's source is something to avoid not applaud ;)
Finaldeath
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

I'm trying to put some example code on the library page of the wiki. Two questions...

1) Can we have somewhere to upload NUT files to for the library section. Its not very practical to paste the code into the Wiki, and it doesn't support uploading of non-image files. Plus I don't have any web space of my own.

2) How do I release something under the GPL? Do I need to include the full text of the license?
PathZilla - A networking AI - Now with tram support.
User avatar
Roest
Traffic Manager
Traffic Manager
Posts: 215
Joined: 03 Apr 2008 08:18

Re: NoAI Branch - An AI Framework

Post by Roest »

Zutty wrote:Plus I don't have any web space of my own.
free 100 MB
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

Roest wrote:
Zutty wrote:Plus I don't have any web space of my own.
free 100 MB
Woah! How could I not know about this?!?! Thanks :)
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

A while ago I told you guys I was working on a tournament system. Today I finally finished it. I ran a few games, with some AIs I had on my disk. I tried different rule-sets to get a base-line. It turns out that most AIs totally fail when the cost are set HIGH. Air can't even start when you can't get a high enough loan ;) Anyway here it goes:

http://devs.openttd.org/~noai/tournament/

If you want your AI benchmarked against the others, please send me a .tar file with your AI in it. For now I won't make a website to upload your AI, as that takes too much time, and I will run the benchmark on demand. So .. let the fight begin :)
The only thing necessary for the triumph of evil is for good men to do nothing.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin »

That, dear TrueLight, is purely awesome! :shock: Especially these animated .gifs - I can't even imagine how you've managed to do something like this.

:bow:

I'm just wondering why Convoy and Apollo seem to fail completely on your runs so far. I can't really extract out of the .gifs what was wrong with them... ?(

edit: analyzing a log of a game with Convoy, it seems to have encountered an error in the script and killed itself. That explains it somehow...
edit2: strange though.. when I tested Convoy shortly ago, it didn't make any errors afaik.. but there were API changes recently, so maybe that's the cause..
* @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
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

This is very, very cool indeed. :bow: Too bad Convoy did kill itself. What version did you use: 1.0 or 1.1, as the v1.0 did kill itself rather quickly, and some bugs were solved in v1.1. I've been working on Convoy, I'll send a v1.2 one of these days.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

It is nice to see you guys are so happy with this :)

I used Convey 1.1, but with latest SVN. Don't know if that is any problem... Or anyway, I pressed the Download link on the wiki page, I assumed it pointed to 1.1 :) Well, let me know when you have 1.2 ;)

And Apollo doesn't really do anything, so it is supposed to loose ;)

Btw, bankruptcy is disabled for this tournament, so AIs go on for 10 years, no matter what :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

Or anyway, I pressed the Download link on the wiki page, I assumed it pointed to 1.1
Depends on when you pressed it, I updated the link yesterday or friday
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

GeekToo wrote:
Or anyway, I pressed the Download link on the wiki page, I assumed it pointed to 1.1
Depends on when you pressed it, I updated the link yesterday or friday
Well, I downloaded it a few hours ago, so I had the latest ;)
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 »

Did you know the NoAI API currently contains 394 API functions?

Did you know you most likely use 60% of that when designing any Road AI?

And that it will increase with 20% when adding Rail support?

This is getting big ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Another question about IsWithinTownInfluence. If I use AIStation.IsWithinTownInfluence, it works. But If I use AITile.IsWithinTownInfluence, I get an index IsWithinTownInfluence does not exist.

Is that a bug or am I using it wrong.

Area.Validate(AITile.IsWithinTownInfluence,current_town);

Thanks,
MarkS
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: NoAI Branch - An AI Framework

Post by DaleStan »

Zutty wrote:2) How do I release something under the GPL?
You do what it says to do on http://www.gnu.org/licenses/licenses.html
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 18 guests