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
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

@truelight
I copied this comment from order_cmd.cpp. I thought it would be a good thing if the comments were consistent over all the code, but I must admit that I also had some problems to understand what it wanted me to tell :) I now changed it and hope that it is a bit more understandable.
For the LowerRaiseTile patch I defined all SLOPE_* in squirrel.
And finally I used svn diff instead of the linux diff command.

@ac84 and @saint
When those functions finally exists that might be a good idea. But when I think about it I come to another question. Where do we want to integrate further intelligence, like finding a suitable place for an airport or pathfinding. If we build this in C(++) it would be real fast and powerfull, but if we build this in squirrel people could more easily change it and they would include it as library into their ai.
If this question is cleared I could create a function that finds a suitable place for building. So an ai-programmer doesn't have to search for it himself. If I remember right there also was a pathfinder available.

EDIT:
I changed LowerRaise.patch to include the enumeration of SLOPE_*. This way it is included in the noai doxygen docu and it will be automatically copied to the squirrel files.
Attachments
MoveOrder.patch
(2.65 KiB) Downloaded 53 times
LowerRaiseTile.patch
(7.95 KiB) Downloaded 56 times
Last edited by dynaxo on 14 Oct 2007 17:49, edited 1 time in total.
As you may presently yourself be fully made aware of, my grammar sucks
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 »

saint wrote: If/when I do continue (which I would like to :wink: ), it seems that a reasonable framework/helpers to do the basics such as in Clueless (impressive work Zuu!) is a must in all AI's, adding to the work we need to do to ensure the rest of the AI is easier to code.
Thanks for the nice words about Clueless. :)

Though Clueless was written just after NoAI was made public. Back then tile lists and other neat features that your AI will benefit from where not available in the NoAI branch.

Good luck with your AI when you continue. :)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
rabbit67890
Engineer
Engineer
Posts: 72
Joined: 23 Sep 2007 09:57

Re: NoAI Branch - An AI Framework

Post by rabbit67890 »

what programing language are we useing ?( ?(
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

rabbit67890 wrote:what programing language are we useing ?( ?(
OpenTTD is programmed in C/C++ while the ai's get programmed in squirrel
As you may presently yourself be fully made aware of, my grammar sucks
rabbit67890
Engineer
Engineer
Posts: 72
Joined: 23 Sep 2007 09:57

Re: NoAI Branch - An AI Framework

Post by rabbit67890 »

can i build a ai in c++
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 »

dynaxo wrote:
rabbit67890 wrote:what programing language are we useing ?( ?(
OpenTTD is programmed in C/C++ while the ai's get programmed in squirrel
rabbit67890 wrote:can i build a ai in c++
As a second option you can also make your AIs using pure C++, though the API development is mainly targeted to squirrel, even if it is accessible from C++ AIs too.

Some links that might be of interest:
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
rabbit67890
Engineer
Engineer
Posts: 72
Joined: 23 Sep 2007 09:57

Re: NoAI Branch - An AI Framework

Post by rabbit67890 »

Zuu wrote:
dynaxo wrote:
rabbit67890 wrote:what programing language are we useing ?( ?(
OpenTTD is programmed in C/C++ while the ai's get programmed in squirrel
rabbit67890 wrote:can i build a ai in c++
As a second option you can also make your AIs using pure C++, though the API development is mainly targeted to squirrel, even if it is accessible from C++ AIs too.

Some links that might be of interest:
how do i install squirrel :?:
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 »

rabbit67890 wrote:how do i install squirrel :?:
Squirrel is integrated in OpenTTD.

Please read the wiki to get started and then if something is unclear I'd like to recommend the OpenTTD IRC channel #openttd on irc.oftc.net. Or ask here, but please take you some time and read the stuff on the wiki, it is not more than a few pages to get though but it will get you started.

[Edit: changed IRC network to the correct one. - The network name is in my fingers only when I'm in a IRC client, not in my head.. :) - Thanks for reminding me glx! ]
Last edited by Zuu on 14 Oct 2007 06:06, edited 2 times in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
rabbit67890
Engineer
Engineer
Posts: 72
Joined: 23 Sep 2007 09:57

Re: NoAI Branch - An AI Framework

Post by rabbit67890 »

EDIT
zip file made
ANOTHER EDIT
i made it with c++
Attachments
rabbits ai.zip
my new ai
(3.14 KiB) Downloaded 81 times
Last edited by rabbit67890 on 13 Oct 2007 21:57, edited 1 time in total.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: NoAI Branch - An AI Framework

Post by glx »

Zuu wrote:I'd like to recommend the OpenTTD IRC channel #openttd on quakenet.
The channel is not on quakenet, it's on oftc.net ;)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

rabbit67890 wrote:EDIT
zip file made
ANOTHER EDIT
i made it with c++
Although C++ really isn't a problem to make your AI in, it is harder for people to try out your AI. They need to compile OpenTTD them self, which most users simply can't. As SQ (Squirrel) looks very similar to C++, I really do advise you to take a look at it. The benefit of it is that you can share your AI with many people, by simply putting the files in the right directory.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: NoAI Branch - An AI Framework

Post by Bilbo »

TrueLight wrote: Although C++ really isn't a problem to make your AI in, it is harder for people to try out your AI. They need to compile OpenTTD them self, which most users simply can't. As SQ (Squirrel) looks very similar to C++, I really do advise you to take a look at it. The benefit of it is that you can share your AI with many people, by simply putting the files in the right directory.
Yes, but with C++ you can use existing libraries (like for neural networks or such stuff) - re-implementing NN in squirrell may be quite lengthy work. Also, while it may not be tryable by others without recompiling, it may be some candidate for new default AI in trunk ...

There is some set of functioins exported to squirrell, so you can also use these directly from C++

Both approaches (C++ and Squirrell) have its advantages and disadvantages...
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

dynaxo wrote:@truelight
I copied this comment from order_cmd.cpp. I thought it would be a good thing if the comments were consistent over all the code, but I must admit that I also had some problems to understand what it wanted me to tell :) I now changed it and hope that it is a bit more understandable.
For the LowerRaiseTile patch I defined all SLOPE_* in squirrel.
And finally I used svn diff instead of the linux diff command.
Sorry about the delay, but finally added in SVN. Nice job, and thanks a lot :)
The only thing necessary for the triumph of evil is for good men to do nothing.
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

Hi, AI people.

I see work halted from May'07... too bad if project dies like this -(
We need at least "AIRail" class similar to AIRoad to be able build AI that use trains (most AI new developers wants this)...

Please do it, thanks.

I'll publish my AI, that beats yours then -)
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: NoAI Branch - An AI Framework

Post by DaleStan »

Why don't you publish your AI first? That way people have something look at encourage them to try to beat it.
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
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

DaleStan wrote:Why don't you publish your AI first? That way people have something look at encourage them to try to beat it.
I'm working on it. I found that AI API haven't necessary functions even for trucks :(
How can I get list of industries which accepts particular cargo?
How can I get Vehicle capacity, speed, reliabilty?
It need to be done before new people like me can write an AI.
Kilinich
Engineer
Engineer
Posts: 10
Joined: 18 Oct 2007 10:58
Location: Moscow, Russia

Re: NoAI Branch - An AI Framework

Post by Kilinich »

I think we need some more:

new AIEngine class with functions like this:
char * GetEngineName (EngineID engine_id)
cargo_id GetEngineCargo (EngineID engine_id)
uint32 GetEngineCapacity (EngineID engine_id)
uint32 GetEngineReliability (EngineID engine_id)
uint32 GetEngineMaxSpeed (EngineID engine_id)
bool IsValidEngine (EngineID engine_id)

add to AIIndustry class:
bool IsAcceptingCargo (IndustryID industru_id, CargoID cargo_id)

new valuator:
AIIndustryListAccept (CargoID cargo_id)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Kilinich wrote:I think we need some more:

new AIEngine class with functions like this:
char * GetEngineName (EngineID engine_id)
cargo_id GetEngineCargo (EngineID engine_id)
uint32 GetEngineCapacity (EngineID engine_id)
uint32 GetEngineReliability (EngineID engine_id)
uint32 GetEngineMaxSpeed (EngineID engine_id)
bool IsValidEngine (EngineID engine_id)

add to AIIndustry class:
bool IsAcceptingCargo (IndustryID industru_id, CargoID cargo_id)

new valuator:
AIIndustryListAccept (CargoID cargo_id)
Most of those functions are already handled via AIVehicle::FindBestVehicle. IsValidEngine is already in AIVehicle. Nevertheless, I see no problem in adding some more functions, and list-valuators, to allow easy finding the best engine.
The only thing necessary for the triumph of evil is for good men to do nothing.
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

TrueLight wrote:Sorry about the delay, but finally added in SVN. Nice job, and thanks a lot :)
My pleasure. My next patch will introduce two events for vehicles that are waiting at a station and that are entering a station. There will also be a function to get the count of waiting vehicles at a station.
As you may presently yourself be fully made aware of, my grammar sucks
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

dynaxo wrote:
TrueLight wrote:Sorry about the delay, but finally added in SVN. Nice job, and thanks a lot :)
My pleasure. My next patch will introduce two events for vehicles that are waiting at a station and that are entering a station. There will also be a function to get the count of waiting vehicles at a station.
Sounds awesome :) I created a catagory on FlySpray for NoAI patches, please post them there :) (http://bugs.openttd.org, post as Patch, under NoAI).
The only thing necessary for the triumph of evil is for good men to do nothing.
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 12 guests