aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java57
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck04.java81
2 files changed, 138 insertions, 0 deletions
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 @@
1package ch.epfl.xblast.server.debug;
2
3import java.util.List;
4
5import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.server.Block;
7import ch.epfl.xblast.server.Board;
8import ch.epfl.xblast.server.GameState;
9import ch.epfl.xblast.server.Player;
10
11public final class GameStatePrinter {
12 private GameStatePrinter() {}
13
14 public static void printGameState(GameState s) {
15 List<Player> ps = s.alivePlayers();
16 Board board = s.board();
17
18 for (int y = 0; y < Cell.ROWS; ++y) {
19 xLoop: for (int x = 0; x < Cell.COLUMNS; ++x) {
20 Cell c = new Cell(x, y);
21 for (Player p: ps) {
22 if (p.position().containingCell().equals(c)) {
23 System.out.print(stringForPlayer(p));
24 continue xLoop;
25 }
26 }
27 Block b = board.blockAt(c);
28 System.out.print(stringForBlock(b));
29 }
30 System.out.println();
31 }
32 }
33
34 private static String stringForPlayer(Player p) {
35 StringBuilder b = new StringBuilder();
36 b.append(p.id().ordinal() + 1);
37 switch (p.direction()) {
38 case N: b.append('^'); break;
39 case E: b.append('>'); break;
40 case S: b.append('v'); break;
41 case W: b.append('<'); break;
42 }
43 return b.toString();
44 }
45
46 private static String stringForBlock(Block b) {
47 switch (b) {
48 case FREE: return " ";
49 case INDESTRUCTIBLE_WALL: return "##";
50 case DESTRUCTIBLE_WALL: return "??";
51 case CRUMBLING_WALL: return "¿¿";
52 case BONUS_BOMB: return "+b";
53 case BONUS_RANGE: return "+r";
54 default: throw new Error();
55 }
56 }
57}
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 @@
1package ch.epfl.xblast.namecheck;
2
3import java.util.List;
4import java.util.Optional;
5
6import ch.epfl.cs108.Sq;
7import ch.epfl.xblast.Cell;
8import ch.epfl.xblast.Lists;
9import ch.epfl.xblast.PlayerID;
10import ch.epfl.xblast.Time;
11import ch.epfl.xblast.server.Block;
12import ch.epfl.xblast.server.Board;
13import ch.epfl.xblast.server.Bomb;
14import ch.epfl.xblast.server.Bonus;
15import ch.epfl.xblast.server.GameState;
16import ch.epfl.xblast.server.Player;
17import ch.epfl.xblast.server.Ticks;
18
19/**
20 * Classe abstraite utilisant tous les éléments de l'étape 4, pour essayer de
21 * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est
22 * pas un test unitaire, et n'a pas pour but d'être exécuté!
23 */
24
25abstract class NameCheck04 {
26 void checkLists() {
27 List<Integer> l1 = null;
28 List<List<Integer>> p1 = Lists.permutations(l1);
29 List<List<List<Integer>>> p2 = Lists.permutations(p1);
30 System.out.println(p2);
31 }
32
33 void checkBonus(boolean x) {
34 Bonus b = x ? Bonus.INC_BOMB : Bonus.INC_RANGE;
35 Player p = null;
36 p = b.applyTo(p);
37 }
38
39 void checkBlock(Block b) {
40 b = b.isBonus() ? Block.BONUS_BOMB : Block.BONUS_RANGE;
41 Bonus s = b.associatedBonus();
42 System.out.println(s);
43 }
44
45 void checkTime() {
46 Optional<Integer> o;
47 o = Optional.of(Time.S_PER_MIN);
48 o = Optional.of(Time.MS_PER_S);
49 o = Optional.of(Time.US_PER_S);
50 o = Optional.of(Time.NS_PER_S);
51 System.out.println(o);
52 }
53
54 void checkTicks() {
55 Optional<Integer> o;
56 o = Optional.of(Ticks.TICKS_PER_SECOND);
57 o = Optional.of(Ticks.TICK_NANOSECOND_DURATION);
58 o = Optional.of(Ticks.TOTAL_TICKS);
59 System.out.println(o);
60 }
61
62 void checkGameState() {
63 int ts = 0;
64 Board b = null;
65 List<Player> ps = null;
66 List<Bomb> bs = null;
67 List<Sq<Sq<Cell>>> es = null;
68 List<Sq<Cell>> xs = null;
69 GameState s = new GameState(ts, b, ps, bs, es, xs);
70 s = new GameState(b, ps);
71 ts = s.ticks();
72 if (s.isGameOver()) {
73 Optional<Double> t = Optional.of(s.remainingTime());
74 System.out.println(t.get());
75 }
76 Optional<PlayerID> w = s.winner();
77 b = s.board();
78 ps = s.isGameOver() ? s.alivePlayers() : s.players();
79 System.out.println(w);
80 }
81}