From 8ce0ed0c2f2837641cc7de8c328a9182f8825f22 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Thu, 7 Apr 2016 18:27:16 +0200 Subject: Fix nextPlayer blocking bombs + remove magic number for BOMB_BLOCKING_DISTANCE --- src/ch/epfl/xblast/server/Board.java | 6 +++++- src/ch/epfl/xblast/server/GameState.java | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index bff3ea8..79259b5 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -16,6 +16,11 @@ import java.util.List; */ public final class Board { + /** + * Distance (in SubCells) from a bomb to block a player. + */ + public static final int BOMB_BLOCKING_DISTANCE = 6; + private static final int BLOCKS_LIST_SIZE = 195; private static final int BOARD_ROWS = 13; private static final int BOARD_COLUMNS = 15; @@ -45,7 +50,6 @@ public final class Board { * List containing all the blocks of the board. */ private List> blocks; - /** * Instantiates a new Board with the given sequence of blocks. * diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 10b648b..c9a23ac 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -200,12 +200,11 @@ public final class GameState { directedPositions1 = directedPositions1.tail(); // Check possible collisions and update the Sequence if necessary (kinda ugly right now) - Cell possiblyWalledCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); - if (!board1.blockAt(possiblyWalledCell).canHostPlayer()) { // if block non-free + Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); + if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free Sq actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick - } - if (bombedCells1.contains(player0.position().containingCell()) && player0.position().distanceToCentral() <= 6) { // Magic number ! 10 lashes for Fnux. + } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { Sq actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick } -- cgit v1.2.3