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

Update Default Player Type to String For Flexibility #2048

Merged
merged 5 commits into from Jul 3, 2017

Conversation

ron-murhammer
Copy link
Member

@ron-murhammer ron-murhammer commented Jul 2, 2017

Further addresses: https://forums.triplea-game.org/topic/132/handling-of-ai-players-not-meant-to-be-played-github-request

Functional Changes:

  • Game XML player property changed from isAIDefault to defaultType to allow for "Human", "AI", "DoesNothing". Default is still "Human".
  • Added checks that player row is enabled and not hidden when using set all player type or player type for alliance functionality
  • Only display alliance button if player is in an alliance (don't show empty button)

Examples:
<player name="Germans" optional="false" defaultType="AI" />
<player name="Italians" optional="false" defaultType="DoesNothing" />

@codecov-io
Copy link

codecov-io commented Jul 2, 2017

Codecov Report

Merging #2048 into master will increase coverage by <.01%.
The diff coverage is 17.24%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2048      +/-   ##
============================================
+ Coverage     18.71%   18.71%   +<.01%     
  Complexity     5405     5405              
============================================
  Files           777      777              
  Lines         77702    77709       +7     
  Branches      12914    12917       +3     
============================================
+ Hits          14539    14541       +2     
- Misses        61104    61111       +7     
+ Partials       2059     2057       -2
Impacted Files Coverage Δ Complexity Δ
...engine/framework/startup/ui/PlayerSelectorRow.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...in/java/games/strategy/engine/data/GameParser.java 70.17% <100%> (ø) 169 <0> (ø) ⬇️
...main/java/games/strategy/engine/data/PlayerID.java 44.92% <75%> (ø) 16 <1> (ø) ⬇️
src/main/java/games/strategy/net/nio/Decoder.java 74.5% <0%> (-0.99%) 27% <0%> (-1%)
...tegy/triplea/oddsCalculator/ta/OddsCalculator.java 44.2% <0%> (+0.31%) 13% <0%> (ø) ⬇️
...rategy/triplea/attachments/UnitTypeComparator.java 42.85% <0%> (+7.14%) 11% <0%> (+1%) ⬆️

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 d9a0978...dd345b3. Read the comment docs.

Copy link
Member

@ssoloff ssoloff left a comment

Choose a reason for hiding this comment

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

Code looks good, @ron-murhammer. One potential (but unlikely) NPE identified below.

@@ -73,26 +77,26 @@ public void actionPerformed(final ActionEvent e) {
}
if (!(previousSelection.equals("no_one")) && Arrays.asList(types).contains(previousSelection)) {
playerTypes.setSelectedItem(previousSelection);
} else if (player.isAiDefault()) {
} else if (player.getDefaultType().equals(PLAYER_TYPE_AI)) {
Copy link
Member

Choose a reason for hiding this comment

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

You might want to swap the order of the comparison here because PlayerID#getDefaultType() can return null. It looks like that should never happen for PlayerID instances created via GameParser, but there is a public constructor which does set the corresponding field to null (although it appears it's only used by the tests at this time).

// the 4th in the list should be Pro AI (Hard AI)
playerTypes.setSelectedItem(types[Math.max(0, Math.min(types.length - 1, 3))]);
} else if (player.getDefaultType().equals(PLAYER_TYPE_DOES_NOTHING)) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as previous comment.

@@ -23,27 +23,31 @@

class PlayerSelectorRow {

private static final String PLAYER_TYPE_AI = "AI";
private static final String PLAYER_TYPE_DOES_NOTHING = "DoesNothing";
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking out loud... Is there a better place for these constants (including one for "Human")? Since you're defining the legal values in the DTD, that would suggest they're API and should be defined in the engine domain model. I'm guessing this feature is still evolving, and you'll probably move them when everything becomes better focused. 😄 (An enum may even be in its future given that the DTD limits it to a finite set of values.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought the same thing but decided to leave them just in this class for now.

@ron-murhammer
Copy link
Member Author

Merging this now after addressing the review comments.

@ron-murhammer ron-murhammer merged commit a6c7774 into master Jul 3, 2017
@RoiEXLab RoiEXLab deleted the Add_Player_Default_Type branch July 3, 2017 05:26
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