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

AI fix v3 subs submerging #5492

Merged
merged 3 commits into from
Nov 17, 2019
Merged

AI fix v3 subs submerging #5492

merged 3 commits into from
Nov 17, 2019

Conversation

ron-murhammer
Copy link
Member

Copy link
Member

@DanVanAtta DanVanAtta left a comment

Choose a reason for hiding this comment

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

Seems like a fix. Few comments/suggestions for API and a question about 'isDestoyer' check.

@@ -176,6 +186,7 @@ public ProBattleResult callBattleCalculator(
final List<Unit> attackingUnits,
final List<Unit> defendingUnits,
final Set<Unit> bombardingUnits,
final boolean checkSubmerge,
Copy link
Member

Choose a reason for hiding this comment

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

Any objection to using an enum instead of boolean parameter? The "true, true" invocation is difficult to understand, requires a redirect to look at this code, slows down reading comprehension. Alternatively a static factory method could be employed to encapsulate the boolean parameters to be class-internal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the boolean parameters out of public methods so its just internal implementation in this class.

final double transportedUnitValue =
TuvUtils.getTuv(defendingTransportedUnits, ProData.unitValueMap);
tuvSwing += transportedUnitValue * winPercentage / 100;
}

// Remove TUV and add to remaining units for defenders that can submerge before battle
if (tuvSwing > 0
&& checkSubmerge
Copy link
Member

Choose a reason for hiding this comment

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

are all 4 of these boolean conditions to represent "canSubmergeBeforeBattle"? If so, extracting to a variable or method could make the comment redundant and the code a bit easier to grok

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. Updated.

&& checkSubmerge
&& Properties.getSubRetreatBeforeBattle(data)
&& defendingUnits.stream().anyMatch(Matches.unitCanEvade())
&& attackingUnits.stream().noneMatch(Matches.unitIsDestroyer())) {
Copy link
Member

Choose a reason for hiding this comment

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

side-note, it really seems like there should a rules class to do this logic. If there are other units that can prevent subs from submerging, seems this would break.

Does v2 or v1 rules allow destroyers to block sub-submerge? It might be moot if there are no destroyers on those maps, but could be worth considering that the 'isDestroyer' condition is truly universal.

Copy link
Member Author

@ron-murhammer ron-murhammer Nov 16, 2019

Choose a reason for hiding this comment

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

The isDestroyer is actually checking the unit property not whether the unit type itself is a destroyer. I can't remember if v1 handles it the same as the rest but at the moment all the AI logic assumes that isDestroyer property prevents submerging subs.

Copy link
Member

Choose a reason for hiding this comment

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

I think v1 can get away with it because there are no destroyer units.

Copy link
Member

@DanVanAtta DanVanAtta left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, looks good 👍

@codecov-io
Copy link

codecov-io commented Nov 17, 2019

Codecov Report

Merging #5492 into master will decrease coverage by 0.12%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5492      +/-   ##
============================================
- Coverage     24.71%   24.58%   -0.13%     
- Complexity     7066     7120      +54     
============================================
  Files          1085     1089       +4     
  Lines         78143    79403    +1260     
  Branches      11553    11689     +136     
============================================
+ Hits          19310    19520     +210     
- Misses        56631    57676    +1045     
- Partials       2202     2207       +5
Impacted Files Coverage Δ Complexity Δ
...a/games/strategy/triplea/ai/pro/ProPurchaseAi.java 0.26% <0%> (-0.01%) 1 <0> (ø)
...trategy/triplea/ai/pro/util/ProOddsCalculator.java 3.44% <0%> (-0.26%) 1 <0> (ø)
.../triplea/ai/pro/simulate/ProSimulateTurnUtils.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...ategy/triplea/ai/pro/data/ProTerritoryManager.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...ava/org/triplea/live/servers/ServerProperties.java 39.13% <0%> (-40.87%) 12% <0%> (+7%)
...unt/login/authorizer/anonymous/AnonymousLogin.java 66.66% <0%> (-16.67%) 3% <0%> (-1%)
...riplea/http/client/lobby/chat/LobbyChatClient.java 76.47% <0%> (-14.96%) 10% <0%> (-5%)
...a/org/triplea/live/servers/LiveServersFetcher.java 56.25% <0%> (-12.99%) 5% <0%> (ø)
...strategy/engine/lobby/client/login/LobbyLogin.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...ava/org/triplea/server/http/ServerApplication.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ff763c...08cf7cc. Read the comment docs.

@ron-murhammer ron-murhammer merged commit 1371e38 into master Nov 17, 2019
@ron-murhammer ron-murhammer deleted the AI_fix_v3_subs_submerging branch November 17, 2019 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants