From b0356d4ff6694ccc7f8fae1766b73b0e99c78ed9 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 8 Mar 2016 23:16:12 +0100 Subject: Import NameCheck04 and GaneStatePrinter (given files for the week 4) --- .../epfl/xblast/server/debug/GameStatePrinter.java | 57 +++++++++++++++ test/ch/epfl/xblast/namecheck/NameCheck04.java | 81 ++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 src/ch/epfl/xblast/server/debug/GameStatePrinter.java create mode 100644 test/ch/epfl/xblast/namecheck/NameCheck04.java diff --git a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java new file mode 100644 index 0000000..240446b --- /dev/null +++ b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java @@ -0,0 +1,57 @@ +package ch.epfl.xblast.server.debug; + +import java.util.List; + +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.GameState; +import ch.epfl.xblast.server.Player; + +public final class GameStatePrinter { + private GameStatePrinter() {} + + public static void printGameState(GameState s) { + List ps = s.alivePlayers(); + Board board = s.board(); + + for (int y = 0; y < Cell.ROWS; ++y) { + xLoop: for (int x = 0; x < Cell.COLUMNS; ++x) { + Cell c = new Cell(x, y); + for (Player p: ps) { + if (p.position().containingCell().equals(c)) { + System.out.print(stringForPlayer(p)); + continue xLoop; + } + } + Block b = board.blockAt(c); + System.out.print(stringForBlock(b)); + } + System.out.println(); + } + } + + private static String stringForPlayer(Player p) { + StringBuilder b = new StringBuilder(); + b.append(p.id().ordinal() + 1); + switch (p.direction()) { + case N: b.append('^'); break; + case E: b.append('>'); break; + case S: b.append('v'); break; + case W: b.append('<'); break; + } + return b.toString(); + } + + private static String stringForBlock(Block b) { + switch (b) { + case FREE: return " "; + case INDESTRUCTIBLE_WALL: return "##"; + case DESTRUCTIBLE_WALL: return "??"; + case CRUMBLING_WALL: return "¿¿"; + case BONUS_BOMB: return "+b"; + case BONUS_RANGE: return "+r"; + default: throw new Error(); + } + } +} diff --git a/test/ch/epfl/xblast/namecheck/NameCheck04.java b/test/ch/epfl/xblast/namecheck/NameCheck04.java new file mode 100644 index 0000000..b6adc8c --- /dev/null +++ b/test/ch/epfl/xblast/namecheck/NameCheck04.java @@ -0,0 +1,81 @@ +package ch.epfl.xblast.namecheck; + +import java.util.List; +import java.util.Optional; + +import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.Lists; +import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.Time; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.Bomb; +import ch.epfl.xblast.server.Bonus; +import ch.epfl.xblast.server.GameState; +import ch.epfl.xblast.server.Player; +import ch.epfl.xblast.server.Ticks; + +/** + * Classe abstraite utilisant tous les éléments de l'étape 4, pour essayer de + * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est + * pas un test unitaire, et n'a pas pour but d'être exécuté! + */ + +abstract class NameCheck04 { + void checkLists() { + List l1 = null; + List> p1 = Lists.permutations(l1); + List>> p2 = Lists.permutations(p1); + System.out.println(p2); + } + + void checkBonus(boolean x) { + Bonus b = x ? Bonus.INC_BOMB : Bonus.INC_RANGE; + Player p = null; + p = b.applyTo(p); + } + + void checkBlock(Block b) { + b = b.isBonus() ? Block.BONUS_BOMB : Block.BONUS_RANGE; + Bonus s = b.associatedBonus(); + System.out.println(s); + } + + void checkTime() { + Optional o; + o = Optional.of(Time.S_PER_MIN); + o = Optional.of(Time.MS_PER_S); + o = Optional.of(Time.US_PER_S); + o = Optional.of(Time.NS_PER_S); + System.out.println(o); + } + + void checkTicks() { + Optional o; + o = Optional.of(Ticks.TICKS_PER_SECOND); + o = Optional.of(Ticks.TICK_NANOSECOND_DURATION); + o = Optional.of(Ticks.TOTAL_TICKS); + System.out.println(o); + } + + void checkGameState() { + int ts = 0; + Board b = null; + List ps = null; + List bs = null; + List>> es = null; + List> xs = null; + GameState s = new GameState(ts, b, ps, bs, es, xs); + s = new GameState(b, ps); + ts = s.ticks(); + if (s.isGameOver()) { + Optional t = Optional.of(s.remainingTime()); + System.out.println(t.get()); + } + Optional w = s.winner(); + b = s.board(); + ps = s.isGameOver() ? s.alivePlayers() : s.players(); + System.out.println(w); + } +} -- cgit v1.2.3