AIStation.GetCargoRating

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

Post Reply
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

AIStation.GetCargoRating

Post by Attila7 »

As a matter of design philosophy, I was under the impression that we want to have an AI that does not cheat, but at the same time is not handicapped by missing abilities that a human player has. I may be wrong, but this would be my philosophy.

As such, I am trying to implement what is relatively simple for a human to do, to see how many stations compete for the same cargo at an industry. This is turning into a major undertaking, because we don't have an AIStationList_IndustryCargoTaken(iid,cargo) or some-such. However, that is not at issue here.

With the tools that we have it is not possible to determine if a station is taking a particular cargo. A human can take a look at the cargo rating for a station --- any station --- but the AI can only do this for its own stations, because GetCargoRating is restricted by IsValidStation, which returns false if the station is not the AI's. A number of other AIStation functions are similarly restricted.

I am hoping this is an oversight and not a design decision and that it can be fixed. My view is that IsValidStation should not check if the station is owned by the AI, just that it is a valid station that exists.

While I am at this, can we also get a AIStationList_IndustryCargoTaken(iid,cargo) or something similar. :D It should be fairly simple for the game to produce this, as it must already have such a list to distribute cargo to each station.
Attila
"Artificial intelligence is no match for natural stupidity."
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIStation.GetCargoRating

Post by Yexo »

See FS#2776. At first it was a design decision to let an AI only get information about his own vehicles/stations/etc. At this time I agree that AIs need more information about their opponents, but it is not implemented yet.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AIStation.GetCargoRating

Post by Zuu »

What you can do currently is to check how much cargo that was transported from the industry last month. If it is non-zero and you know that you don't transport that cargo from the industry, then it is easy to say that there is at least one opponent that is transporting away cargo from the industry.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

Yes, I am doing this now, but I needed something better, especially when there are many AIs going after everything on the map. :)
Attila
"Artificial intelligence is no match for natural stupidity."
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

Yexo wrote:See FS#2776. At first it was a design decision to let an AI only get information about his own vehicles/stations/etc. At this time I agree that AIs need more information about their opponents, but it is not implemented yet.
Is this something we are likely to see in the next version? At least the removal of the ownership restriction on IsValidStation could be removed without much work or effect on existing AIs.
Attila
"Artificial intelligence is no match for natural stupidity."
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

It seems that this topic is being ignored, so I am going to add yet another reason to remove the IsValidStation restriction that prevents getting information on opponent stations.

I want to count the number of airports around a town and if there are already two airports and we are not playing with noise, I don't want to waste time leveling an area just to find out that I can't build another airport.

This seemingly simple task cannot be accomplished, because although I can tell that a tile is a station and I can even get the station Id for it, I cannot tell if it is an airport if it does not belong to me.

So, could you please remove this unnecessary restriction and give AIs the ability to act more intelligently when it comes to evaluating their surroundings.

I am attaching a screenshot that shows the situation.
Attachments
YATT, 26th Aug 1955.png
(319.05 KiB) Downloaded 2 times
Attila
"Artificial intelligence is no match for natural stupidity."
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

As a workaround for the airport count issue, I found that AIAirport.IsAirportTile does return true for opponent airports, so I can use that. However, this makes the NoAI API design even more incongruous.
Attila
"Artificial intelligence is no match for natural stupidity."
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AIStation.GetCargoRating

Post by Zuu »

As an alternative you could find a clear spot and try to build a heliport (when they are available) to see if it is allowed before leveling land for a intercontinental airport.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIStation.GetCargoRating

Post by Yexo »

AITown::GetAllowedNoise and AIAirport::GetNoiseLevelIncrease return all the information you need to check if the noise an airport generates is allowed.

Just removing the owner check for IsValidStation creates other problems, because IsValidStation is used by several lists to determine whether or not a station should end up in a list. Because of this it can confuse AIs that are depending on the current behavior of IsValidStation. It also makes the situation even more inconsistent. This change should be implemented, but at the same time there should probably a mechanism for AIs to set whether they want information about their own stations/vehicles/... or about all stations/vehicles/... It has to be designed in a way so it's not much work to upgrade current AIs, but all information is still available. Currently I do not have the time to start this rather big project.

I have no objection to your proposed AIStationList_IndustryCargoTaken, but currently that list would include only your own stations (see above) so I don't think that is what you want.
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

