Page 11 of 32
Re: (AI naming error)
Posted: 14 Jul 2007 17:02
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!

Re: NoAI Branch - An AI Framework
Posted: 15 Jul 2007 13:26
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

Re: NoAI Branch - An AI Framework
Posted: 15 Jul 2007 13:36
by Roujin
could you describe in a few words how WrightAI acts?

purely out of interest

Re: NoAI Branch - An AI Framework
Posted: 15 Jul 2007 13:40
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

Re: NoAI Branch - An AI Framework
Posted: 15 Jul 2007 14:54
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 ...
Re: NoAI Branch - An AI Framework
Posted: 15 Jul 2007 19:22
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?
Re: NoAI Branch - An AI Framework
Posted: 16 Jul 2007 13:41
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.
Re: NoAI Branch - An AI Framework
Posted: 16 Jul 2007 20:42
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!)
Re: NoAI Branch - An AI Framework
Posted: 16 Jul 2007 21:27
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!!
Re: NoAI Branch - An AI Framework
Posted: 18 Jul 2007 10:21
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.
Re: NoAI Branch - An AI Framework
Posted: 18 Jul 2007 10:57
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.
Re: NoAI Branch - An AI Framework
Posted: 18 Jul 2007 18:39
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.
Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 05:12
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)
Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 12:04
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?

Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 14:04
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.
Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 14:17
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...
Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 15:40
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).
Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 23:21
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

Re: NoAI Branch - An AI Framework
Posted: 19 Jul 2007 23:48
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?

Re: NoAI Branch - An AI Framework
Posted: 23 Jul 2007 21:58
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!