From 67959ff058abc5fa0f943b031c6a1369c0f3a5c7 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 9 Apr 2016 23:55:05 +0200 Subject: Fix bomb dropping after max reached --- src/ch/epfl/xblast/server/GameState.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 8a9d5a9..3d14bd0 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -80,6 +80,16 @@ public final class GameState { .collect(Collectors.toMap(Bomb::position, Function.identity())); } + /** + * Maps bombs to their owning player ID. + * + * @param b the list of bombs + * @return the mapping + */ + private static Map> mapBombsToPlayers(List b) { + return b.stream().collect(Collectors.groupingBy(Bomb::ownerId)); + } + /** * Returns a set of cells that contains at least one blast in the given blasts sequences. * @@ -357,12 +367,16 @@ public final class GameState { */ private static List newlyDroppedBombs(List players0, Set bombDropEvents, List bombs0) { HashSet bombedCells = new HashSet<>(GameState.bombedCells(bombs0).keySet()); + Map> bombOwnerMap = GameState.mapBombsToPlayers(bombs0); List bombs1 = new ArrayList<>(bombs0); for (Player p : GameState.alivePlayers(players0)) { if (!bombDropEvents.contains(p.id())) continue; if (bombedCells.contains(p.position().containingCell())) continue; + List ownedBombs = bombOwnerMap.get(p.id()); + if (ownedBombs != null && ownedBombs.size() >= p.maxBombs()) continue; + Bomb b = new Bomb(p.id(), p.position().containingCell(), Ticks.BOMB_FUSE_TICKS, p.bombRange()); bombedCells.add(b.position()); bombs1.add(b); -- cgit v1.2.3