Coulda, woulda, shoulda... I'll let Brumi decide.Lord Aro wrote:Again, the old ai would have made huge long wooden bridges, and certainly never upgrade them
SimpleAI v14 - trying to remake the old AI
Moderator: OpenTTD Developers
Re: SimpleAI v4 - trying to remake the old AI
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Re: SimpleAI v4 - trying to remake the old AI
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
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
Re: SimpleAI v4 - trying to remake the old AI
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
Indeed. I'll go through the builder.nut to see if I can make something useful.
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Re: SimpleAI v4 - trying to remake the old AI
AIBridgeList?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?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v4 - trying to remake the old AI
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
Sorry. So it may be necessary to create array of all bridges, updated during construction.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...
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v4 - trying to remake the old AI
SimpleAI crashed right after loading savegame.
- Attachments
-
- SimpleAI_Crash.PNG (27.9 KiB) Viewed 4268 times
Re: SimpleAI v4 - trying to remake the old AI
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.
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
ChooChoo has a simple "flatten this area" routine. It's in builder_misc.nut (LevelTerrain).
Re: SimpleAI v4 - trying to remake the old AI
Don't know about effective, but Chopper terraforms for its helipad things
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: SimpleAI v4 - trying to remake the old AI
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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SimpleAI v4 - trying to remake the old AI
No, I loaded the game and a couple of seconds later the AI crashed. I didn't have to do anything.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.
Edit: Never mind that. The savegame autosaves right after I open it.
Re: SimpleAI v4 - trying to remake the old AI
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
@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
Plane support is here! At least to some extent...
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!
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!
Re: SimpleAI v4 - trying to remake the old AI
I think that number of allowed planes should depend on distance between airports (like in AIAI) and their speed (slower/faster planes, speed multiplier).
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v4 - trying to remake the old AI
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
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;
}
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: SimpleAI v4 - trying to remake the old AI
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.Brumi wrote:Plane support is here! At least to some extent...
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!
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Re: SimpleAI v4 - trying to remake the old AI
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).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: SimpleAI v4 - trying to remake the old AI
A new beta version for v5 is available, this time with terraforming included
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?
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
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);
Keep me informed if there is a bug in the new version
Who is online
Users browsing this forum: No registered users and 31 guests