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 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 SamuXarick:IsNoiseLevelAllowed branch 2 times, most recently from a51629d to 9804f2d Mar 31, 2019
@PeterN

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

SamuXarick commented Mar 31, 2019

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

This comment has been minimized.

Copy link
Contributor Author

SamuXarick 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.

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.
@SamuXarick SamuXarick force-pushed the SamuXarick:IsNoiseLevelAllowed branch from 9804f2d to 5e93c92 Mar 31, 2019
@@ -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:

This comment has been minimized.

Copy link
@glx22

glx22 Mar 31, 2019

Contributor

There's already an "API additions" section

@TrueBrain

This comment has been minimized.

Copy link
Member

TrueBrain commented Mar 31, 2019

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 :)

@SamuXarick

This comment has been minimized.

Copy link
Contributor Author

SamuXarick commented Mar 31, 2019

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

This comment has been minimized.

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

This comment has been minimized.

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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.