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
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Post by griffin71 »

Zuu wrote:EDIT: I guess you wanted to remove NoAI so that you're AI become the only AI because of the issue described above. If your reasons are other, I'm sorry I've misinterpreted you.
Thank you, Zuu, correct. With the link that XeryusTC provided, I recompiled openttd, so the problem was already solved. Maybe I'll use your commandline solution from now on, because then I don't have to wait until it starts.

I have been playing around today with Squirrel, and I started writing a routine that would return me two towns that are close together, and have a high number of potential passengers. Initially, I took the populations for it, but because XeryusTC gave me the link to the sourcefiles, I decided to add the following functions, and give myself Squirrel access to them:

Code: Select all

uint32 GetMaxPass(TownID town_id);
uint32 GetMaxMail(TownID town_id);
uint32 GetNewMaxPass(TownID town_id);
uint32 GetNewMaxMail(TownID town_id);
uint32 GetActPass(TownID town_id);
uint32 GetActMail(TownID town_id);
uint32 GetNewActPass(TownID town_id);
uint32 GetNewActMail(TownID town_id);
byte GetPctPassTransported(TownID town_id);
byte GetPctMailTransported(TownID town_id);
This works fine, so I now use these functions to obtain the most recent number of passengers NOT transported from a town. Together with a good distance, that will be a good starting point for my AI to choose his first route. (Indeed, my AI is a male, as he does not and will not support multitasking ;-) )
I just wonder what

Code: Select all

GetPctPassTransported
GetPctMailTransported
actually signify. The town struct does not say anything in its comments about them. They seem some sort of percentage, but they often assume values over 100 in towns where there is transport. :?

As a final remark for today, I noticed that in certain cases openttd gives a runtime exception, and dies. This has been the case when the Squirrel script could not be compiled, but depends on the details. MSVC catches and asks to debug (keeping the windows open), so I could see that Squirrel was complaining about being unable to compile.

Thank you all for your answers.
A game worth playing is a game worth modding :-)
willisterman
Engineer
Engineer
Posts: 27
Joined: 16 Jun 2006 19:41

Post by willisterman »

Any hints/Tips on getting this compiled on Visual C++? I get the trunk running fine, but when compiling this branch, I get lots of errors.

Attached is build log:

Thanks.
Attachments
BuildLog.zip
(7.22 KiB) Downloaded 206 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

griffin71 wrote:... and have a high number of potential passengers. Initially, I took the populations for it, but because XeryusTC gave me the link to the sourcefiles, I decided to add the following functions, and give myself Squirrel access to them:

Code: Select all

uint32 GetMaxPass(TownID town_id);
uint32 GetMaxMail(TownID town_id);
uint32 GetNewMaxPass(TownID town_id);
uint32 GetNewMaxMail(TownID town_id);
uint32 GetActPass(TownID town_id);
uint32 GetActMail(TownID town_id);
uint32 GetNewActPass(TownID town_id);
uint32 GetNewActMail(TownID town_id);
byte GetPctPassTransported(TownID town_id);
byte GetPctMailTransported(TownID town_id);
This works fine, so I now use these functions to obtain the most recent number of passengers NOT transported from a town. ...
Using the amount of NOT transported passengers sounds like a good way to make an AI that don't (mostly) use the same cities as all other instances of the same AI.

Each instance of my AI keep track of which cities it have connected and don't connect a single city twice. But if I have 7 instances of my AI cities become quite crowdy of road-stations and road-depots. (I'm only using population and distance for rating city relations.)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
willisterman
Engineer
Engineer
Posts: 27
Joined: 16 Jun 2006 19:41

Post by willisterman »

Still not been able to get it to compile in Visual Studio, so switched to MinGW + Msys, and its working fine.

As has been mentioned before, to really get it working well, I've had to add my functions to the source, as I need access to the towns passenger and mail infomation, not just population. Will these be added in the branch, as I dont want to keep adding redundant infomation.
User avatar
Maedhros
OpenTTD Developer
OpenTTD Developer
Posts: 603
Joined: 30 Mar 2006 18:24
Location: Durham, UK

Post by Maedhros »

willisterman wrote:As has been mentioned before, to really get it working well, I've had to add my functions to the source, as I need access to the towns passenger and mail infomation, not just population. Will these be added in the branch, as I dont want to keep adding redundant infomation.
I imagine if you (or griffin71) provide a patch they'll be added more quickly...
No-one's more important than the earthworm.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Post by glx »

willisterman: for your problem with VC7, I think it's because none of the devs tried to compile with this version (it compiles fine with 2005, ie VC8)
willisterman
Engineer
Engineer
Posts: 27
Joined: 16 Jun 2006 19:41

