From c44550bd30a154f9614178b6de01b3a15a3f93f1 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Wed, 24 Feb 2016 15:55:07 +0100 Subject: Add the Block enum and the Ticks interface --- src/ch/epfl/xblast/server/Block.java | 51 ++++++++++++++++++++++++++++++++++++ src/ch/epfl/xblast/server/Ticks.java | 33 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/ch/epfl/xblast/server/Block.java create mode 100644 src/ch/epfl/xblast/server/Ticks.java diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java new file mode 100644 index 0000000..75925a3 --- /dev/null +++ b/src/ch/epfl/xblast/server/Block.java @@ -0,0 +1,51 @@ +package ch.epfl.xblast.server; + +public enum Block { + + /** + * 'Free' block, no wall. + */ + FREE, + + /** + * Indestructible block. + */ + INDESTRUCTIBLE_WALL, + + /** + * Destructible block. + */ + DESTRUCTIBLE_WALL, + + /** + * Crumbling Wall. + */ + CRUMBLING_WALL; + + /** + * Returns T(this block is free). + * + * @return T(this block is free) + */ + public boolean isFree() { + return this == FREE; + } + + /** + * Returns T(this block can host a player). + * + * @return T(this block can host a player) + */ + public boolean canHostPlayer() { + return this.isFree(); + } + + /** + * Returns T(this block cast a shadow) + * + * @returns T(this block cast a shadow) + */ + public boolean castsSahdow() { + return this == INDESTRUCTIBLE_WALL || this == DESTRUCTILE_WALL || this == CRUMBLING_WALL; + } +} diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java new file mode 100644 index 0000000..8c1e134 --- /dev/null +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -0,0 +1,33 @@ +package ch.epfl.xblast.server; + +public interface Ticks { + /** + * Duration of the death of a player. + */ + public static int PLAYER_DYING_TICKS = 8; + + /** + * Duration of the invulnerability of a player. + */ + public static int PLAYER_INVULNERABLE_TICKS = 64; + + /** + * Duration of + */ + public static int BOMB_FUSE_TICKS = 100; + + /** + * Duration of an explosion. + */ + public static int EXPLOSION_TICKS = 30; + + /** + * Duration of crumbling of a wall. + */ + public static int WALL_CRUMBLLING_TICKS = EXPLOSION_TICKS; + + /** + * Duration of the presence of a bonus. + */ + public static int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; +} -- cgit v1.2.3 From 746aafc3f0e8212282a5fbf31de7a83d2a618dc8 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sat, 27 Feb 2016 12:04:39 +0100 Subject: Add the Lists and Board Class + the Ticks Interface. Add the tests related to the '02_Board' part of the project. --- src/ch/epfl/xblast/Lists.java | 38 +++++++ src/ch/epfl/xblast/server/Block.java | 4 +- src/ch/epfl/xblast/server/Board.java | 123 ++++++++++++++++++++++ test/ch/epfl/xblast/ListsTest.java | 32 ++++++ test/ch/epfl/xblast/namecheck/NameCheck02.java | 60 +++++++++++ test/ch/epfl/xblast/server/BlockTest.java | 35 +++++++ test/ch/epfl/xblast/server/BoardTest.java | 137 +++++++++++++++++++++++++ 7 files changed, 427 insertions(+), 2 deletions(-) create mode 100644 src/ch/epfl/xblast/Lists.java create mode 100644 src/ch/epfl/xblast/server/Board.java create mode 100644 test/ch/epfl/xblast/ListsTest.java create mode 100644 test/ch/epfl/xblast/namecheck/NameCheck02.java create mode 100644 test/ch/epfl/xblast/server/BlockTest.java create mode 100644 test/ch/epfl/xblast/server/BoardTest.java diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java new file mode 100644 index 0000000..096ceba --- /dev/null +++ b/src/ch/epfl/xblast/Lists.java @@ -0,0 +1,38 @@ +package ch.epfl.xblast; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +/** + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ +public final class Lists { + /** + * Return a sysmetric version of the list. + * + * @param l the input list + * @throws IllegalArgumentException if the given list is empty + * @return mirroredList the mirrored ilist + */ + public static List mirrored(List l) { + if (l.size() == 0) { + throw new IllegalArgumentException(); + } + + List mirroredList = new ArrayList(); + List rightSide = new ArrayList(); + + for (int i=0;i < l.size()-1;i++) { + rightSide.add(l.get(i)); + } + + Collections.reverse(rightSide); + + mirroredList.addAll(l); + mirroredList.addAll(rightSide); + + return mirroredList; + } +} diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java index 75925a3..8268f33 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java @@ -45,7 +45,7 @@ public enum Block { * * @returns T(this block cast a shadow) */ - public boolean castsSahdow() { - return this == INDESTRUCTIBLE_WALL || this == DESTRUCTILE_WALL || this == CRUMBLING_WALL; + public boolean castsShadow() { + return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; } } diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java new file mode 100644 index 0000000..c8d3e01 --- /dev/null +++ b/src/ch/epfl/xblast/server/Board.java @@ -0,0 +1,123 @@ +package ch.epfl.xblast.server; + +import java.util.List; +import java.util.ArrayList; +import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Lists; + +/** + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ + +public final class Board { + /** + * List containing all the blocks of the board. + */ + private List> blocks; + + /** + * Instanciates a new Board with the given sequence of blocks. + * + * @throws IllegalArgumentEception if the blocks is not composed of 195 elements + * @param blocks sequence conataining all the blocks of the Boards + */ + public Board (List> blocks) { + if (blocks.size() != 195) { + throw new IllegalArgumentException(); + } + this.blocks = blocks; + } + + /** + * Build a new Board with the given Matrix. + * + * @param rows list containing all the rows + * @throws IllegalArgumentException if rows is not 13*15 + * @return a new Board built with given rows + */ + public static Board ofRows(List> rows) { + if (rows.size() != 13) { + throw new IllegalArgumentException(); + } + + List> blocksSequence = new ArrayList<>(); + + for (int i = 0; i < rows.size(); i++) { + + if (rows.get(i).size() != 15) { + throw new IllegalArgumentException(); + } + + for (int j = 0; j < rows.get(i).size(); j++) { + blocksSequence.add(Sq.constant(rows.get(i).get(j))); + } + } + + return new Board(blocksSequence); + } + + /** + * Build a walled board filled with the given inner rows + * + * @param innerBlocks lists of the internal rows + * @throws IllegalArgumentException if innerbLocks is not 11*13 + * @return a new walled board filled with the given rows + */ + public static Board ofInnerBlocksWalled(List> innerBlocks) { + if (innerBlocks.size() != 11) { + throw new IllegalArgumentException(); + } + + List> rowsList = new ArrayList<>(); + List wallLine = new ArrayList<>(); + + for (int i = 0; i < 15;i++) { + wallLine.add(Block.INDESTRUCTIBLE_WALL); + } + + for (int i = 0; i < innerBlocks.size(); i++) { + if (innerBlocks.get(i).size() != 13) { + throw new IllegalArgumentException(); + } + + List row = innerBlocks.get(i); + row.add(0,Block.INDESTRUCTIBLE_WALL); + row.add(Block.INDESTRUCTIBLE_WALL); + + rowsList.add(row); + } + + rowsList.add(0,wallLine); + rowsList.add(wallLine); + + return ofRows(rowsList); + } + + /** + * Build a symetric walled board from the NWB quadrant. + * + * @param quadrantNWBlocks the NW quadrant of the board (inner blocks only!) + * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 + * @return a new walled board simmetricaly filled with the given NW quadrant + */ + public static Board ofQuadrantNWBlocksWalled(List> quadrantNWBlocks) { + if (quadrantNWBlocks.size() != 6) { + throw new IllegalArgumentException(); + } + + List> rowsList = new ArrayList<>(); + + List> halfInnerBoard = Lists.>mirrored(quadrantNWBlocks); + + for (int i = 0; i < halfInnerBoard.size(); i++) { + if (halfInnerBoard.get(i).size() != 7) { + throw new IllegalArgumentException(); + } + + rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); + } + + return ofInnerBlocksWalled(rowsList); + } +} diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java new file mode 100644 index 0000000..6a98b3f --- /dev/null +++ b/test/ch/epfl/xblast/ListsTest.java @@ -0,0 +1,32 @@ +package ch.epfl.xblast; + +import java.util.List; +import java.util.Arrays; +import static org.junit.Assert.*; +import org.junit.Test; + +/** +* @author Pacien TRAN-GIRARD (261948) +* @author Timothée FLOURE (257420) +*/ +public class ListsTest { + @Test(expected=IllegalArgumentException.class) + public void isEmptyListThrowingException() { + List sampleList = Arrays.asList(); + Lists.mirrored(sampleList); + } + + @Test(expected=IllegalArgumentException.class) + public void isNullListThrowingException() { + List sampleList = Arrays.asList(); + Lists.mirrored(sampleList); + } + + @Test + public void isListMirrored() { + List sampleList = Arrays.asList(1,2,3,4,5); + List expected = Arrays.asList(1,2,3,4,5,4,3,2,1); + + assertEquals(expected, Lists.mirrored(sampleList)); + } +} diff --git a/test/ch/epfl/xblast/namecheck/NameCheck02.java b/test/ch/epfl/xblast/namecheck/NameCheck02.java new file mode 100644 index 0000000..978526e --- /dev/null +++ b/test/ch/epfl/xblast/namecheck/NameCheck02.java @@ -0,0 +1,60 @@ +package ch.epfl.xblast.namecheck; + +import java.util.List; + +import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.Lists; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.Ticks; + +/** + * Classe abstraite utilisant tous les éléments de l'étape 2, 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 NameCheck02 { + void checkTicks() { + int x = Ticks.PLAYER_DYING_TICKS + + Ticks.PLAYER_INVULNERABLE_TICKS + + Ticks.BOMB_FUSE_TICKS + + Ticks.EXPLOSION_TICKS + + Ticks.WALL_CRUMBLING_TICKS + + Ticks.BONUS_DISAPPEARING_TICKS; + System.out.println(x); + } + + void checkBlock() { + Block b = Block.FREE; + b = Block.INDESTRUCTIBLE_WALL; + b = Block.DESTRUCTIBLE_WALL; + b = Block.CRUMBLING_WALL; + boolean d = b.isFree() && b.canHostPlayer() && b.castsShadow(); + System.out.println(b + "/" + d); + } + + void checkLists() { + List l1 = null; + List l2 = null; + List> l3 = null; + List l1m = Lists.mirrored(l1); + List l2m = Lists.mirrored(l2); + List> l3m = Lists.>mirrored(l3); + System.out.println("" + l1m + l2m + l3m); + } + + void checkBoard() { + List> q = null; + Board b = Board.ofQuadrantNWBlocksWalled(q); + b = Board.ofInnerBlocksWalled(q); + b = Board.ofRows(q); + List> cells = null; + b = new Board(cells); + Cell c = null; + Sq bs = b.blocksAt(c); + Block l = b.blockAt(c); + System.out.println(bs + "/" + l); + } +} diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java new file mode 100644 index 0000000..bbe4376 --- /dev/null +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -0,0 +1,35 @@ +package ch.epfl.xblast.server; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Timothée FLOURE (257420) + * @author pacien TRAN-GIRARD (261948) + */ +public class BlockTest { + @Test + public void free() { + assertFalse(Block.INDESTRUCTIBLE_WALL.isFree()); + assertFalse(Block.DESTRUCTIBLE_WALL.isFree()); + assertFalse(Block.CRUMBLING_WALL.isFree()); + assertTrue(Block.FREE.isFree()); + } + + @Test + public void canHostPlayer() { + assertFalse(Block.INDESTRUCTIBLE_WALL.canHostPlayer()); + assertFalse(Block.DESTRUCTIBLE_WALL.canHostPlayer()); + assertFalse(Block.CRUMBLING_WALL.canHostPlayer()); + assertTrue(Block.FREE.canHostPlayer()); + } + + @Test + public void castSadhow() { + assertTrue(Block.INDESTRUCTIBLE_WALL.castsShadow()); + assertTrue(Block.DESTRUCTIBLE_WALL.castsShadow()); + assertTrue(Block.CRUMBLING_WALL.castsShadow()); + assertFalse(Block.FREE.castsShadow()); + } +} diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java new file mode 100644 index 0000000..7868e70 --- /dev/null +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -0,0 +1,137 @@ +package ch.epfl.xblast.server; + +import java.util.List; +import java.util.ArrayList; +import org.junit.Test; +import ch.epfl.cs108.Sq; + +import static org.junit.Assert.*; + +/** + * @author Timothée FLOURE (257420) + * @author Pacien TRAN-GIRARD (261948) + */ +public class BoardTest { + + @Test(expected=IllegalArgumentException.class) + public void isBoardBuilderEmptyInputThrowingException() { + List> blocks = new ArrayList>(); + new Board(blocks); + + } + + + @Test(expected=IllegalArgumentException.class) + public void isBoardBuilderIllegalInputThrowingException() { + List> blocks = new ArrayList>(); + + for (int i = 0;i<8;i++) { + blocks.add(Sq.constant(Block.FREE)); + } + + new Board(blocks); + + } + + @Test(expected=IllegalArgumentException.class) + public void isOfRowsEmptyInputMatrixThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofRows(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfRowsIllegalInputThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofRows(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromRowsMatrix() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 13; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 15; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofRows(rowsList) instanceof Board); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfInnerBlocksWalledEmptyInputMatrixThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofInnerBlocksWalled(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfInnerBlocksWalledIllegalInputThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromInnerBlocks() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 11; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 13; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + } + + @Test(expected=IllegalArgumentException.class) + public void isBuildWithEmptyQuadrantThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofQuadrantNWBlocksWalled(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isBuildWithIllegalQuadrantThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromNWQuadrant() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 6; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 7; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + } +} -- cgit v1.2.3 From 3fd6365255ba761f45f34bff3fef27a28b3a1785 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 29 Feb 2016 13:54:26 +0100 Subject: Fix typo in comment + remove tests on null input --- src/ch/epfl/xblast/server/Board.java | 1 - src/ch/epfl/xblast/server/Ticks.java | 2 +- test/ch/epfl/xblast/ListsTest.java | 6 ------ test/ch/epfl/xblast/server/BoardTest.java | 2 -- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index c8d3e01..fa91587 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -117,7 +117,6 @@ public final class Board { rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); } - return ofInnerBlocksWalled(rowsList); } } diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index 8c1e134..8793adb 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -12,7 +12,7 @@ public interface Ticks { public static int PLAYER_INVULNERABLE_TICKS = 64; /** - * Duration of + * Duration of the timer of a bomb. */ public static int BOMB_FUSE_TICKS = 100; diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 6a98b3f..42b317f 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -16,12 +16,6 @@ public class ListsTest { Lists.mirrored(sampleList); } - @Test(expected=IllegalArgumentException.class) - public void isNullListThrowingException() { - List sampleList = Arrays.asList(); - Lists.mirrored(sampleList); - } - @Test public void isListMirrored() { List sampleList = Arrays.asList(1,2,3,4,5); diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 7868e70..e40769b 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -12,7 +12,6 @@ import static org.junit.Assert.*; * @author Pacien TRAN-GIRARD (261948) */ public class BoardTest { - @Test(expected=IllegalArgumentException.class) public void isBoardBuilderEmptyInputThrowingException() { List> blocks = new ArrayList>(); @@ -20,7 +19,6 @@ public class BoardTest { } - @Test(expected=IllegalArgumentException.class) public void isBoardBuilderIllegalInputThrowingException() { List> blocks = new ArrayList>(); -- cgit v1.2.3 From 6e911cbce608ff530815448ce0463048016f8f28 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 15:28:56 +0100 Subject: Elaborate class documentation --- src/ch/epfl/xblast/server/Block.java | 10 ++++++++-- src/ch/epfl/xblast/server/Board.java | 10 ++++++---- src/ch/epfl/xblast/server/Ticks.java | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java index 8268f33..d1c96e5 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java @@ -1,5 +1,11 @@ package ch.epfl.xblast.server; +/** + * A Block. + * + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public enum Block { /** @@ -41,9 +47,9 @@ public enum Block { } /** - * Returns T(this block cast a shadow) + * Returns T(this block cast a shadow). * - * @returns T(this block cast a shadow) + * @return T(this block cast a shadow) */ public boolean castsShadow() { return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index fa91587..b385ed8 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -6,6 +6,8 @@ import ch.epfl.cs108.Sq; import ch.epfl.xblast.Lists; /** + * A two-dimensional Board in which the game takes place. + * * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ @@ -19,8 +21,8 @@ public final class Board { /** * Instanciates a new Board with the given sequence of blocks. * - * @throws IllegalArgumentEception if the blocks is not composed of 195 elements - * @param blocks sequence conataining all the blocks of the Boards + * @throws IllegalArgumentException if the blocks is not composed of 195 elements + * @param blocks sequence containing all the blocks of the Boards */ public Board (List> blocks) { if (blocks.size() != 195) { @@ -95,11 +97,11 @@ public final class Board { } /** - * Build a symetric walled board from the NWB quadrant. + * Build a symmetric walled board from the NWB quadrant. * * @param quadrantNWBlocks the NW quadrant of the board (inner blocks only!) * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 - * @return a new walled board simmetricaly filled with the given NW quadrant + * @return a new walled board symmetrically filled with the given NW quadrant */ public static Board ofQuadrantNWBlocksWalled(List> quadrantNWBlocks) { if (quadrantNWBlocks.size() != 6) { diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index 8793adb..0992876 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -1,33 +1,39 @@ package ch.epfl.xblast.server; +/** + * The Ticks interface defines durations in ticks of time-sensitive aspects of the game. + * + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public interface Ticks { /** - * Duration of the death of a player. + * Duration of the death of a player (in ticks). */ public static int PLAYER_DYING_TICKS = 8; /** - * Duration of the invulnerability of a player. + * Duration of the invulnerability of a player (in ticks). */ public static int PLAYER_INVULNERABLE_TICKS = 64; /** - * Duration of the timer of a bomb. + * Duration of the timer of a bomb (in ticks). */ public static int BOMB_FUSE_TICKS = 100; /** - * Duration of an explosion. + * Duration of an explosion (in ticks). */ public static int EXPLOSION_TICKS = 30; /** - * Duration of crumbling of a wall. + * Duration of crumbling of a wall (in ticks). */ public static int WALL_CRUMBLLING_TICKS = EXPLOSION_TICKS; /** - * Duration of the presence of a bonus. + * Duration of the presence of a bonus (in ticks). */ public static int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; } -- cgit v1.2.3 From 1c2350a9f65068cc2e41ff1d471e5a73c55751f0 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 15:31:05 +0100 Subject: Add missing library --- .gitignore | 2 +- lib/sq.jar | Bin 0 -> 6651 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 lib/sq.jar diff --git a/.gitignore b/.gitignore index 5a61770..de15d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,7 @@ local.properties .mtj.tmp/ # Package Files # -*.jar +#*.jar *.war *.ear diff --git a/lib/sq.jar b/lib/sq.jar new file mode 100644 index 0000000..44bbc9a Binary files /dev/null and b/lib/sq.jar differ -- cgit v1.2.3 From f28560be9aceaf407613834a8fade1bfeedda449 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 15:34:45 +0100 Subject: Reformat code --- src/ch/epfl/xblast/Lists.java | 8 +++++--- src/ch/epfl/xblast/server/Block.java | 1 + src/ch/epfl/xblast/server/Board.java | 26 ++++++++++++++------------ src/ch/epfl/xblast/server/Ticks.java | 2 ++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index 096ceba..aadc694 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java @@ -1,20 +1,21 @@ package ch.epfl.xblast; -import java.util.List; import java.util.ArrayList; import java.util.Collections; +import java.util.List; /** * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ public final class Lists { + /** * Return a sysmetric version of the list. * * @param l the input list - * @throws IllegalArgumentException if the given list is empty * @return mirroredList the mirrored ilist + * @throws IllegalArgumentException if the given list is empty */ public static List mirrored(List l) { if (l.size() == 0) { @@ -24,7 +25,7 @@ public final class Lists { List mirroredList = new ArrayList(); List rightSide = new ArrayList(); - for (int i=0;i < l.size()-1;i++) { + for (int i = 0; i < l.size() - 1; i++) { rightSide.add(l.get(i)); } @@ -35,4 +36,5 @@ public final class Lists { return mirroredList; } + } diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java index d1c96e5..409f68e 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java @@ -54,4 +54,5 @@ public enum Block { public boolean castsShadow() { return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; } + } diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index b385ed8..62cfd0a 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -1,18 +1,19 @@ package ch.epfl.xblast.server; -import java.util.List; -import java.util.ArrayList; import ch.epfl.cs108.Sq; import ch.epfl.xblast.Lists; +import java.util.ArrayList; +import java.util.List; + /** * A two-dimensional Board in which the game takes place. * * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ - public final class Board { + /** * List containing all the blocks of the board. */ @@ -21,10 +22,10 @@ public final class Board { /** * Instanciates a new Board with the given sequence of blocks. * - * @throws IllegalArgumentException if the blocks is not composed of 195 elements * @param blocks sequence containing all the blocks of the Boards + * @throws IllegalArgumentException if the blocks is not composed of 195 elements */ - public Board (List> blocks) { + public Board(List> blocks) { if (blocks.size() != 195) { throw new IllegalArgumentException(); } @@ -35,8 +36,8 @@ public final class Board { * Build a new Board with the given Matrix. * * @param rows list containing all the rows - * @throws IllegalArgumentException if rows is not 13*15 * @return a new Board built with given rows + * @throws IllegalArgumentException if rows is not 13*15 */ public static Board ofRows(List> rows) { if (rows.size() != 13) { @@ -60,11 +61,11 @@ public final class Board { } /** - * Build a walled board filled with the given inner rows + * Build a walled board filled with the given inner rows * * @param innerBlocks lists of the internal rows - * @throws IllegalArgumentException if innerbLocks is not 11*13 * @return a new walled board filled with the given rows + * @throws IllegalArgumentException if innerbLocks is not 11*13 */ public static Board ofInnerBlocksWalled(List> innerBlocks) { if (innerBlocks.size() != 11) { @@ -74,7 +75,7 @@ public final class Board { List> rowsList = new ArrayList<>(); List wallLine = new ArrayList<>(); - for (int i = 0; i < 15;i++) { + for (int i = 0; i < 15; i++) { wallLine.add(Block.INDESTRUCTIBLE_WALL); } @@ -84,13 +85,13 @@ public final class Board { } List row = innerBlocks.get(i); - row.add(0,Block.INDESTRUCTIBLE_WALL); + row.add(0, Block.INDESTRUCTIBLE_WALL); row.add(Block.INDESTRUCTIBLE_WALL); rowsList.add(row); } - rowsList.add(0,wallLine); + rowsList.add(0, wallLine); rowsList.add(wallLine); return ofRows(rowsList); @@ -100,8 +101,8 @@ public final class Board { * Build a symmetric walled board from the NWB quadrant. * * @param quadrantNWBlocks the NW quadrant of the board (inner blocks only!) - * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 * @return a new walled board symmetrically filled with the given NW quadrant + * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 */ public static Board ofQuadrantNWBlocksWalled(List> quadrantNWBlocks) { if (quadrantNWBlocks.size() != 6) { @@ -121,4 +122,5 @@ public final class Board { } return ofInnerBlocksWalled(rowsList); } + } diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index 0992876..cdccad8 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -7,6 +7,7 @@ package ch.epfl.xblast.server; * @author Timothée FLOURE (257420) */ public interface Ticks { + /** * Duration of the death of a player (in ticks). */ @@ -36,4 +37,5 @@ public interface Ticks { * Duration of the presence of a bonus (in ticks). */ public static int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; + } -- cgit v1.2.3 From 57ac52bb05bef4be369ee4cf2794afb50362d3a3 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 15:35:37 +0100 Subject: Elaborate documentation --- src/ch/epfl/xblast/Lists.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index aadc694..f468788 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java @@ -5,16 +5,18 @@ import java.util.Collections; import java.util.List; /** + * Lists utility class providing common operations on lists. + * * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ public final class Lists { /** - * Return a sysmetric version of the list. + * Return a symmetric version of the list. * * @param l the input list - * @return mirroredList the mirrored ilist + * @return mirroredList the mirrored list * @throws IllegalArgumentException if the given list is empty */ public static List mirrored(List l) { -- cgit v1.2.3 From ee00d0bfbfa5ea253559038c27a23da33c528d0e Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 15:36:04 +0100 Subject: Fix typo in constant name --- src/ch/epfl/xblast/server/Ticks.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index cdccad8..c19f073 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -31,11 +31,11 @@ public interface Ticks { /** * Duration of crumbling of a wall (in ticks). */ - public static int WALL_CRUMBLLING_TICKS = EXPLOSION_TICKS; + public static int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; /** * Duration of the presence of a bonus (in ticks). */ public static int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; - + } -- cgit v1.2.3 From 7c19be7f34b932d696d839a092f05617400589f6 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:25:37 +0100 Subject: Rewrite list mirroring function and add test --- src/ch/epfl/xblast/Lists.java | 43 +++++++++++++++++++++----------------- test/ch/epfl/xblast/ListsTest.java | 40 ++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index f468788..51e76b0 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java @@ -3,6 +3,8 @@ package ch.epfl.xblast; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Lists utility class providing common operations on lists. @@ -13,30 +15,33 @@ import java.util.List; public final class Lists { /** - * Return a symmetric version of the list. + * Returns a reversed copy of the given list, leaving the original one unmodified. * - * @param l the input list - * @return mirroredList the mirrored list + * @param l the list to reverse + * @param the type of the list's elements + * @return a reversed copy of the list. + */ + public static List reversed(List l) { + List r = new ArrayList<>(l); + Collections.reverse(r); + return r; + } + + /** + * Returns a symmetric version of the list, without repeating the last element of the input list. + * For instance, mirrored([kay]) will return [kayak]. + * + * @param l the input list + * @param the type of the list's elements + * @return the mirrored list * @throws IllegalArgumentException if the given list is empty */ public static List mirrored(List l) { - if (l.size() == 0) { - throw new IllegalArgumentException(); - } - - List mirroredList = new ArrayList(); - List rightSide = new ArrayList(); - - for (int i = 0; i < l.size() - 1; i++) { - rightSide.add(l.get(i)); - } - - Collections.reverse(rightSide); - - mirroredList.addAll(l); - mirroredList.addAll(rightSide); + if (l == null || l.size() == 0) throw new IllegalArgumentException(); - return mirroredList; + return Stream + .concat(l.stream(), Lists.reversed(l).stream().skip(1)) + .collect(Collectors.toList()); } } diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 42b317f..0a2f5f9 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -1,26 +1,42 @@ package ch.epfl.xblast; -import java.util.List; -import java.util.Arrays; -import static org.junit.Assert.*; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; + /** -* @author Pacien TRAN-GIRARD (261948) -* @author Timothée FLOURE (257420) -*/ + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public class ListsTest { - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void isEmptyListThrowingException() { - List sampleList = Arrays.asList(); - Lists.mirrored(sampleList); + List emptyList = new ArrayList<>(); + Lists.mirrored(emptyList); } @Test public void isListMirrored() { - List sampleList = Arrays.asList(1,2,3,4,5); - List expected = Arrays.asList(1,2,3,4,5,4,3,2,1); + List sampleList = Arrays.asList(1, 2, 3, 4, 5); + List expected = Arrays.asList(1, 2, 3, 4, 5, 4, 3, 2, 1); + + assertEquals(expected, Lists.mirrored(sampleList)); + } - assertEquals(expected, Lists.mirrored(sampleList)); + @Test + public void mirrorElementsAreEqual() { + List sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); + List mirrored = Lists.mirrored(sampleList); + + for (int i = 0; i < mirrored.size() / 2; ++i) + assertEquals(mirrored.get(i), mirrored.get(mirrored.size() - 1 - i)); } + } -- cgit v1.2.3 From 7d26df97d90532b7fa094def157ea38c13a8c0f9 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:32:05 +0100 Subject: Add mirrored list size test --- test/ch/epfl/xblast/ListsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 0a2f5f9..b898399 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -30,6 +30,15 @@ public class ListsTest { assertEquals(expected, Lists.mirrored(sampleList)); } + @Test + public void mirroredListSizeIsCorrect() { + int sampleSize = 10; + List sampleList = IntStream.range(0, sampleSize).boxed().collect(Collectors.toList()); + List mirrored = Lists.mirrored(sampleList); + + assertEquals(sampleSize * 2 - 1, mirrored.size()); + } + @Test public void mirrorElementsAreEqual() { List sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); -- cgit v1.2.3 From e25492f5f71b4ad4e09e485fe46b5dd60a568994 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:37:56 +0100 Subject: Remove redundant explicit type declaration --- src/ch/epfl/xblast/server/Board.java | 4 ++-- src/ch/epfl/xblast/server/Ticks.java | 12 +++++------ test/ch/epfl/xblast/server/BoardTest.java | 34 +++++++++++++++---------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index 62cfd0a..5e899f6 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -111,14 +111,14 @@ public final class Board { List> rowsList = new ArrayList<>(); - List> halfInnerBoard = Lists.>mirrored(quadrantNWBlocks); + List> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); for (int i = 0; i < halfInnerBoard.size(); i++) { if (halfInnerBoard.get(i).size() != 7) { throw new IllegalArgumentException(); } - rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); + rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); } return ofInnerBlocksWalled(rowsList); } diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index c19f073..aa08a23 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -11,31 +11,31 @@ public interface Ticks { /** * Duration of the death of a player (in ticks). */ - public static int PLAYER_DYING_TICKS = 8; + int PLAYER_DYING_TICKS = 8; /** * Duration of the invulnerability of a player (in ticks). */ - public static int PLAYER_INVULNERABLE_TICKS = 64; + int PLAYER_INVULNERABLE_TICKS = 64; /** * Duration of the timer of a bomb (in ticks). */ - public static int BOMB_FUSE_TICKS = 100; + int BOMB_FUSE_TICKS = 100; /** * Duration of an explosion (in ticks). */ - public static int EXPLOSION_TICKS = 30; + int EXPLOSION_TICKS = 30; /** * Duration of crumbling of a wall (in ticks). */ - public static int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; + int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; /** * Duration of the presence of a bonus (in ticks). */ - public static int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; + int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; } diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index e40769b..673ab3b 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -14,14 +14,14 @@ import static org.junit.Assert.*; public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isBoardBuilderEmptyInputThrowingException() { - List> blocks = new ArrayList>(); + List> blocks = new ArrayList<>(); new Board(blocks); } @Test(expected=IllegalArgumentException.class) public void isBoardBuilderIllegalInputThrowingException() { - List> blocks = new ArrayList>(); + List> blocks = new ArrayList<>(); for (int i = 0;i<8;i++) { blocks.add(Sq.constant(Block.FREE)); @@ -33,14 +33,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isOfRowsEmptyInputMatrixThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofRows(rowsList); } @Test(expected=IllegalArgumentException.class) public void isOfRowsIllegalInputThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -52,10 +52,10 @@ public class BoardTest { @Test public void buildBoardFromRowsMatrix() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 13; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 15; j++) { sampleRow.add(Block.FREE); } @@ -67,14 +67,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isOfInnerBlocksWalledEmptyInputMatrixThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofInnerBlocksWalled(rowsList); } @Test(expected=IllegalArgumentException.class) public void isOfInnerBlocksWalledIllegalInputThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -86,10 +86,10 @@ public class BoardTest { @Test public void buildBoardFromInnerBlocks() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 11; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 13; j++) { sampleRow.add(Block.FREE); } @@ -101,14 +101,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isBuildWithEmptyQuadrantThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofQuadrantNWBlocksWalled(rowsList); } @Test(expected=IllegalArgumentException.class) public void isBuildWithIllegalQuadrantThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -120,10 +120,10 @@ public class BoardTest { @Test public void buildBoardFromNWQuadrant() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 6; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 7; j++) { sampleRow.add(Block.FREE); } -- cgit v1.2.3 From 55e19228a2b9119f136f62b050421ac91cdecf53 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:38:27 +0100 Subject: Fix typo in function name --- test/ch/epfl/xblast/server/BlockTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java index bbe4376..6cfc853 100644 --- a/test/ch/epfl/xblast/server/BlockTest.java +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -26,7 +26,7 @@ public class BlockTest { } @Test - public void castSadhow() { + public void castShadow() { assertTrue(Block.INDESTRUCTIBLE_WALL.castsShadow()); assertTrue(Block.DESTRUCTIBLE_WALL.castsShadow()); assertTrue(Block.CRUMBLING_WALL.castsShadow()); -- cgit v1.2.3 From b25cee830238c64c08a2e3733bbed0730d20a734 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 1 Mar 2016 16:26:40 +0100 Subject: Add the blocksAt() and blockAt() methods to the Board class --- src/ch/epfl/xblast/server/Board.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index 5e899f6..2cbf380 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -2,6 +2,7 @@ package ch.epfl.xblast.server; import ch.epfl.cs108.Sq; import ch.epfl.xblast.Lists; +import ch.epfl.xblast.Cell; import java.util.ArrayList; import java.util.List; @@ -123,4 +124,23 @@ public final class Board { return ofInnerBlocksWalled(rowsList); } + /** + * Return the sequence of blocks related to the given cell. + * + * @param c cell + * @return the sequence of blocks related to the given cell. + */ + public Sq blocksAt(Cell c) { + return blocks.get(c.rowMajorIndex()); + } + + /** + * Returns the block related to the given cell. + * + * @param c cell + * @return the first block of the sequence related to the given cell + */ + public Block blockAt(Cell c) { + return blocksAt(c).head(); + } } -- cgit v1.2.3 From 80143bb3522007a903f2a34967e0cf5b0d6b20e0 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 1 Mar 2016 16:59:56 +0100 Subject: Add the test related to the blockAt() method --- src/ch/epfl/xblast/Direction.java | 2 +- test/ch/epfl/xblast/server/BoardTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ch/epfl/xblast/Direction.java b/src/ch/epfl/xblast/Direction.java index 700f9be..030038b 100644 --- a/src/ch/epfl/xblast/Direction.java +++ b/src/ch/epfl/xblast/Direction.java @@ -2,7 +2,7 @@ package ch.epfl.xblast; /** * A Direction. - * + * * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 673ab3b..b23ac06 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import org.junit.Test; import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Cell; import static org.junit.Assert.*; @@ -132,4 +133,22 @@ public class BoardTest { assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); } + + @Test + public void isBlockAtReturningTheRightBlock() { + Cell sampleCell = new Cell(0,0); + Cell sampleCell2 = new Cell(3,4); + + List> blocksList = new ArrayList<>(); + + blocksList.add(Sq.constant(Block.INDESTRUCTIBLE_WALL)); + for (int i = 0; i < 194; i++) { + blocksList.add(Sq.constant(Block.FREE)); + } + Board sampleBoard = new Board(blocksList); + + assertTrue(sampleBoard.blockAt(sampleCell) == Block.INDESTRUCTIBLE_WALL); + assertTrue(sampleBoard.blockAt(sampleCell2) == Block.FREE); + } + } -- cgit v1.2.3 From e63054be16b46155968a748c83a600f28ac8c4aa Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 1 Mar 2016 17:20:57 +0100 Subject: Board Class : remove magic numbers + get ride of duplicated code --- src/ch/epfl/xblast/server/Board.java | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index 2cbf380..d47bdd3 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -14,6 +14,33 @@ import java.util.List; * @author Timothée FLOURE (257420) */ public final class Board { + private static final int BLOCKS_LIST_SIZE = 195; + private static final int BOARD_ROWS = 13; + private static final int BOARD_COLUMNS = 15; + private static final int INNER_BOARD_ROWS = BOARD_ROWS - 2; + private static final int INNER_BOARD_COLUMNS = BOARD_COLUMNS - 2; + private static final int QUADRANT_ROWS = 6; + private static final int QUADRANT_COLUMNS = 7; + + /** + * Throw an exeption if the matrix does not have the given number of rows/columns. + * + * @param matrix the tested matrix + * @param rows the expected number of rows + * @param columns the expected number of columns + * @throws IllegalArgumentException if the matrix does not comply with the given sizes. + */ + private static void checkBlockMatrix(List> matrix, int rows, int columns) { + if (matrix.size() != rows) { + throw new IllegalArgumentException(); + } else { + for (int i = 0; i < rows; i++) { + if (matrix.get(i).size() != columns) { + throw new IllegalArgumentException(); + } + } + } + } /** * List containing all the blocks of the board. @@ -27,7 +54,7 @@ public final class Board { * @throws IllegalArgumentException if the blocks is not composed of 195 elements */ public Board(List> blocks) { - if (blocks.size() != 195) { + if (blocks.size() != BLOCKS_LIST_SIZE) { throw new IllegalArgumentException(); } this.blocks = blocks; @@ -41,18 +68,10 @@ public final class Board { * @throws IllegalArgumentException if rows is not 13*15 */ public static Board ofRows(List> rows) { - if (rows.size() != 13) { - throw new IllegalArgumentException(); - } - + checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); List> blocksSequence = new ArrayList<>(); for (int i = 0; i < rows.size(); i++) { - - if (rows.get(i).size() != 15) { - throw new IllegalArgumentException(); - } - for (int j = 0; j < rows.get(i).size(); j++) { blocksSequence.add(Sq.constant(rows.get(i).get(j))); } @@ -69,22 +88,15 @@ public final class Board { * @throws IllegalArgumentException if innerbLocks is not 11*13 */ public static Board ofInnerBlocksWalled(List> innerBlocks) { - if (innerBlocks.size() != 11) { - throw new IllegalArgumentException(); - } - + checkBlockMatrix(innerBlocks, INNER_BOARD_ROWS, INNER_BOARD_COLUMNS); List> rowsList = new ArrayList<>(); List wallLine = new ArrayList<>(); - for (int i = 0; i < 15; i++) { + for (int i = 0; i < BOARD_COLUMNS; i++) { wallLine.add(Block.INDESTRUCTIBLE_WALL); } for (int i = 0; i < innerBlocks.size(); i++) { - if (innerBlocks.get(i).size() != 13) { - throw new IllegalArgumentException(); - } - List row = innerBlocks.get(i); row.add(0, Block.INDESTRUCTIBLE_WALL); row.add(Block.INDESTRUCTIBLE_WALL); @@ -106,19 +118,11 @@ public final class Board { * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 */ public static Board ofQuadrantNWBlocksWalled(List> quadrantNWBlocks) { - if (quadrantNWBlocks.size() != 6) { - throw new IllegalArgumentException(); - } - + checkBlockMatrix(quadrantNWBlocks, QUADRANT_ROWS, QUADRANT_COLUMNS); List> rowsList = new ArrayList<>(); - List> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); for (int i = 0; i < halfInnerBoard.size(); i++) { - if (halfInnerBoard.get(i).size() != 7) { - throw new IllegalArgumentException(); - } - rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); } return ofInnerBlocksWalled(rowsList); -- cgit v1.2.3 From 4745bff1ce9888effe8ec26253e4349d47436a05 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 1 Mar 2016 17:25:52 +0100 Subject: Board class : fix magic numbers in comments --- src/ch/epfl/xblast/server/Board.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index d47bdd3..bde0ae9 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -51,7 +51,7 @@ public final class Board { * Instanciates a new Board with the given sequence of blocks. * * @param blocks sequence containing all the blocks of the Boards - * @throws IllegalArgumentException if the blocks is not composed of 195 elements + * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements */ public Board(List> blocks) { if (blocks.size() != BLOCKS_LIST_SIZE) { @@ -65,7 +65,7 @@ public final class Board { * * @param rows list containing all the rows * @return a new Board built with given rows - * @throws IllegalArgumentException if rows is not 13*15 + * @throws IllegalArgumentException if rows is not BOARD_ROWS * BOARD_COLUMNS */ public static Board ofRows(List> rows) { checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); @@ -85,7 +85,7 @@ public final class Board { * * @param innerBlocks lists of the internal rows * @return a new walled board filled with the given rows - * @throws IllegalArgumentException if innerbLocks is not 11*13 + * @throws IllegalArgumentException if innerbLocks is not INNER_BOARD_ROWS * INNER_BOARD_COLUMNS */ public static Board ofInnerBlocksWalled(List> innerBlocks) { checkBlockMatrix(innerBlocks, INNER_BOARD_ROWS, INNER_BOARD_COLUMNS); @@ -115,7 +115,7 @@ public final class Board { * * @param quadrantNWBlocks the NW quadrant of the board (inner blocks only!) * @return a new walled board symmetrically filled with the given NW quadrant - * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7 + * @throws IllegalArgumentException if quadrantNWBlocks is not QUADRANT_ROWS * QUADRANT_COLUMNS */ public static Board ofQuadrantNWBlocksWalled(List> quadrantNWBlocks) { checkBlockMatrix(quadrantNWBlocks, QUADRANT_ROWS, QUADRANT_COLUMNS); -- cgit v1.2.3 From a111835984e2d6abbf3dcab317cf97c0f5842ba1 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 1 Mar 2016 17:38:14 +0100 Subject: Reformat code and doc-blocks --- src/ch/epfl/xblast/server/Board.java | 14 ++++--- test/ch/epfl/xblast/CellTest.java | 29 ++++++++------ test/ch/epfl/xblast/DirectionTest.java | 2 + test/ch/epfl/xblast/SubCellTest.java | 25 +++++++----- test/ch/epfl/xblast/namecheck/NameCheck01.java | 11 ++++-- test/ch/epfl/xblast/namecheck/NameCheck02.java | 9 +++-- test/ch/epfl/xblast/server/BlockTest.java | 5 ++- test/ch/epfl/xblast/server/BoardTest.java | 53 +++++++++++++------------- 8 files changed, 86 insertions(+), 62 deletions(-) diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index bde0ae9..4d2e743 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -1,8 +1,8 @@ package ch.epfl.xblast.server; import ch.epfl.cs108.Sq; -import ch.epfl.xblast.Lists; import ch.epfl.xblast.Cell; +import ch.epfl.xblast.Lists; import java.util.ArrayList; import java.util.List; @@ -14,6 +14,7 @@ import java.util.List; * @author Timothée FLOURE (257420) */ public final class Board { + private static final int BLOCKS_LIST_SIZE = 195; private static final int BOARD_ROWS = 13; private static final int BOARD_COLUMNS = 15; @@ -23,10 +24,10 @@ public final class Board { private static final int QUADRANT_COLUMNS = 7; /** - * Throw an exeption if the matrix does not have the given number of rows/columns. + * Throw an exception if the matrix does not have the given number of rows/columns. * - * @param matrix the tested matrix - * @param rows the expected number of rows + * @param matrix the tested matrix + * @param rows the expected number of rows * @param columns the expected number of columns * @throws IllegalArgumentException if the matrix does not comply with the given sizes. */ @@ -48,7 +49,7 @@ public final class Board { private List> blocks; /** - * Instanciates a new Board with the given sequence of blocks. + * Instantiates a new Board with the given sequence of blocks. * * @param blocks sequence containing all the blocks of the Boards * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements @@ -85,7 +86,7 @@ public final class Board { * * @param innerBlocks lists of the internal rows * @return a new walled board filled with the given rows - * @throws IllegalArgumentException if innerbLocks is not INNER_BOARD_ROWS * INNER_BOARD_COLUMNS + * @throws IllegalArgumentException if innerBlocks is not INNER_BOARD_ROWS * INNER_BOARD_COLUMNS */ public static Board ofInnerBlocksWalled(List> innerBlocks) { checkBlockMatrix(innerBlocks, INNER_BOARD_ROWS, INNER_BOARD_COLUMNS); @@ -147,4 +148,5 @@ public final class Board { public Block blockAt(Cell c) { return blocksAt(c).head(); } + } diff --git a/test/ch/epfl/xblast/CellTest.java b/test/ch/epfl/xblast/CellTest.java index ba8becc..c5d93e8 100644 --- a/test/ch/epfl/xblast/CellTest.java +++ b/test/ch/epfl/xblast/CellTest.java @@ -1,15 +1,19 @@ package ch.epfl.xblast; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import org.junit.Test; - +/** + * @author EPFL + */ public class CellTest { + @Test public void rowMajorIndexCorrespondsToOrder() { int i = 0; - for (Cell c: Cell.ROW_MAJOR_ORDER) + for (Cell c : Cell.ROW_MAJOR_ORDER) assertEquals(i++, c.rowMajorIndex()); assertEquals(Cell.COUNT, i); } @@ -19,7 +23,7 @@ public class CellTest { assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size()); boolean[] cellSeen = new boolean[Cell.COUNT]; - for (Cell c: Cell.SPIRAL_ORDER) { + for (Cell c : Cell.SPIRAL_ORDER) { assertFalse(cellSeen[c.rowMajorIndex()]); cellSeen[c.rowMajorIndex()] = true; } @@ -28,9 +32,9 @@ public class CellTest { @Test public void spiralOrderNeighborsAreSpatialNeighbors() { Cell pred = Cell.SPIRAL_ORDER.get(0); - for (Cell c: Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { + for (Cell c : Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { int areNeighborsCount = 0; - for (Direction d: Direction.values()) { + for (Direction d : Direction.values()) { if (pred.equals(c.neighbor(d))) areNeighborsCount += 1; } @@ -51,18 +55,19 @@ public class CellTest { @Test public void neighborsOfOriginAreCorrect() { Cell c = new Cell(0, 0); - assertEquals(new Cell( 0, 12), c.neighbor(Direction.N)); - assertEquals(new Cell( 1, 0), c.neighbor(Direction.E)); - assertEquals(new Cell( 0, 1), c.neighbor(Direction.S)); - assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); + assertEquals(new Cell(0, 12), c.neighbor(Direction.N)); + assertEquals(new Cell(1, 0), c.neighbor(Direction.E)); + assertEquals(new Cell(0, 1), c.neighbor(Direction.S)); + assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); } @Test public void oppositeNeighborOfNeighborIsThis() { - for (Cell c: Cell.ROW_MAJOR_ORDER) { - for (Direction d: Direction.values()) { + for (Cell c : Cell.ROW_MAJOR_ORDER) { + for (Direction d : Direction.values()) { assertEquals(c, c.neighbor(d).neighbor(d.opposite())); } } } + } diff --git a/test/ch/epfl/xblast/DirectionTest.java b/test/ch/epfl/xblast/DirectionTest.java index 0ebb3b7..49cf4be 100644 --- a/test/ch/epfl/xblast/DirectionTest.java +++ b/test/ch/epfl/xblast/DirectionTest.java @@ -9,6 +9,7 @@ import static org.junit.Assert.*; * @author Pacien TRAN-GIRARD (261948) */ public class DirectionTest { + @Test public void oppositeOfOppositeIsIdentity() { for (Direction d : Direction.values()) @@ -48,4 +49,5 @@ public class DirectionTest { assertEquals(0, d.yVector() + d.opposite().yVector()); } } + } diff --git a/test/ch/epfl/xblast/SubCellTest.java b/test/ch/epfl/xblast/SubCellTest.java index 1c79791..b3450e1 100644 --- a/test