Page 8 of 14

Re: SimpleAI v4 - trying to remake the old AI

Posted: 08 Aug 2010 19:59
by SirkoZ
Lord Aro wrote:Again, the old ai would have made huge long wooden bridges, and certainly never upgrade them
Coulda, woulda, shoulda... I'll let Brumi decide. ;-)

Re: SimpleAI v4 - trying to remake the old AI

Posted: 09 Aug 2010 08:33
by Brumi
I think separating roads (or rather just using the existing one) can be done by modifying some pathfinder penalties. I cannot do serious modifications to the pathfinder simply because I don't understand the mechanics of it (I'm really bad at code reading :( ). So, feel free to do some experiments with those penalties around line 545 in builder.nut. I think _cost_no_existing_road is the key here.
There are some cases when multiple instances of SimpleAI try to build roads at the same place (it occurs quite often when they're racing for a subsidy), then they find their routes independent of each other before one road is built. So, the second company to finish the pathfinding doesn't consider the road built by the first one, because it was built while the second company was already pathfinding. This may result in close parallel roads.

Upgrading bridges could be quite hard as tracking roads is not very easy, especially in towns. Tracking rails is possible, but so far the most conveninent solution would be to scan the whole map for bridges owned by the company and then upgrade them if possible. But this would take a really big hit on the AI's performance CPU-wise. Any better ideas?

Anyway, I have an easy job when talking about these little inconveniences because 'the old AI also did it like that' argument is always there :P

Re: SimpleAI v4 - trying to remake the old AI

Posted: 10 Aug 2010 11:52
by SirkoZ
Brumi wrote:...Any better ideas?

Anyway, I have an easy job when talking about these little inconveniences because 'the old AI also did it like that' argument is always there :P
:lol:

Indeed. I'll go through the builder.nut to see if I can make something useful.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 13 Aug 2010 09:29
by Kogut
Upgrading bridges could be quite hard as tracking roads is not very easy, especially in towns. Tracking rails is possible, but so far the most conveninent solution would be to scan the whole map for bridges owned by the company and then upgrade them if possible. But this would take a really big hit on the AI's performance CPU-wise. Any better ideas?
AIBridgeList?

Re: SimpleAI v4 - trying to remake the old AI

Posted: 13 Aug 2010 11:52
by Brumi
As far as I know it lists the available bridges, not the already built ones. Or maybe I'm confusing it with AIBridgeList_length... :?

Re: SimpleAI v4 - trying to remake the old AI

Posted: 13 Aug 2010 14:00
by Kogut
Brumi wrote:As far as I know it lists the available bridges, not the already built ones. Or maybe I'm confusing it with AIBridgeList_length... :?
Sorry. So it may be necessary to create array of all bridges, updated during construction.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 11:42
by ABCRic
SimpleAI crashed right after loading savegame.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 12:12
by Brumi
Thank you for the report. :)
Here the game was saved right after it was loaded, wasn't it? The AI hadn't finished its loading routines when the game was saved again.
Two consecutive save/loads in a very short time may cause problems when there is an unfinished route, as the AI may not be able to remove it properly. But a crash is too much here - I will look into it.


And another thing: can any of you recommend me an AI which has easily understandable terraforming routines? Placing bigger airports without terraforming is quite ineffective.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 15:17
by Michiel
ChooChoo has a simple "flatten this area" routine. It's in builder_misc.nut (LevelTerrain).

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 15:20
by Lord Aro
Don't know about effective, but Chopper terraforms for its helipad things

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 15:56
by Zuu
PAXLink do some landscaping when placing airports. I don't remember how good it is implemented though. It is probably quite simple with 4-5 retries.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 16 Aug 2010 16:19
by ABCRic
Brumi wrote:Thank you for the report. :)
Here the game was saved right after it was loaded, wasn't it? The AI hadn't finished its loading routines when the game was saved again.
Two consecutive save/loads in a very short time may cause problems when there is an unfinished route, as the AI may not be able to remove it properly. But a crash is too much here - I will look into it.
No, I loaded the game and a couple of seconds later the AI crashed. I didn't have to do anything.

Edit: Never mind that. The savegame autosaves right after I open it.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 17 Aug 2010 09:26
by Brumi
Thanks for the answers, I will have a look at those terraforming routines.