Post by willisterman »

Ah, its not too much of a problem, as I said, but I've not got round to switching to VC8, dont want to spend any time fixing any problems with my programs.

I can provide diffs for what I've done, but my coding style isnt great, and I know a few others had done the same thing, so I'll let theirs get using instead.

One thing I'm interested in, is finding out if I can share an array between AI's. At the moment, I build up a list of the end-points of a town using a recursive agorithim, but with a few AI's, they are going to want to scan the same town. I'd like it if the array was available by all, and they just check if the endpoints are current, instead of doing a full scan.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

willisterman wrote:(..)

One thing I'm interested in, is finding out if I can share an array between AI's. At the moment, I build up a list of the end-points of a town using a recursive agorithim, but with a few AI's, they are going to want to scan the same town. I'd like it if the array was available by all, and they just check if the endpoints are current, instead of doing a full scan.
This isn't possible in SQ, and shouldn't be done at all. It is bad policy. Every AI should be 100% stand-alone, and not share data with an other.

Say, for the matter of argument, that it is possible. Many problems and questions arise, but okay, one of the main problems: I want my AI to battle your AI. I know that you use a shared array, so I corrupt it. Therefor your AI dies very fast, and mine wins! HURRAY! Just one of the tons of arguments why it shouldn't be done :) (an other is, if 2 versions of your AI run, both using the same array in a different way, oh I can keep on going :)).

So you can store things per AI, that is no problem. Global storage won't be available, and shouldn't be used :) Just let all AIs scan again for theirself.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

I'd say it is possible. You just have to use something in the OpenTTD world to communicate between two AIs. That could be tough signs (both AIs can agree on useing sign no 3 as interface) or by construction and removing of road-bits on pre-set spots. Just the imagination limits the possibilities of communication methods. Yes, it is several hours of developing to make it work, but I say it is possible.

However I agree with TrueLight that AIs should be mostly stand-alone. (Edit: No global storage) This is also important since there are plans to allow AIs to be clients in multiplayer in future.

But I think it would be a fun experiment to make an AI that can communicate with another AI though signs, road-bits or whatever... :)


Edit2: Sending messages like, - "hey player 1 seams to be human, lets coop against him" :D
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Post by fabca2 »

Zuu wrote:I'd say it is possible. You just have to use something in the OpenTTD world to communicate between two AIs. That could be tough signs (both AIs can agree on useing sign no 3 as interface) or by construction and removing of road-bits on pre-set spots. Just the imagination limits the possibilities of communication methods. Yes, it is several hours of developing to make it work, but I say it is possible.
or just a file. (I don't know if open/read/write/close file statements are allowed, if it is, that's easy...)
I also prefer to avoid shared data between AI... but if somebody really wants to have it I prefer he use something OUTSIDE of the "world of ottd" instead of sign or undocumented stuff :roll:
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

fabca2 wrote:
Zuu wrote:I'd say it is possible. You just have to use something in the OpenTTD world to communicate between two AIs. That could be tough signs (both AIs can agree on useing sign no 3 as interface) or by construction and removing of road-bits on pre-set spots. Just the imagination limits the possibilities of communication methods. Yes, it is several hours of developing to make it work, but I say it is possible.
or just a file. (I don't know if open/read/write/close file statements are allowed, if it is, that's easy...)
I also prefer to avoid shared data between AI... but if somebody really wants to have it I prefer he use something OUTSIDE of the "world of ottd" instead of sign or undocumented stuff :roll:
File access is not possible, none of the standard library functions of squirrel are available in OpenTTD partly because of portability problems as far as I am aware. Some math-functions have manually been added by the devs though.

Also remember, multiplayer compability.

As of now only communication though stuff in the "world of ottd" is possible. That is not the same as saying that that is how it will work when NoAI matures. A reasonable way would be to use the private chat functionality to communicate between AIs if there arises a need to have communication between AIs, aka if someone finds it interesting to develop a such AI.

It might be that a communicating AI would be baned from many servers, that is possible. But that does not stop people from finding it an interesting though to experiment with such things.

To be reasonable I think most AIs will be constructed as stand-alone AIs. And there is nothing to fear as AIs are modular and you don't have to use them if you don't like them.

But let's stop the political talk and wait and see what happens. :)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
antichaos
Engineer
Engineer
Posts: 42
Joined: 13 Feb 2007 21:51
Location: UK

Post by antichaos »

