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

Re: (AI naming error)

Post by griffin71 »

TrueLight wrote:(...)
With a big thanks to glx, it should now be fixed in latest SVN. We used memory when it was already free'd, only MSVC had problems with that :)
Indeed, the problem is now solved. Many thanks.
Strange to say that the problem only occurred if you configure MSVC for building the project openttd for debug. Building project openttd for release did not have that problem. I found that out today, but now it's fixed! :-)
A game worth playing is a game worth modding :-)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

As of today, we added WrightAI, a simple airport AI that is pretty good in what he does. Is meant as example code for others to see how an AI possibly can be done. Feel free to use any code of it, as long as you remember it is GPL licensed :)
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 »

could you describe in a few words how WrightAI acts? :) purely out of interest :)
* @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
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

It makes a list of all the towns, remove any town already used, sort by population, pick the top 10 from that list and sorts them randomly.
It walks all those towns trying to find a suitable spot for an airport in a 30x30 radius.
It repeats that, to found a second town, trying to keep a minimum distance of 25 between the 2 towns.

It builds the airports. It builds an airplane. It waits.

After 2 years it checks if the airplane makes enough profit. If not, it sells the airplane. If all airplanes are sold for a route, it sells the airports.
When there is 250+ cargo on a station, and no new vehicle in the last <distance between stations> days, it buys a new vehicle.

When possible, it pays back its loan, if needed, it gets a loan.

It builds a new route every 1000 ticks.

I think that covers it all :) It is really simple. One side-note though: currently you have to start it in the year the City Airport is available, else it won't be able to do anything :) Something we are working on :)
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: It walks all those towns trying to find a suitable spot for an airport in a 30x30 radius.
It repeats that, to found a second town, trying to keep a minimum distance of 25 between the 2 towns.
25 is way too little for airports. When I was improving the airport distances in default AI, I end up with optimal distance being 10000 tiles for concorde-like planes and 400 for 947km/h planes (and 2000 for those old slow ones.)

So I ended up with max. distance being equal to optimum distance and min. distance being equal to half of map size, clamped between 1% and 20% of optimal size (which may prevent building airports on tiny maps, but planes would suck on such small distances anyway). So concorde route will never get under 100 tiles for example ...
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)
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: NoAI Branch - An AI Framework

Post by Zephyris »

What sort of method is being used to select the optimum vehicle for a route, as the most expensive is not always the best for a route. A method which calculates vehicle suitability will have to directly access vehicle properties (for full, automatic, newgrf support). Has anyone been thinking about this?
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: NoAI Branch - An AI Framework

Post by MagicBuzz »

TrueLight wrote:After 2 years it checks if the airplane makes enough profit. If not, it sells the airplane. If all airplanes are sold for a route, it sells the airports.
When there is 250+ cargo on a station, and no new vehicle in the last <distance between stations> days, it buys a new vehicle.
2 years : it should be variable according the vehicules speed and route distance. something like "(10 x distance) / speed" should be a better approach : short routes with high speed vehicules will be checker ealier.

250+ : it should be something like <vehicule capacity> * 1.5 instead of a fixed value. thus, the station rating should be took into account : 10 units of goods waiting at a station with a "very poor" rating is normal, as goods won't wait for long at a station with a bad rating. increasing the traffic will raise the rating and help getting more goods.

<distance between stations> days : you convert a distance to days ? should be a little more* than (2 * distance / speed) days
* : to ensure the lasted build vehicule got time to come back and load again, so we can be sure it isn't enougth.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

MagicBuzz wrote:
TrueLight wrote:After 2 years it checks if the airplane makes enough profit. If not, it sells the airplane. If all airplanes are sold for a route, it sells the airports.
When there is 250+ cargo on a station, and no new vehicle in the last <distance between stations> days, it buys a new vehicle.
2 years : it should be variable according the vehicules speed and route distance. something like "(10 x distance) / speed" should be a better approach : short routes with high speed vehicules will be checker ealier.

250+ : it should be something like <vehicule capacity> * 1.5 instead of a fixed value. thus, the station rating should be took into account : 10 units of goods waiting at a station with a "very poor" rating is normal, as goods won't wait for long at a station with a bad rating. increasing the traffic will raise the rating and help getting more goods.

<distance between stations> days : you convert a distance to days ? should be a little more* than (2 * distance / speed) days
* : to ensure the lasted build vehicule got time to come back and load again, so we can be sure it isn't enougth.

So I smell a patch coming up. Can't wait :)

(nobody claimed the AI was finished or perfect :) It is just a draft how it can be done :) So please, feel free to modify it in any way to increase the performance of it!)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Re: NoAI Branch - An AI Framework

Post by Nickman »

I'll be looking into this branch, it is looking really interesting to me.

I'll take a look at the code currently available and try and build my very own AI in the future ;).

Keep up the great work!!
Youri219
Traffic Manager
Traffic Manager
Posts: 191
Joined: 28 Apr 2007 11:53

Re: NoAI Branch - An AI Framework

Post by Youri219 »

Question about ariports/airplanes.

Lets assume the AI has setup a route between towns A and B, and another one between C and D. If both town A and C have many people waiting at the airport, will the AI buy an airplane between these towns currently, or is it maybe you want to implement later?

Another (probably to advanced right now) nice option would be 'feeder' bus/tram/train lines, which supply an airport with additional passengers which would otherwise be outside the catchment area.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Youri219 wrote:Question about ariports/airplanes.

Lets assume the AI has setup a route between towns A and B, and another one between C and D. If both town A and C have many people waiting at the airport, will the AI buy an airplane between these towns currently, or is it maybe you want to implement later?

Another (probably to advanced right now) nice option would be 'feeder' bus/tram/train lines, which supply an airport with additional passengers which would otherwise be outside the catchment area.
Currently I do not have plans to do either one, although I do hope some user picks up this AI and makes it even better. It is currently more meant as show-case, to show people it can be done. Also it helped me a lot finding missing functions and features of NoAI, which hopefully are now all there.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Re: NoAI Branch - An AI Framework

Post by Nickman »

Is it possible to give an example of a C++ AI TrueLight?

Actually, I just need to know wich files to inlcude :).
The wiki doesn't state this so...

I tried by including ai_factory.hpp but that wasn't sufficient?

------------

Ok, I found out what to include and stuff (I took a look at the NoAI.hpp and NoAI.cpp files) and my very own AI is working and can be started by the game.

Now, I used the following code to name the different AI's:

Code: Select all

	if (!this->company.SetCompanyName("TestAI")) {
		int i = 2;
		while (!this->company.SetCompanyName("TestAI #" + i)) {
			i = i + 1;
		}
	}
But ingame, my AI's get named like in the attachment.

Why could this be?

It's a little late now over here, but tomorrow I'll try to take a look at the API code to see if anything strange is going on in there.
Attachments
Naming is not like I programmed...
Naming is not like I programmed...
Strange_Naming.png (1.92 MiB) Viewed 693 times
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 »

I checked out the noAI and I noticed two things:

The default AI was ripped out. While it sucks (and cheats), it could be used to compare agains any new AI.

Also, since even when I set "opponents start immediately" (or if opponents are accidentally set up to appear later) it takes them a while to appear, I think some console command to immediately spawn a new AI player would be nice. Also it may be useful to tell which one (sometimes NoAI is spawned (which does nothing, I assume it is that testing AI that just loans random amount and print debugging stuff on ddebugging output :), sometimes WrightAI (which can make decent profit)
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)
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Re: NoAI Branch - An AI Framework

Post by Nickman »

Problem about the naming found thanks to the IRC channel ;).

Problem was that I was trying to append an int to a C style string, this resulted in a shift to the right.


-----

Another question :

Is it possible to acces a Squirrel script (like a pathfinder) inside my own C++ AI?
If so, how? :)
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 »

Bilbo wrote:Also it may be useful to tell which one (sometimes NoAI is spawned (which does nothing, I assume it is that testing AI that just loans random amount and print debugging stuff on ddebugging output :), sometimes WrightAI (which can make decent profit)
A GUI to manage AIs will be done later. We first want to finish the API.

And you can force an AI using -a switch when starting openttd.
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 »

glx wrote: A GUI to manage AIs will be done later. We first want to finish the API.

And you can force an AI using -a switch when starting openttd.
GUI is unnecessary, just a bunch of console commands would be fine :)

I'll try the -a switch...
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 »

Nickman wrote: Another question :

Is it possible to acces a Squirrel script (like a pathfinder) inside my own C++ AI?
If so, how? :)
No; SQ can access C++ things, but C++ can't access SQ like that. But it won't take really long before a road PF in C++ will be done (is work in progress).
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 »

Slowly more and more functions get done: the event system is now done. Of course it still misses tons of events you would like to get, but we are working on that :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Re: NoAI Branch - An AI Framework

Post by Nickman »

It is looking great ;).
I'll be on holiday from the end of the week, but I'll try to get my laptop in shape to make some AI stuff ;).

------

Is it possible to make the doxygen files downloadable in a zip file or something?
So I can take it with me where I want? :)
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: NoAI Branch - An AI Framework

Post by griffin71 »

TrueLight, I have a request for a function in the AIVehicle class:

Code: Select all

EngineID AIVehicle::GetEngineId(CargoID cargo, uint SequenceNum)
It should return an engine ID, or null.
SequenceNum will be an integer number, starting with zero. If only 1 engine is available for the cargoID, then that EngineID should be returned if Sequencenum == 0; if more are available, they should be returned when SequenceNum ==1, 2, ...; just as many as there are engines available.
In addition, a function that returns the Engine specs should be present, so that the AI can make a choice for the engine. (I just want to keep in mind that in the future, our great artists will almost surely design their own vehicle sets, and more than 1 good engine may become available for a certain type of cargo.)
Are there any plans for implementing this?

(I'm trying to derive some kind of empirical relation between engine type and how much hills slow them down. This is a preparation to the extension of my pathfinder to work in hills.)

Thanks!
A game worth playing is a game worth modding :-)
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Google [Bot] and 4 guests