Skip to content

Commit

Permalink
Optimize a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
Max committed Mar 12, 2024
1 parent 7e505dc commit a92a749
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ch/epfl/chacun/MessageBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public Map<PlayerColor, Integer> points() {
Map<PlayerColor, Integer> scorers = new HashMap<>();
for (Message message : messages) {
for (PlayerColor scorer : message.scorers) {
scorers.putIfAbsent(scorer, 0);
scorers.put(scorer, scorers.get(scorer) + message.points);
scorers.put(scorer, scorers.getOrDefault(scorer, 0) + message.points);
}
}
return scorers;
Expand Down Expand Up @@ -209,8 +208,7 @@ public MessageBoard withScoredMeadow(Area<Zone.Meadow> meadow, Set<Animal> cance
Set<PlayerColor> scorers = meadow.majorityOccupants();
// Don't create a message if no points are scored
if (points > 0) {
String messageContent = textMaker
.playersScoredMeadow(scorers, points, animalCount);
String messageContent = textMaker.playersScoredMeadow(scorers, points, animalCount);
// Create the message
ArrayList<Message> messages = new ArrayList<>(this.messages);
messages.add(new Message(messageContent, points, scorers, meadow.tileIds()));
Expand Down Expand Up @@ -243,7 +241,9 @@ public MessageBoard withScoredPitTrap(Area<Zone.Meadow> adjacentMeadow, Set<Anim
animalCount.get(Animal.Kind.MAMMOTH),
animalCount.get(Animal.Kind.AUROCHS),
animalCount.get(Animal.Kind.DEER));

Set<PlayerColor> scorers = adjacentMeadow.majorityOccupants();
// Don't create a message if no points are scored
if (points > 0) {
String messageContent = textMaker.playersScoredPitTrap(scorers, points, animalCount);
ArrayList<Message> messages = new ArrayList<>(this.messages);
Expand Down

0 comments on commit a92a749

Please sign in to comment.