Zuu wrote:A reasonable way would be to use the private chat functionality to communicate between AIs if there arises a need to have communication between AIs, aka if someone finds it interesting to develop a such AI.
Interesting tactic - create an AI with enough natural language ability to be able to convince a human player to divulge the password to his company, then steal it. :)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

Bug: Company name can only be set once. After that it is impossible to set another name.

Attached a small AI that demonstrates this.
Attachments
main.nut.txt
(1.67 KiB) Downloaded 242 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

Zuu wrote:Bug: Company name can only be set once. After that it is impossible to set another name.

Attached a small AI that demonstrates this.
The code says: (src/ai/api/ai_company.cpp)

Code: Select all

bool AICompany::SetCompanyName(const char *name)
{
	if (name == NULL) return false;

	_cmd_text = name;
	return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME);
}
Most notable is that it sets the president-name which explains why "Transport" is appended automatically. Changing "CMD_CHANGE_PRESIDENT_NAME" to "CMD_CHANGE_COMPANY_NAME" fixes the bug.
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

Post by TrueBrain »

Zuu wrote:
Zuu wrote:Bug: Company name can only be set once. After that it is impossible to set another name.

Attached a small AI that demonstrates this.
(..)

Most notable is that it sets the president-name which explains why "Transport" is appended automatically. Changing "CMD_CHANGE_PRESIDENT_NAME" to "CMD_CHANGE_COMPANY_NAME" fixes the bug.
Fixed, and added [SG]etPresidentName(). Tnx :)
The only thing necessary for the triumph of evil is for good men to do nothing.
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

TrueLight wrote:
Zuu wrote:
Zuu wrote:Bug: Company name can only be set once. After that it is impossible to set another name.

Attached a small AI that demonstrates this.
(..)

Most notable is that it sets the president-name which explains why "Transport" is appended automatically. Changing "CMD_CHANGE_PRESIDENT_NAME" to "CMD_CHANGE_COMPANY_NAME" fixes the bug.
Fixed, and added [SG]etPresidentName(). Tnx :)
That was fast, thanks :)
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

Now that we are talking about AICompany then i think these functions could be somewhat usefull, but its not high priority.

[GS]etPlayerFace()
[GS]etColourscheme()
getHQLocation()
relocateHQ()
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Clueless goes public!

Post by Zuu »

[edit]
WARING this versioun of Clueless need r9591
Does not work with current revision (r11311)
[/edit]

Clueless is the AI I've been working on since some time ago. I had to take a break because of exam studies last week, but now I've fixed some stuff and decided that it is time to release it.

The strongest part of Clueless is that it makes money if the map is not to hostile and can reuse existing road.

The weakest part of Clueless is by no doubt that it's road-builder can't get around bigger things like industries.

How do I test it?
* Get noai-branch (r9591)
* Get Clueless
* Start openttd like this:

Code: Select all

./openttd -a "Clueless"
* Turn off build-on-slopes!
* Play on a flat map, with low sea-level. Also it should have low amount of towns and no industries.
* Press fast-forward and wait
* Enjoy!

Reading the code
If you use VIM and don't know how to get color-highlighting on .nut-files, don't worry check out my old post which will help you with that.

Yay, and enjoy Clueless :)
Attachments
clueless.zip
Contains the Clueless AI. :)

Unpack and place in your bin/ai/ directory. To use the included run.sh starter you have to stand in the bin-directory, and execute it from there.

My test-scenario is also included.
(56.12 KiB) Downloaded 291 times
overveiw.png
Compared to the result of Clueless on page 4 of this thread it have become quite a lot better. Both better looking networks and more profit.
(171.8 KiB) Downloaded 224 times
When building road-stations Clueless build all alternatives and then remove all but the best one. This is a design choice for security. I know some "players" might find it ugly, however it would require quite a lot of code to make a less ugly so
When building road-stations Clueless build all alternatives and then remove all but the best one. This is a design choice for security. I know some "players" might find it ugly, however it would require quite a lot of code to make a less ugly so
extra.png (212.65 KiB) Viewed 6611 times
Last edited by Zuu on 22 Nov 2007 10:04, edited 1 time in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Post by kaan »

I have looked at the clueless AI and it looks like a solid peice of work. I hope you dont mind if the rest of us steals some code in there ;)

I have one question though: Does squirrel demand that all classes are in one file?
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

kaan wrote:Now that we are talking about AICompany then i think these functions could be somewhat usefull, but its not high priority.

[GS]etPlayerFace()
[GS]etColourscheme()
getHQLocation()
relocateHQ()
1) who cares about faces. Absolutely no priority what so ever
2) colors might be made possible in the near future
3) HQ location should be easy to add, will keep it in mind
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 7 guests