@ABCRic: Anyway, if you still have the last save before the crash, you can recover it and continue playing if you disable autosave for a while (I mean, make sure it doesn't save the game right after loading). Of course I'm trying to fix this problem for the next version, but reading and understanding my own code after so much time is giving me a hard time :?

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 08:22
by Brumi
Plane support is here! At least to some extent... :D
I'd like to show you what I've been working on recently, plane support is coming for SimpleAI v5. The alpha version is downloadable from the first post. (it's not there on Bananas)

Of course there is a bunch of things missing, for example, terraforming for airports is still not there. So the AI will only be able to build airports on flat, smooth terrain. The integration of planes into the existing system is also not the best, currently it will try to build airports in roughly 10% of the cases if the other two means of transport are also enabled. Tell me if this should be higher/lower/configurable.

Currently the AI tries to build only 1 airport per city. It uses four types of airports: small, commuter, large and metropolitan. I also tried to set a maximum value of planes for each type of airport, so planes won't be added if this value is reached. So, the current airport capacities:
Small: 4
Commuter: 6
Large: 6
Metropolitan: 8
I set these values without any experimenting, so tell me if you think that these airports can handle more/less aircraft.
If you see large planes landing on small airports, or that there are more planes using an airport than the given value above, then it's a bug, please report it to me.

Also, any other bug reports are welcome. Happy testing! :D

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 08:34
by Kogut
I think that number of allowed planes should depend on distance between airports (like in AIAI) and their speed (slower/faster planes, speed multiplier).

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 08:46
by Brumi
You're right, but as only one airport is built per town, one airport may handle multiple routes. So, if the AI wants to build an air connection from A to B, and A already has an airport, then it will use the existing airport. Then wtih mutiple routes it would be hard to determine the capacity dynamically.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 10:06
by Kogut
It is not very hard (from AIAI, free to reuse and modify (I would like to hear about improvements)):

Code: Select all

function AirBuilder::IsItPossibleToAddBurden(stacja, tile, engine, ile=1)
{
local maksimum;
local total = this.GetBurden(stacja);
local airport_type = AIAirport.GetAirportType(AIStation.GetLocation(stacja));
if(airport_type==AIAirport.AT_LARGE) maksimum = 1500; 
if(airport_type==AIAirport.AT_METROPOLITAN ) maksimum = 2000;
if(airport_type==AIAirport.AT_COMMUTER) maksimum = 500; 
if(airport_type==AIAirport.AT_SMALL) maksimum = 600; 
 
if(AIAI.GetSetting("debug_signs_for_airports_load")) AISign.BuildSign(AIStation.GetLocation(stacja), total + " (" + maksimum + ")");

total+=ile*this.Burden(AIStation.GetLocation(stacja), tile, engine);

return total <= maksimum;
}

function AirBuilder::GetBurden(stacja)
{
local total;
local total = 0;
local airlist=AIVehicleList_Station(stacja);
for (local plane = airlist.Begin(); airlist.HasNext(); plane = airlist.Next())
   {
   total += this.Burden(AIOrder.GetOrderDestination (plane, 0), AIOrder.GetOrderDestination (plane, 1), AIVehicle.GetEngineType(plane));
   }
   
return total;
}

function AirBuilder::Burden(tile_1, tile_2, engine)
{
return AIEngine.GetMaxSpeed(engine)*200/(this.GetEffectiveDistanceBetweenAirports(tile_1, tile_2)+50);
}

function AirBuilder::GetEffectiveDistanceBetweenAirports(tile_1, tile_2)
{
local x1 = AIMap.GetTileX(tile_1);
local y1 = AIMap.GetTileY(tile_1);

local x2 = AIMap.GetTileX(tile_2);
local y2 = AIMap.GetTileY(tile_2);

local x_delta = abs(x1 - x2);
local y_delta = abs(y1 - y2);

local longer = max(x_delta, y_delta);
local shorter = min(x_delta, y_delta);

return shorter*99/70 + longer - shorter;
}

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 15:03
by SirkoZ
Brumi wrote:Plane support is here! At least to some extent... :D
I'd like to show you what I've been working on recently, plane support is coming for SimpleAI v5. The alpha version is downloadable from the first post. (it's not there on Bananas)

Of course there is a bunch of things missing, for example, terraforming for airports is still not there. So the AI will only be able to build airports on flat, smooth terrain. The integration of planes into the existing system is also not the best, currently it will try to build airports in roughly 10% of the cases if the other two means of transport are also enabled. Tell me if this should be higher/lower/configurable.

Currently the AI tries to build only 1 airport per city. It uses four types of airports: small, commuter, large and metropolitan. I also tried to set a maximum value of planes for each type of airport, so planes won't be added if this value is reached. So, the current airport capacities:
Small: 4
Commuter: 6
Large: 6
Metropolitan: 8
I set these values without any experimenting, so tell me if you think that these airports can handle more/less aircraft.
If you see large planes landing on small airports, or that there are more planes using an airport than the given value above, then it's a bug, please report it to me.

Also, any other bug reports are welcome. Happy testing! :D
Thank you for the nice surprise. Those numbers of aircraft per airport seem right to me as I use similar numbers myself. Chance of building airports should be as it was with the old AI - that is if it fails building other two transport types, as you suggested, Brumi.

Re: SimpleAI v4 - trying to remake the old AI

Posted: 26 Aug 2010 20:19
by Zuu
Another approach is to set a limit of the allowed queue length of the airport. PAXLink has the same limit for all airports (I think it is 8 ). Airports with a higher throughput will be allowed to take more aircrafts without tailoring a specific limit to each airport. That said, the queue length code requires some airport-specific definitions of the holding pattern since the API do not include any function to query the number of airplanes in holding (queue).

Re: SimpleAI v4 - trying to remake the old AI

Posted: 18 Sep 2010 19:35
by Brumi
A new beta version for v5 is available, this time with terraforming included 8)
I've used CostToFlattern() from PAXLink (oops, I forgot to credit it in the code, but it will be there in the next release :) ), and the whole Terraform.nut from NoCAB. So the AI will be able to build airports even on hilly terrain.
Another feature I added is that existing bridges are upgraded if there are newer bridges available.

The bad news is that I rarely write code these days, so some features I was planning to add for v5 (like dynamic airport capacities on the advice of Kogut, and maybe longer trains and stations) will only be there in v6 or later. I'll upload this version to Bananas if there are no bug reports. If I have a free day or two, I may start working on it again, but now it's a bit hard for me.

And I have a question:
In what cases does this code fail?

Code: Select all

group = AIGroup.CreateGroup(AIVehicle.VT_AIR);
local groupname = AICargo.GetCargoLabel(crg) + " - " + AIStation.GetName(stasrc);
if (groupname.len() > 29) groupname = groupname.slice(0, 28);
AIGroup.SetName(group, groupname);
I know that group names must be unique, but I'm getting names like 'group 2' just too frequently.

Keep me informed if there is a bug in the new version :)