Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: AI/GS IsNoiseLevelIncreaseAllowed #7451

Closed
wants to merge 1 commit into from

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Mar 31, 2019

API addition that may be used to check whether the noise that will be added to the nearest town if an airport would be built at a tile is allowed.

@SamuXarick SamuXarick changed the title Add: AI/GS IsNoiseLevelAllowed Add: AI/GS IsNoiseLevelIncreaseAllowed Mar 31, 2019
@SamuXarick SamuXarick force-pushed the IsNoiseLevelAllowed branch 2 times, most recently from a51629d to 9804f2d Compare March 31, 2019 01:09
@PeterN
Copy link
Member

PeterN commented Mar 31, 2019

Can't you just test building an airport instead? Players are not able to directly query this, so it seems odd than AIs can.

@SamuXarick
Copy link
Contributor Author

This idea came from another PR.

local noise = AIAirport.GetNoiseLevelIncrease(tile, a);
local allowed_noise = AITown.GetAllowedNoise(AIAirport.GetNearestTown(tile, a));
if (noise > allowed_noise) continue;

This is how I use it in an AI. Both ScriptAirport::GetNoiseLevelIncrease and ScriptAirport::GetNearestTown call AirportGetNearestTown. This API addition serves to avoid repeating the call.

@SamuXarick
Copy link
Contributor Author

Can't you just test building an airport instead? Players are not able to directly query this, so it seems odd than AIs can.

DoCommand is slow, even in test mode. DoCommand slows down the whole thing. It's easier on the cpu, but makes the AI feel like it's falling asleep in comparison. With the test noise, I iterate 32 towns, without it, I iterate 5 towns in the same time-frame.

API addition that may be used to check whether the noise that will be added to the nearest town if an airport would be built at a tile is allowed.
@@ -18,6 +18,9 @@
* \b 1.10.0
*
* This version is not yet released. The following changes are not set in stone yet.

* API additions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already an "API additions" section

@TrueBrain
Copy link
Member

The AI API is designed to only give information and allow actions which a human can also get/do (with some minor offset when it was absolutely needed). There is nothing in this function that can't already be done in scripts. Yes, it would take a bit longer, but a human would also take longer to figure out this question.

New AI API entries are and should always be measured like this. "Can a human do it too?"

As such, I am declining this addition. Either we should make this easily available for the human too, or the AI should be slow to process thing question.

This could, how ever, easily be put in a library. It is the exact reason Pathfinders are in libraries, and not in the API.

Tnx for the contribution though! Hope you understand why we are closing this :)

@TrueBrain TrueBrain closed this Mar 31, 2019
@TrueBrain TrueBrain added the won't implement This change has been rejected label Mar 31, 2019
@SamuXarick
Copy link
Contributor Author

Oh no TrueBrain, perhaps I failed at explaining things again? When I said "With the test noise", I meant those 3 lines in the code, not my API addition. My API addition is only mixing the 3 lines into 1 single command, to avoid repeating execution of the same code. Doing the test with those 3 lines vs doing the test with the new API command was meant to be an optimization only. :(

@nielsmh
Copy link
Contributor

nielsmh commented Mar 31, 2019

No you're wrong. A human player does not have any way to read the current airport noise level of a town, the player cannot know whether it's possible to build a new airport without actually trying to build a new airport. If an AI can know whether it's possible to build an airport in a location without actually building the airport, then the AI is by definition cheating, because it's using information not available to a human player.

@SamuXarick
Copy link
Contributor Author

SamuXarick commented Apr 1, 2019

AI Code 1 (1 below):

local noise = AIAirport.GetNoiseLevelIncrease(tile, a);
local allowed_noise = AITown.GetAllowedNoise(AIAirport.GetNearestTown(tile, a));
if (noise > allowed_noise) continue;

AI Code 2 (2 below):
if (!AIAirport.IsNoiseLevelIncreaseAllowed(tile, a)) continue;

(1) + master,         Total time: 56,189s, AirportGetNearestTown time: 12,1649185s (21,65%)(img 1)
(1) + master + #7424, Total time: 48,371s, AirportGetNearestTown time:  4,3388787s  (8,97%)(img 2)
(2) + master,         Total time: 49,499s, AirportGetNearestTown time:  6,3804211s (12,89%)(img 3)
(2) + master + #7424, Total time: 45,184s, AirportGetNearestTown time:  2,0829824s  (4,61%)(img 4)

img 1:
2019-04-01 (3)

img 2:
2019-04-01

img 3:
2019-04-01 (1)

img 4:
2019-04-01 (2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
won't implement This change has been rejected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants