Another idea for NoAI APi improvement
Moderator: OpenTTD Developers
Another idea for NoAI APi improvement
As humans can watch certain vehicles and stations to improve their performance, I think some functions could be added to NoAI API to make that a little bit easier for noAI too.
Now noAI can poll the vehicles, but to see what vehicles are around certain area, AI have to query for all vehicles and then filter them by position.
Adding AIVehicleList_Area(Tile, radius) that will return all vehicles in certain area (the maximal value of radius could be limited to some "reasonable value") would help AI's to monitor performance of vehicles in certain areas and detect queues or another unwanted situations (simply seeing too much vehicles in one area mean usually trouble)
Humans can look at place in map and see there is a problem. This will help AI's to do the same with less CPU time consumed.
Another usable addition would be adding event like AIEventStationFirstVehicle, but that will be triggered for every arrival, not just first. As that could generate lots of event, it could be disabled by default, and AI would have to enable it for certain vehicles or stations of interest - those the AI wish to monitor closely (similar to humans opening another viewports or windows with desired station or vehicle)
Now noAI can poll the vehicles, but to see what vehicles are around certain area, AI have to query for all vehicles and then filter them by position.
Adding AIVehicleList_Area(Tile, radius) that will return all vehicles in certain area (the maximal value of radius could be limited to some "reasonable value") would help AI's to monitor performance of vehicles in certain areas and detect queues or another unwanted situations (simply seeing too much vehicles in one area mean usually trouble)
Humans can look at place in map and see there is a problem. This will help AI's to do the same with less CPU time consumed.
Another usable addition would be adding event like AIEventStationFirstVehicle, but that will be triggered for every arrival, not just first. As that could generate lots of event, it could be disabled by default, and AI would have to enable it for certain vehicles or stations of interest - those the AI wish to monitor closely (similar to humans opening another viewports or windows with desired station or vehicle)
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)
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)
Re: Another idea for NoAI APi improvement
The cpu win compared to the following is very small:Bilbo wrote:As humans can watch certain vehicles and stations to improve their performance, I think some functions could be added to NoAI API to make that a little bit easier for noAI too.
Now noAI can poll the vehicles, but to see what vehicles are around certain area, AI have to query for all vehicles and then filter them by position.
Adding AIVehicleList_Area(Tile, radius) that will return all vehicles in certain area (the maximal value of radius could be limited to some "reasonable value") would help AI's to monitor performance of vehicles in certain areas and detect queues or another unwanted situations (simply seeing too much vehicles in one area mean usually trouble)
Humans can look at place in map and see there is a problem. This will help AI's to do the same with less CPU time consumed.
Code: Select all
function VehicleDistanceToTile(vehicle, tile) {
return AIMap.DistanceManhattan(AIVehicle.GetLocation(vehicle), tile);
}
local list = AIVehicleList();
list.Valuate(VehicleDistanceToTile, some_tile);
list.KeepBelowValue(5);
/* list now contains all vehicles in a 5-tile radius around some_tile. */
Personally I don't see a need for this. If you want to follow a vehicle closely, just query it a lot.Another usable addition would be adding event like AIEventStationFirstVehicle, but that will be triggered for every arrival, not just first. As that could generate lots of event, it could be disabled by default, and AI would have to enable it for certain vehicles or stations of interest - those the AI wish to monitor closely (similar to humans opening another viewports or windows with desired station or vehicle)
Re: Another idea for NoAI APi improvement
I'd say that AIs written with NoAI API already has the capability to be much better than human on monitoring large areas that a human. Although it will only monitor things you have programmed it to monitor.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Another idea for NoAI APi improvement
Hmm .... this could probably work, though for large maps (2048 * 2048) and lots of vehicles (hundreds/thousands) it may start to be a little ineffective. I wonder if the code used to display vehicles on screen does have any optimization to select only vehicles visible in the shown area or if it simply uses similar iteration over all vehicles in each frame to determine if they lie withing the displayed boundaries - ineffective if only small fraction of many vehicles (for such large maps, thousands of vehicles is nothing uncommon) is actually visible ...Yexo wrote:The cpu win compared to the following is very small:Code: Select all
function VehicleDistanceToTile(vehicle, tile) { return AIMap.DistanceManhattan(AIVehicle.GetLocation(vehicle), tile); } local list = AIVehicleList(); list.Valuate(VehicleDistanceToTile, some_tile); list.KeepBelowValue(5); /* list now contains all vehicles in a 5-tile radius around some_tile. */
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)
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)
Re: Another idea for NoAI APi improvement
I think main problem is that there isn't any way how to see competitor's vehicles (or is it possible?). It makes it really hard to detect traffic jams. Same problem is with stations.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Another idea for NoAI APi improvement
How do you determine whether something is within a given area except checking every vehicle? Even a sorting algorithm needs to do that and wouldn't gain speed over checking x and y directly...Bilbo wrote:Hmm .... this could probably work, though for large maps (2048 * 2048) and lots of vehicles (hundreds/thousands) it may start to be a little ineffective. I wonder if the code used to display vehicles on screen does have any optimization to select only vehicles visible in the shown area or if it simply uses similar iteration over all vehicles in each frame to determine if they lie withing the displayed boundaries - ineffective if only small fraction of many vehicles (for such large maps, thousands of vehicles is nothing uncommon) is actually visible ...
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Another idea for NoAI APi improvement
I've not tested it, but something like this should work...Pat wrote:I think main problem is that there isn't any way how to see competitor's vehicles (or is it possible?). It makes it really hard to detect traffic jams. Same problem is with stations.
Code: Select all
function HasTraffic(tile) {
local _ = AITestMode();
return (!AITile.DemolishTile(tile) && AIError.GetLastError() == AIError.ERR_VEHICLE_IN_THE_WAY);
}
I'm still working on my traffic handling, but I maintain a list of tiles that are known to have traffic on then. e.g. if construction on a tile failed because of ERR_VEHICLE_IN_THE_WAY I remember it. If it happens enough times then the tile is black-listed.
PathZilla - A networking AI - Now with tram support.
Re: Another idea for NoAI APi improvement
Well, there are data structures (like quad trees for example) that can help with that, so if you query for vehicles within certain rectangle, you do not need to go through all vehicles.planetmaker wrote:How do you determine whether something is within a given area except checking every vehicle? Even a sorting algorithm needs to do that and wouldn't gain speed over checking x and y directly...Bilbo wrote:Hmm .... this could probably work, though for large maps (2048 * 2048) and lots of vehicles (hundreds/thousands) it may start to be a little ineffective. I wonder if the code used to display vehicles on screen does have any optimization to select only vehicles visible in the shown area or if it simply uses similar iteration over all vehicles in each frame to determine if they lie withing the displayed boundaries - ineffective if only small fraction of many vehicles (for such large maps, thousands of vehicles is nothing uncommon) is actually visible ...
There are some hash tables for collision detection and for updating viewport, so probably there is faster way (in terms of CPU cycles) to retrieve all vehicles within given rectangle than going through all vehicles in the game. Now just export such fiunction so it is available to AI's :)
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)
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)
Re: Another idea for NoAI APi improvement
wow, it's really smart idea.Zutty wrote: I've not tested it, but something like this should work...ERR_VEHICLE_IN_THE_WAY takes precedence over other errors, at least it does in the GUI, and so you should get this error even if theres a vehicle on a road you don't own.Code: Select all
function HasTraffic(tile) { local _ = AITestMode(); return (!AITile.DemolishTile(tile) && AIError.GetLastError() == AIError.ERR_VEHICLE_IN_THE_WAY); }
I'm still working on my traffic handling, but I maintain a list of tiles that are known to have traffic on then. e.g. if construction on a tile failed because of ERR_VEHICLE_IN_THE_WAY I remember it. If it happens enough times then the tile is black-listed.
But i still think than for new versions we need posibility to get more info about competitors staions (rating) and vehicles. In this area AI has less informations than player.
Who is online
Users browsing this forum: No registered users and 9 guests