-
Notifications
You must be signed in to change notification settings - Fork 381
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
Improve blitz validation & add property for attacking from contested territories. #10617
Conversation
I'd like to get your thoughts as rule experts if this is the right thing to do. One option is to make it a map property - but that would still result in the wrong error message for current maps. |
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
Codecov Report
@@ Coverage Diff @@
## master #10617 +/- ##
============================================
+ Coverage 28.10% 28.16% +0.05%
- Complexity 7998 8018 +20
============================================
Files 1197 1197
Lines 76982 76985 +3
Branches 10526 10522 -4
============================================
+ Hits 21633 21680 +47
+ Misses 53396 53361 -35
+ Partials 1953 1944 -9
Continue to review full report at Codecov.
|
Hmm, I took a look at the A&A 1914 rules, which also use 1-round combat.
So, that's not the same logic as this. That requires checking if the destination territory is contested. Though, implementing A&A 1914 rules is its own topic I suppose, but if we want to implement them, some additional properties would need to be added to control this logic. |
Are you saying that, under these rules, you can move directly from a contested territory to an enemy owned territory with enemy units in it as long as you have one or more units in it too, yet you cannot move from a contested territory to an empty enemy owned territory? If so, I would say this makes no sense: it should be easier to move into an empty enemy owned territory than to move into an enemy onwed territory crowded by a million enemy units and one of your units... How about land units which begin the turn in enemy territories devoid of enemy units (in case there is no taking control of such territories immediately)? Are they treated exactly like those starting in contested territories? Are there any differences between starting in a contested territory which you own and starting in a contested territory which your enemy owns, or ownership just doesn't matter so long as the territory is contested? My suggestion here is having a few properties, to define what you can do and keeping the default behaviour as simple and generic as possible (documenting it in "PoS2"). This should allow map-makers to choose what they want and would have the benefit of telling everyone the behaviour of the game, to some extent. In 2017, I've tested the program and written the following explanations as how it works:
This is how the program worked back in 2017, according to my experience. I do know that something changed since then. Something similar should now be written to detail how the program currently works. |
Yes, I suggest having contested-to-friendly only as the basis and addining any further movement allowances (like being able to go from contested to already contested and whatever this PR is about) as well-worded properties (you need to have true). Since now also land units can be unable to block or able to move past other units, if either all enemy units that are contesting the territory against you are unable to block other units or all units you are trying to move are able to move past them, then the case should be handled as if the starting territory was non contested (so that you can move directly even into an uncontested enemy territory with enemy units able to block your units). Moreover, the matter should be the same as land for convoy zones (sea territories) if you cannot enter enemy convoy zones during Non Combat Move (there is a property for this too). |
Only from a core-boardgame-rules perspective this feature would be restricted to 1914 and its ruleset only. Any variation maybe a welcome option for 1914 or any custom mapmaker game. Otherwise it of course reminds me of the "Sea Units starting in hostile Seazones" - implementation - brought to land territories. |
@panther2 Is it true that, in 1914, my sea units starting in a contested sea zone can move to an adjacent sea zone which is occupied by enemy units and no other units, whereas my land units starting in a contested land zone cannot move to an adjacent land zone which is occupied by enemy units unless the adjacent zone is also already occupied by one or more units each of which is owned by me or one of my allies? If so, we have a different handlying of the case in 1914, possibly depending on whether or not the zone is land or sea. |
@Cernelius With "otherwise" I meant the wwII-related games. And the "reminds me of" was just a hint towards a code implementation that meets the "Sea unit starting in hostile Sea Zones"-rules of the WWII games, that maybe could somehow be adapted/altered for use for territories in user made games, too. Concerning 1914 I am not familiar with the boardgame ruleset, as I have never been interested in this WW I scenario. |
I guess my problem with the current behavior is the error is talking about blitz which is completely unrelated. Otherwise, the map that's affected by this is Imperialism 1974 where how it should work is that you should be able to move troops through any territories and can choose or not to attack (either other players or neutrals). The land battles being optional is another triplea property that needs to be added (it exists for sea battles but not land battles). |
43fe5fd
to
f3ebdc6
Compare
@Cernelius Thanks. I've switched to split the blitz and no-blitz cases into separate checks such that the "no blitz" case will now have an error message that doesn't mention blitzing ("Cannot attack out of a contested territory"). I've added a property to allow such moves (in the second, non-blitz category) so existing maps are not affected. I've revised the description of this change to mention the new logic. Can you read over that and let me know if you agree with that logic? |
EDIT: Nevermind deleting this post content because I was accidentally in edit mode! |
While testing the edge cases I found some things the current engine doesn't handle well. Please hold off on looking more for now as I'd like to fix them at the same time. |
I need some time to get around checking out the intended 1914 rules. Wouldn't be advisable also supporting the 1914 rules (with properties to be set true) as part of this PR? Can we please have an exact and exhaustive description of how the program currently handles these matters when all properties are false? I think that is very important in order to build upon it. |
317e625
to
b4ee1e0
Compare
game-app/game-core/src/test/java/games/strategy/triplea/delegate/WW2V3Year41Test.java
Fixed
Show fixed
Hide fixed
game-app/game-core/src/test/java/games/strategy/triplea/delegate/WW2V3Year41Test.java
Fixed
Show fixed
Hide fixed
game-app/game-core/src/test/java/games/strategy/triplea/delegate/WW2V3Year41Test.java
Fixed
Show fixed
Hide fixed
game-app/game-core/src/test/java/games/strategy/triplea/delegate/WW2V3Year41Test.java
Fixed
Show fixed
Hide fixed
game-app/game-core/src/test/java/games/strategy/triplea/delegate/WW2V3Year41Test.java
Fixed
Show fixed
Hide fixed
// Check that extra infantry can't come along on a blitz if they're not air transported. | ||
removeFrom(eastPoland, eastPoland.getUnits()); | ||
|
||
Route route = new Route(poland, eastPoland, beloRussia); |
Check notice
Code scanning
Distance between variable 'route' declaration and its first usage is 7, but allowed 3. Consider making that variable final if you still need to store its value in advance (before method calls that might have side effects on the original value).
I believe it is important to clarify how the program behaves in all such situations (by "Neutral" I mean the relationship archetype neutral basic so not the "Neutral" player (which is not neutral but at war with anything)), assuming we are moving 1 land unit over land of 1 space only: Starting territory ownership:
Starting zone units (beside infrastructures):
Ending zone ownership:
Ending zone units (beside infrastructures):
Outcome @asvitkine If it is easier for you to know the results than for me to do so by testing every single case in a game, may you please compile a list of program behaviours without the property set true? This is the list (other than the ones where the ending zone is Neutral, I filled the obvious ones, where the starting territory is friendly owned and has no enemy units in it, and where the ending zone is friendly owned and has no enemy units in it): 1111=Can move Then list all the cases for which the property changes the behaviour. Thanks. Once this is done, I think it would be important to add such documentation within PoS2. |
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
...p/game-core/src/main/java/games/strategy/triplea/delegate/move/validation/MoveValidator.java
Fixed
Show fixed
Hide fixed
Thanks for thinking about this diligently. I'm afraid I don't have a way to verify the above easier than manually testing. I also think there's unfortunately a lot of extra conditions that the above wouldn't tell the full story of, such as whether the unit has moved before, whether that move was an attack, the presence of air and land transports, how much movement units have, whether a territory was conquered this turn, etc. Having said that, I don't think enumerating all the possible combinations of these options is feasible - there's just too many factors. So maybe just doing it for your suggested list is OK and the rest can be covered with some more targeted testing. |
498360a
to
2a22c15
Compare
After some back and forth with @Cernelius, I'm abandoning changing the blitzing logic changes this PR was originally proposing and keeping movement out of contested territories working exactly as before when the new property isn't set. I've updated the tests and the PR description to reflect the changes. @DanVanAtta, can you review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, no major callouts or issues that I can see. I left a few comments for you to review @asvitkine to consider places where we might be able to improve user messaging.
public static final String NOT_ALL_UNITS_CAN_BLITZ_OUT_OF_EMPTY_ENEMY_TERRITORY = | ||
"Not all units can blitz out of empty enemy territory"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to make this more specific regarding which units cannot blitz? Can we make this dynamic perhaps and list the unique unit types that cannot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to change anything with this error message since it's existing behavior (I just moved it to a variable), but actually the result object already contains the units that were invalid, since this message is added thus:
result.addDisallowedUnit(NOT_ALL_UNITS_CAN_BLITZ_OUT_OF_EMPTY_ENEMY_TERRITORY, u);
With u
being the unit that's not OK. So it's up to the code that's using the result (e.g. the UI code) to display that better, which would be a separate improvement.
} | ||
} | ||
return result; | ||
} | ||
|
||
private Map<Unit, Unit> dependentsToUnitToTransportsMap( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a typo in the name of this method? Reading it, it sounds like we have 'dependents' -> units' -> 'transports'
Should it be: 'dependentUnitsToTransportMap'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually "dependents" to "unitsToTransportMap", but I agree that it's hard to read.
How about I rename it to convertTransportKeyedMapToLoadedUnitKeyedMap()?
unitsToTransport.put(beingTransported, transport); | ||
// Validate capacity, as airTransportDependents is coming from the move we're validating. | ||
if (capacity < cost) { | ||
result.setError("Not all units could be air transported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can make this error message more specific and helpful to the user. For example, could we say something like "not all units could be air transported, X out of Y transport capacity required"
Or, if we could say which units could not be transported, eg: "Not enough transport capacity for: X, Y, Z"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try using result.addDisallowedUnit() here instead, like it's done for the blitz case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, addDisallowedUnit() is not an error, just a warning, so it's not the same semantics.
Thinking about this more, I think this is actually OK to leave as-is, because this situation won't happen in practice due to validation done in MovePanel - it doesn't let you load more units than allowed on an air transport. So this is just guarding against coding mistakes (e.g. if move panel changes or if AI submits invalid moves) or malicious players that are sending invalid moves with a custom client. As such, I'll just keep it as-is but add a comment to this extent.
moveDelegate.start(); | ||
} | ||
|
||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding javadocs to '@test' to describe the test setup and what we are testing. Those comments describing the test I've personally found to be useful pretty soon after to go back and understand more easily what is being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
game-app/game-core/src/test/java/games/strategy/triplea/delegate/VictoryTest.java
Show resolved
Hide resolved
"Not all units can blitz out of empty enemy territory" is not an universally good definition for blitzable territories. For example, if in Revised you can blitz-out an empty enemy territory, in Classic you should also be able to blitz out an enemy territory with a factory and a aa gun in it as the only enemy units (capturing or liberating these units). In V2 and all following rules-set, you can indeed blitz only "empty" territories, but in V1 (which should be the default for the program) you can also blitz territories in which the only enemy units in them are all infrastructures. So, the messages should be more something like: By the way, I'm with Classic here: I never liked the "factories stop tanks" nonsense that is the rule since Revised. Side note, here I've used the term "infrastructures" even though I believe it is a bad term to define the units (Nobody would consider an AA Gun of WW2 an infrastructure, let alone a Napoleonic general.). I've raised the matter here: |
…territories. Improve blitz validation & add property for attacking from contested territories. This change makes several improvements to combat move validation, including handling combinations of blitzing and air/land transported units correctly and improving error messages related to moving from contested territories. It also adds a property to allow maps to permit attacking from contested territories unrelated to blitzing.
Since I'm not changing that logic here in the end, outside of the new property disabling that, that can be done in a separate change. Feel free to file an issue to track it.
|
Change Summary & Additional Notes
Improve blitz validation & add property for attacking from contested territories.
This change makes several improvements to combat move validation, including handling combinations of blitzing and air/land transported units correctly. It also adds a property to allow maps to permit attacking from contested territories unrelated to blitzing.
More specifically, the following improvements are done:
blitz_test_inf2.tsvg.zip
Tested:
imperialism_contested.tsvg.zip
imperialism_contested_new_property2.tsvg.zip
Release Note
FIX|Improved validation of blitzes in the presence of land and air transports and better move error messages. NEW|"All Units Can Attack From Contested Territories" game property to allow all units to attack from contested territories.