I don't really want to start a big project, only to see info on other stations that is being prevented by IsValidStation also checking if it is MY station.

Perhaps, in the interest of backward compatibility, you could just add a function to turn off the "owned by you" check in IsValidStation.

Something like, AIStation.SetQueryMode(mode) where mode is QUERY_MY_STATIONS_ONLY (default) or QUERY_ALL_STATIONS (what I would like).
AITown::GetAllowedNoise and AIAirport::GetNoiseLevelIncrease return all the information you need to check if the noise an airport generates is allowed.
Thanks for this tip. I did not realize that GetNoiseLevelIncrease returns different values for an airport type depending on how the "station_noise_level" is configured.
Last edited by Attila7 on 12 Sep 2010 13:56, edited 1 time in total.
Attila
"Artificial intelligence is no match for natural stupidity."
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIStation.GetCargoRating

Post by Yexo »

Attila7 wrote:Perhaps, in the interest of backward compatibility, you could just add a function to turns off the "owned by you" check in IsValidStation.

Something like, AIStation.SetQueryMode(mode) where mode is QUERY_MY_STATIONS_ONLY (default) or QUERY_ALL_STATIONS (what I would like).
That is exactly what I had in mind, except for all features and not only stations. Only it means checking all code that uses any of the IsValid* functions to alter their preconditions with an owner check. Adding it only for stations now means more work later when the same feature is introduced for other things like vehicles.
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

Well, how much work you want to do and when is up to you :) but I am writing my AI now <g> so, I will try and not bug you about this...for a while.
Attila
"Artificial intelligence is no match for natural stupidity."
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: AIStation.GetCargoRating

Post by Michiel »

Attila7 wrote:I am attaching a screenshot that shows the situation.
How did you change the debug window font? This makes it much more readable. Is it a setting somewhere or did you have to recompile?
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

I have a heavily modified build of the game to help me debug the AI scripts.

The font change involves defining "large_font = Courier New" in the cfg and I had to write some code to handle this in the debug window. I also changed the colors and there is a full interactive debugger in there as well. The line you see at the bottom is a command input line and the gold text in the window is what I entered.
Attila
"Artificial intelligence is no match for natural stupidity."
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIStation.GetCargoRating

Post by Yexo »

Attila7 wrote:I have a heavily modified build of the game to help me debug the AI scripts.

The font change involves defining "large_font = Courier New" in the cfg and I had to write some code to handle this in the debug window. I also changed the colors and there is a full interactive debugger in there as well. The line you see at the bottom is a command input line and the gold text in the window is what I entered.
That sounds like it could be very useful also for other AI developers. Could you perhaps post a patch with your changes?
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

I intend to, but everything is under development right now.

At some point I will release YATT and then I will document and release the debugger, ATTDebug.

I am also waiting for the next release of OTTD, so we have a stable version for which I can release the debugger, as I constantly have to make changes to keep up with the trunk code in some areas.
Attila
"Artificial intelligence is no match for natural stupidity."
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIStation.GetCargoRating

Post by Yexo »

If you release the debugger long enough before the stable than it can perhaps be included in the openttd code. That is, if it's generic enough to be useful also for other AI writers.
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AIStation.GetCargoRating

Post by Attila7 »

I am fairly certain that we will need to have a specific build for ATTDebug (patch), because it uses all of the Squirrel libraries, modifies OTTD in many ways to allow running a script while the game is paused (see screenshot PAUSED-DEBUG mode), removes the delay for DoCommands etc, etc.

I am sure all of he AI developers will benefit from using ATTDebug, but I am not yet ready to release it. It is itself being debugged as I develop YATT and the strange ways of handling some issues in Squirrel and OTTD have already created obscure problems (my post about SetOrderFlags not working was a result of the way OTTD handles callbacks on some DoCommands, suspends scripts and the way Squirrel handles the DebugHook procedure.)

I will release the patch and the Squirrel scripts that go with it (ATTDebug is written in Squirrel using the DebugHook procedure) when I will have time to deal with the issues that such a release will most certainly bring to light.

I will not have time to work on YATT next week, so perhaps we will be a little closer to the next version of OTTD by then.
Attila
"Artificial intelligence is no match for natural stupidity."
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 37 guests