From e50e68d0523ece7cdf772b12904a6c0dafa2ec4a Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 9 May 2016 13:46:36 +0200 Subject: PlayerAction Enum and rename RandomSimulation to ConsoleSimulation --- .../epfl/xblast/simulation/ConsoleSimulation.java | 80 ++++++++++++++++++++++ .../epfl/xblast/simulation/RandomSimulation.java | 80 ---------------------- 2 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 test/ch/epfl/xblast/simulation/ConsoleSimulation.java delete mode 100644 test/ch/epfl/xblast/simulation/RandomSimulation.java (limited to 'test/ch') diff --git a/test/ch/epfl/xblast/simulation/ConsoleSimulation.java b/test/ch/epfl/xblast/simulation/ConsoleSimulation.java new file mode 100644 index 0000000..35c0eb8 --- /dev/null +++ b/test/ch/epfl/xblast/simulation/ConsoleSimulation.java @@ -0,0 +1,80 @@ +package ch.epfl.xblast.simulation; + +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.BoardTest; +import ch.epfl.xblast.server.GameState; +import ch.epfl.xblast.server.Player; +import ch.epfl.xblast.server.debug.GameStatePrinter; +import ch.epfl.xblast.server.debug.RandomEventGenerator; + +import java.util.Arrays; +import java.util.List; + +/** + * Random game simulation. + * + * @author Pacien TRAN-GIRARD (261948) + */ +public class ConsoleSimulation { + + private static final long DISPLAY_DELAY = 50; // in milliseconds + + private static final int PLAYER_LIVES = 4; + private static final int PLAYER_MAX_BOMBS = 4; + private static final int PLAYER_BOMB_RANGE = 4; + + private static final int SEED = 2016; + private static final int SPEED_CHANGE_PROB = 30; + private static final int BOMB_PROB = 100; + private static final RandomEventGenerator RANDOM_EVENT_GENERATOR = new RandomEventGenerator(SEED, SPEED_CHANGE_PROB, BOMB_PROB); + + private static Board buildTestBoard() { + return Board.ofQuadrantNWBlocksWalled(BoardTest.buildNWQuadrantMap()); + } + + private static Player newPlayer(PlayerID id, Cell pos) { + return new Player(id, PLAYER_LIVES, pos, PLAYER_MAX_BOMBS, PLAYER_BOMB_RANGE); + } + + private static List buildPlayersList() { + return Arrays.asList( + newPlayer(PlayerID.PLAYER_1, new Cell(1, 1)), + newPlayer(PlayerID.PLAYER_2, new Cell(13, 1)), + newPlayer(PlayerID.PLAYER_3, new Cell(13, 11)), + newPlayer(PlayerID.PLAYER_4, new Cell(1, 11))); + } + + private static GameState buildInitialGameState() { + return new GameState(buildTestBoard(), buildPlayersList()); + } + + private static GameState nextGameState(GameState gs) { + return gs.next(RANDOM_EVENT_GENERATOR.randomSpeedChangeEvents(), RANDOM_EVENT_GENERATOR.randomBombDropEvents()); + } + + private static boolean isSimulationOver(GameState gs) { + return gs == null || gs.isGameOver(); + } + + private static void delay() { + try { + Thread.sleep(DISPLAY_DELAY); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + + private static void displayGameState(GameState gs) { + GameStatePrinter.printGameState(gs); + delay(); + } + + public static void main(String[] args) { + for (GameState gs = buildInitialGameState(); !isSimulationOver(gs); gs = nextGameState(gs)) + displayGameState(gs); + } + +} diff --git a/test/ch/epfl/xblast/simulation/RandomSimulation.java b/test/ch/epfl/xblast/simulation/RandomSimulation.java deleted file mode 100644 index 3888650..0000000 --- a/test/ch/epfl/xblast/simulation/RandomSimulation.java +++ /dev/null @@ -1,80 +0,0 @@ -package ch.epfl.xblast.simulation; - -import ch.epfl.xblast.Cell; -import ch.epfl.xblast.PlayerID; -import ch.epfl.xblast.server.Board; -import ch.epfl.xblast.server.BoardTest; -import ch.epfl.xblast.server.GameState; -import ch.epfl.xblast.server.Player; -import ch.epfl.xblast.server.debug.GameStatePrinter; -import ch.epfl.xblast.server.debug.RandomEventGenerator; - -import java.util.Arrays; -import java.util.List; - -/** - * Random game simulation. - * - * @author Pacien TRAN-GIRARD (261948) - */ -public class RandomSimulation { - - private static final long DISPLAY_DELAY = 50; // in milliseconds - - private static final int PLAYER_LIVES = 4; - private static final int PLAYER_MAX_BOMBS = 4; - private static final int PLAYER_BOMB_RANGE = 4; - - private static final int SEED = 2016; - private static final int SPEED_CHANGE_PROB = 30; - private static final int BOMB_PROB = 100; - private static final RandomEventGenerator RANDOM_EVENT_GENERATOR = new RandomEventGenerator(SEED, SPEED_CHANGE_PROB, BOMB_PROB); - - private static Board buildTestBoard() { - return Board.ofQuadrantNWBlocksWalled(BoardTest.buildNWQuadrantMap()); - } - - private static Player newPlayer(PlayerID id, Cell pos) { - return new Player(id, PLAYER_LIVES, pos, PLAYER_MAX_BOMBS, PLAYER_BOMB_RANGE); - } - - private static List buildPlayersList() { - return Arrays.asList( - newPlayer(PlayerID.PLAYER_1, new Cell(1, 1)), - newPlayer(PlayerID.PLAYER_2, new Cell(13, 1)), - newPlayer(PlayerID.PLAYER_3, new Cell(13, 11)), - newPlayer(PlayerID.PLAYER_4, new Cell(1, 11))); - } - - private static GameState buildInitialGameState() { - return new GameState(buildTestBoard(), buildPlayersList()); - } - - private static GameState nextGameState(GameState gs) { - return gs.next(RANDOM_EVENT_GENERATOR.randomSpeedChangeEvents(), RANDOM_EVENT_GENERATOR.randomBombDropEvents()); - } - - private static boolean isSimulationOver(GameState gs) { - return gs == null || gs.isGameOver(); - } - - private static void delay() { - try { - Thread.sleep(DISPLAY_DELAY); - } catch (InterruptedException e) { - e.printStackTrace(); - System.exit(1); - } - } - - private static void displayGameState(GameState gs) { - GameStatePrinter.printGameState(gs); - delay(); - } - - public static void main(String[] args) { - for (GameState gs = buildInitialGameState(); !isSimulationOver(gs); gs = nextGameState(gs)) - displayGameState(gs); - } - -} -- cgit v1.2.3