From bbfbdb05394079c65bbedfde6b89879c19269081 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 12 Mar 2020 12:38:00 +0100 Subject: [PATCH 01/11] fixed some methods in player --- .../fiasko/roborally/objects/Player.java | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Player.java b/src/main/java/inf112/fiasko/roborally/objects/Player.java index 75908b3..10c4b93 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Player.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Player.java @@ -14,23 +14,16 @@ public class Player { private final String name; private boolean powerDownNextRound = false; private ProgrammingCardDeck playerDeck; - private List program = new ArrayList(); + private List program; /** * Instantiates a new player * @param robotID the global identifier of the robot * @param name the unique name of the player - * @param playerDeck the hand of cards dealt to the player */ - public Player(RobotID robotID, String name, ProgrammingCardDeck playerDeck) { + public Player(RobotID robotID, String name) { this.robotID = robotID; this.name = name; - this.playerDeck = playerDeck; - program.add(0, null); //sets the initial values in program to null - program.add(1, null); - program.add(2, null); - program.add(3, null); - program.add(4, null); } /** @@ -39,6 +32,14 @@ public class Player { */ public RobotID getRobotID(){return robotID;} + /** + * Set the players deck to the given deck + * @param playerDeck a deck of cards given to the player + */ + public void setPlayerDeck(ProgrammingCardDeck playerDeck){ + this.playerDeck=playerDeck; + } + /** * Gives you the Name of the player * @return a player Name @@ -70,32 +71,23 @@ public class Player { public void setPowerDownNextRound(boolean powerDownStatus) { this.powerDownNextRound = powerDownStatus;} /** - * Places a card in to the player program - * @param card the card that is placed in to the player program + * Gets the program from the player + * @return List of programing cards */ - public void setCardInProgram(ProgrammingCard card) { - for (int i = 0; i < 5; i++) { - if (program.get(i) == null) { - program.add(i, card); - return; - } - } - throw new IllegalArgumentException("Program deck is full,tried to add to many cards"); + public List getProgramFromPlayer(){ + return program; } /** - * Removes a card by the given index from the player program and returns it. - * @param cardNr the index of the card that is being removed - * @return the card that was removed from the program + * Sets the Players program to the given list of programing cards + * @param cardList list the size of 5 with programing cards */ - public ProgrammingCard removeProgramCard(int cardNr) { - if(cardNr<5 && cardNr>-1) { - program.add(cardNr, null); - return program.remove(cardNr + 1); + public void setInProgram(List cardList){ + if(cardList.size() != 5){ + throw new IllegalArgumentException("list must contain 5 programing cards"); } - else{ - throw new IllegalArgumentException("cant remove more then index 4 or remove negatives"); - + else { + program = new ArrayList<>(cardList); } } From 7bc24ff03e2f2a29fe609c0e1ab4785f6464d303 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 12 Mar 2020 12:38:33 +0100 Subject: [PATCH 02/11] added and altered some test in PlayerTest --- .../fiasko/roborally/objects/PlayerTest.java | 108 +++++++----------- 1 file changed, 39 insertions(+), 69 deletions(-) diff --git a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java index 90e9cce..9277788 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java @@ -4,106 +4,76 @@ import inf112.fiasko.roborally.element_properties.Action; import inf112.fiasko.roborally.element_properties.RobotID; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.*; + public class PlayerTest { private Player playerTest; + private List cards = new ArrayList(); + @Before public void setUp() { - List cards = new ArrayList(); cards.add(new ProgrammingCard(10, Action.MOVE_1)); cards.add(new ProgrammingCard(20, Action.MOVE_2)); cards.add(new ProgrammingCard(30, Action.MOVE_3)); cards.add(new ProgrammingCard(40, Action.BACK_UP)); cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT)); ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); - playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ,playerDeck); + playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ); } @Test public void setPowerDownStatusToTrue() { playerTest.setPowerDownNextRound(true); - assertEquals(true, playerTest.getPowerDownNextRound()); + assertTrue(playerTest.getPowerDownNextRound()); } @Test public void setPowerDownStatusToFalse() { playerTest.setPowerDownNextRound(false); - assertEquals(false, playerTest.getPowerDownNextRound()); + assertFalse(playerTest.getPowerDownNextRound()); + } + @Test + public void testSetInProgram(){ + playerTest.setInProgram(cards); + assertEquals(Action.MOVE_1, playerTest.getProgramFromPlayer().get(0).getAction()); + assertEquals(Action.MOVE_2, playerTest.getProgramFromPlayer().get(1).getAction()); + assertEquals(Action.MOVE_3, playerTest.getProgramFromPlayer().get(2).getAction()); + assertEquals(Action.BACK_UP, playerTest.getProgramFromPlayer().get(3).getAction()); + } + + @Test (expected = IllegalArgumentException.class) + public void testSetInProgramWithToManyCards(){ + cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); + playerTest.setInProgram(cards); } @Test - public void cardGetsInsertedIntoProgram() { - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); - } - @Test - public void addMultipuleCards(){ - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); - playerTest.setCardInProgram(new ProgrammingCard(23452342,Action.MOVE_3)); - assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); - assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction()); - assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction()); - } - @Test(expected = IllegalArgumentException.class) - public void addTooManyCardsGetsAError() { - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); - playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(234523242,Action.MOVE_3)); - } - @Test - public void removeCardsFromPlayerProgram() { - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); - playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); - assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction()); - playerTest.removeProgramCard(4); - assertEquals(null,playerTest.getProgram().get(4)); - } - @Test - public void removeAllCardsFromPlayerProgram() { - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); - playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); - playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); - assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction()); - assertEquals(Action.MOVE_3,playerTest.getProgram().get(3).getAction()); - assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction()); - assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction()); - assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); - playerTest.removeProgramCard(4); - playerTest.removeProgramCard(3); - playerTest.removeProgramCard(2); - playerTest.removeProgramCard(1); - playerTest.removeProgramCard(0); - assertEquals(null,playerTest.getProgram().get(4)); - assertEquals(null,playerTest.getProgram().get(3)); - assertEquals(null,playerTest.getProgram().get(2)); - assertEquals(null,playerTest.getProgram().get(1)); - assertEquals(null,playerTest.getProgram().get(0)); + public void testSetInDeck(){ + cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); + ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); + playerTest.setPlayerDeck(playerDeck); + assertEquals(playerDeck , playerTest.getPlayerDeck()); } - @Test(expected = IllegalArgumentException.class) - public void getErrorIfYouRemoveMoreThenIndexFive(){ - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.removeProgramCard(5); - + @Test + public void GetPlayerRobotId(){ + assertEquals(RobotID.ROBOT_1, playerTest.getRobotID()); } - @Test(expected = IllegalArgumentException.class) - public void getErrorIfYouRemoveANegativIndex(){ - playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); - playerTest.removeProgramCard(-1); + @Test + public void GetPlayerName(){ + assertEquals("TestPlayer", playerTest.getName()); + } + + @Test + public void GetProgramFromPlayer(){ + playerTest.setInProgram(cards); + assertEquals(cards,playerTest.getProgram()); } } From 7bd59902e2e39a71379a3a7af8d85f69436e49a9 Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Mon, 16 Mar 2020 14:33:22 +0100 Subject: [PATCH 03/11] =?UTF-8?q?Referat=20fra=20m=C3=B8te.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/team/referater/referat_16_03_2020.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/team/referater/referat_16_03_2020.md diff --git a/docs/team/referater/referat_16_03_2020.md b/docs/team/referater/referat_16_03_2020.md new file mode 100644 index 0000000..640edbb --- /dev/null +++ b/docs/team/referater/referat_16_03_2020.md @@ -0,0 +1,15 @@ +## Oppmøte +Tilstede: Steinar, Gabriel, Kristian, Torbjørn, Petter +Ikke tilstede: + +## Agenda +- Design valg + +- Brukerhistorier + +- Fordele Oppgaver + +## Møte +- Diskuterte håndtering av framtidinge møter med tanke på korona situasjonen. +- Gikk igjennom prosjekt tavlen og gikk igjennom hver oppgave der. +- Avsluttet møte ved å dele oss opp i par-programmeringsgrupper. \ No newline at end of file From 31bef9fe0b758e308f2c246ef98f715f397e67c2 Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Mon, 16 Mar 2020 15:52:18 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Parprogrammering=20med=20tobydrama=20-=20?= =?UTF-8?q?Laget=20funksjonalitet=20for=20flagg=20registrering=20Lagt=20in?= =?UTF-8?q?n=20metoder=20og=20hjelpemetoder=20for=20=C3=A5=20f=C3=A5=20til?= =?UTF-8?q?=20registrering=20av=20flagg.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inf112/fiasko/roborally/objects/Board.java | 13 +++++++++++++ .../roborally/objects/BoardElementContainer.java | 2 +- .../fiasko/roborally/objects/RoboRallyGame.java | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 5ab22dc..f89c1b1 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -178,6 +178,19 @@ public class Board { return robots.containsKey(robot); } + /** + * Updates the flag of the robot if it stands on the correct flag. + * @param robotID The RobotID of a robot + * @param flagID TileType of the flag we check + */ + public void updateFlagOnRobot(RobotID robotID, TileType flagID) { + Robot robot = robots.get(robotID); + int flagNr = flagID.getTileTypeID() % 16; + if (flagNr - 1 == robot.getLastFlagVisited()) { + robot.setLastFlagVisitedAndUpdateBackupPosition(flagNr); + } + } + /** * Checks if a potential robot move would be blocked by a wall * @param robotPosition The current position of the robot diff --git a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java index e120140..7b253c7 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java +++ b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java @@ -8,7 +8,7 @@ import inf112.fiasko.roborally.element_properties.Position; */ public class BoardElementContainer { K obj; - Position pos; + private Position pos; /** * Initializes the BoardElementContainer diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 74ae131..21e0eb5 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -5,6 +5,7 @@ import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.RobotID; import inf112.fiasko.roborally.element_properties.TileType; import inf112.fiasko.roborally.utility.BoardLoaderUtil; +import javafx.geometry.Pos; import java.io.IOException; import java.util.ArrayList; @@ -204,4 +205,19 @@ public class RoboRallyGame implements IDrawableGame { } } } + + /** + * Checks all flags for robots. Tries to update the flag of the robot. + */ + private void checkAllFlags() { + List> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, + TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4); + for (BoardElementContainer flag:listOfFlags) { + Position flagPosition = flag.getPosition(); + if (gameBoard.hasRobotOnPosition(flagPosition)) { + RobotID robot = gameBoard.getRobotOnPosition(flagPosition); + gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType()); + } + } + } } \ No newline at end of file From c43798dfab78a314ee5b4f8c2d120a50c8621868 Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Mon, 16 Mar 2020 15:52:50 +0100 Subject: [PATCH 05/11] Parprogrammering med tobydrama - Laget Tester for registrering av flagg. --- .../fiasko/roborally/objects/BoardTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index d80bd61..f7ce301 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -61,7 +61,26 @@ public class BoardTest { wallGrid.setElement(2, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST)); + tileGrid.setElement(3,3, new Tile(TileType.FLAG_1, Direction.NORTH)); + tileGrid.setElement(2,2, new Tile(TileType.FLAG_2, Direction.NORTH)); board = new Board(tileGrid, wallGrid, robotList); + + } + + @Test + public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() { + Robot testRobot = robotList.get(6); + assertEquals(0,testRobot.getLastFlagVisited()); + board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_1); + assertEquals(1,testRobot.getLastFlagVisited()); + } + + @Test + public void flagDoesNotUpdatedOnRobotWithWringLastVisitedFlag() { + Robot testRobot = robotList.get(6); + assertEquals(0,testRobot.getLastFlagVisited()); + board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_2); + assertEquals(0,testRobot.getLastFlagVisited()); } @Test From f01576d34e4ba3426f8bfc1379000b63a1440ce4 Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Mon, 16 Mar 2020 16:45:45 +0100 Subject: [PATCH 06/11] Laget tester for getPositionsOfWallOnBoard og getPositionsOfTileOnBoard --- .../fiasko/roborally/objects/BoardTest.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index d80bd61..7d0d4bc 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -10,7 +10,10 @@ import org.junit.BeforeClass; import org.junit.Test; import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; import java.util.List; +import java.util.function.Predicate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -31,6 +34,9 @@ public class BoardTest { private static Position someValidPosition8; private List robotList; private Board board; + private Board boardWithDifferentAmountOfAllTypes; + private Map wallTypeNumberMap = new HashMap<>(); + private Map tileTypeNumberMap = new HashMap<>(); @BeforeClass public static void globalSetUp() { @@ -62,6 +68,31 @@ public class BoardTest { wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST)); board = new Board(tileGrid, wallGrid, robotList); + + Grid tileGridAllTypes = new Grid<>(6,6); + Grid wallGridAllTypes = new Grid<>(6,6); + List emptyRobotList = new ArrayList<>(); + wallGridAllTypes.setElement(1, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(1, 2, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(1, 3, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(2, 1, new Wall(WallType.WALL_CORNER, Direction.EAST)); + wallGridAllTypes.setElement(2, 2, new Wall(WallType.WALL_CORNER, Direction.EAST)); + tileGridAllTypes.setElement(1, 1, new Tile(TileType.COGWHEEL_LEFT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 1, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 2, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 3, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 4, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(2, 1, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 2, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 3, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 4, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 5, new Tile(TileType.TILE, Direction.WEST)); + wallTypeNumberMap.put(WallType.WALL_NORMAL, 3); + wallTypeNumberMap.put(WallType.WALL_CORNER, 2); + tileTypeNumberMap.put(TileType.COGWHEEL_RIGHT, 4); + tileTypeNumberMap.put(TileType.COGWHEEL_LEFT, 1); + tileTypeNumberMap.put(TileType.TILE, 5); + boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes,wallGridAllTypes,emptyRobotList); } @Test @@ -161,4 +192,72 @@ public class BoardTest { board.respawnRobots(); assertFalse(board.isRobotAlive(robot.getRobotId())); } + + @Test + public void getPositionsOfTileOnBoardGivesCorrectAmountOfCogwheelLeftTiles() { + assertEquals((int)tileTypeNumberMap.get(TileType.COGWHEEL_LEFT), + boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT).size()); + } + + @Test + public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getTileType(), TileType.COGWHEEL_LEFT); + } + } + + @Test + public void getPositionsOfTileOnBoardGivesCorrectAmountOfTileTiles() { + assertEquals((int)tileTypeNumberMap.get(TileType.TILE), + boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE).size()); + } + + @Test + public void getPositionsOfTileOnBoardHasTypeTile() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getTileType(), TileType.TILE); + } + } + + @Test + public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallNormalWalls() { + assertEquals((int)wallTypeNumberMap.get(WallType.WALL_NORMAL), + boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL).size()); + } + + @Test + public void getPositionsOfWallOnBoardHasTypeWallNormal() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getWallType(), WallType.WALL_NORMAL); + } + } + + @Test + public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallCornerWalls() { + assertEquals((int)wallTypeNumberMap.get(WallType.WALL_CORNER), + boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER).size()); + } + + @Test + public void getPositionsOfWallOnBoardHasTypeWallCorner() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER); + } + } + + @Test + public void getPositionsOfWallOnBoardHasCorrect() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); + Predicate> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER; + boardElemList.removeIf(pred); + assertEquals(0, boardElemList.size()); + } } From 14dfbea630efa5d9376b509a4d198b078505ba4e Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Mon, 16 Mar 2020 16:46:22 +0100 Subject: [PATCH 07/11] Endret metodenavn for mer lesbarhet --- .../fiasko/roborally/objects/Board.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 5ab22dc..b28eac4 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -345,7 +345,7 @@ public class Board { * @param walls The walls you want all positions for * @return A list of BoardElementContainers */ - public List> getPositionsOfTileOnBoard(WallType ... walls) { + public List> getPositionsOfWallOnBoard(WallType ... walls) { List> combinedList = new ArrayList<>(); for (WallType wall : walls) { combinedList.addAll(makeTileList(wall, this.walls)); @@ -367,18 +367,20 @@ public class Board { for (int y = grid.getHeight() - 1; y >= 0; y--) { for (int x = 0; x < grid.getWidth(); x++) { T gridElement = grid.getElement(x, y); - if (gridElement.getClass().isAssignableFrom(Tile.class)) { - Tile tile = (Tile) gridElement; - if (tile.getTileType() == type) { - objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); + if (gridElement != null) { + if (gridElement.getClass().isAssignableFrom(Tile.class)) { + Tile tile = (Tile) gridElement; + if (tile.getTileType() == type) { + objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); + } + } else if (gridElement.getClass().isAssignableFrom(Wall.class)) { + Wall wall = (Wall) gridElement; + if (wall.getWallType() == type) { + objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); + } + } else { + throw new IllegalArgumentException("Grid has unknown type."); } - } else if (gridElement.getClass().isAssignableFrom(Wall.class)) { - Wall wall = (Wall) gridElement; - if (wall.getWallType() == type) { - objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); - } - } else { - throw new IllegalArgumentException("Grid has unknown type."); } } } From 816f502f129562fce5001a76819dc8109be021c5 Mon Sep 17 00:00:00 2001 From: torlunjen Date: Mon, 16 Mar 2020 17:31:54 +0100 Subject: [PATCH 08/11] Adds partial functionality that moves robots standing on conveyor belts. --- .../fiasko/roborally/objects/Board.java | 12 ++- .../roborally/objects/RoboRallyGame.java | 87 ++++++++++++++++++- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 5ab22dc..467a1c1 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -1,9 +1,6 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.*; -import inf112.fiasko.roborally.utility.TextureConverterUtil; - -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -296,7 +293,7 @@ public class Board { * @param direction The direction to move the element * @return The new position of the element */ - private Position getNewPosition(Position oldPosition, Direction direction) { + Position getNewPosition(Position oldPosition, Direction direction) { switch (direction) { case NORTH: return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() - 1); @@ -327,6 +324,13 @@ public class Board { return elements; } + public Tile getTileOnPosition(Position position) { + if (!isValidPosition(position)) { + throw new IllegalArgumentException("Position is not on the board!"); + } + return tiles.getElement(position.getXCoordinate(), position.getYCoordinate()); + } + /** * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types * @param tiles The tiles you want all positions for diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 74ae131..ab36e2c 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -1,9 +1,6 @@ package inf112.fiasko.roborally.objects; -import inf112.fiasko.roborally.element_properties.Action; -import inf112.fiasko.roborally.element_properties.Position; -import inf112.fiasko.roborally.element_properties.RobotID; -import inf112.fiasko.roborally.element_properties.TileType; +import inf112.fiasko.roborally.element_properties.*; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import java.io.IOException; @@ -17,6 +14,7 @@ import java.util.concurrent.TimeUnit; public class RoboRallyGame implements IDrawableGame { private Board gameBoard; List> cogwheels; + List> conveyorBelts; public RoboRallyGame(boolean debug) { if (debug) { @@ -90,6 +88,13 @@ public class RoboRallyGame implements IDrawableGame { gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots); cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT, TileType.COGWHEEL_LEFT); + conveyorBelts = gameBoard.getPositionsOfTileOnBoard(TileType.TRANSPORT_BAND_FAST, + TileType.TRANSPORT_BAND_SLOW, TileType.TRANSPORT_BAND_FAST_SIDE_ENTRANCE_RIGHT, + TileType.TRANSPORT_BAND_FAST_RIGHT, TileType.TRANSPORT_BAND_SLOW_RIGHT, + TileType.TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_RIGHT, TileType.TRANSPORT_BAND_FAST_SIDE_ENTRANCE_LEFT, + TileType.TRANSPORT_BAND_FAST_LEFT, TileType.TRANSPORT_BAND_SLOW_LEFT, + TileType.TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_LEFT); + new Thread(() -> { try { runGameLoop(); @@ -204,4 +209,78 @@ public class RoboRallyGame implements IDrawableGame { } } } + + /** + * Moves robots standing on conveyor belts in the direction of the conveyor belt. + * Rotates robots being moved to a turn on the conveyor belt. + * @throws InterruptedException If disturbed during sleep. + */ + private void moveConveyorBelts() throws InterruptedException { + for (BoardElementContainer conveyorBelt : conveyorBelts) { + if (!gameBoard.hasRobotOnPosition(conveyorBelt.getPosition())) { + continue; + } + Position newPosition = gameBoard.getNewPosition(conveyorBelt.getPosition(), + conveyorBelt.getObject().getDirection()); + Tile nextTile = gameBoard.getTileOnPosition(newPosition); + Direction currentDirection = conveyorBelt.getObject().getDirection(); + Direction nextDirection = nextTile.getDirection(); + RobotID robot = gameBoard.getRobotOnPosition(conveyorBelt.getPosition()); + if (conveyorBelts.contains(nextTile) && currentDirection != nextDirection) { + if (currentDirection.equals(Direction.NORTH)) { + if (nextDirection.equals(Direction.WEST)) { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotLeft(robot); + } else { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotRight(robot); + } + } else if (currentDirection.equals(Direction.WEST)) { + if (nextDirection.equals(Direction.SOUTH)) { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotLeft(robot); + } else { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotLeft(robot); + } + } else if (currentDirection.equals(Direction.SOUTH)) { + if (nextDirection.equals(Direction.EAST)) { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotLeft(robot); + } else { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotRight(robot); + } + } else if (currentDirection.equals(Direction.EAST)) { + if (nextDirection.equals(Direction.NORTH)) { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotLeft(robot); + } else { + sleep(); + gameBoard.moveRobot(robot, currentDirection); + sleep(); + gameBoard.rotateRobotRight(robot); + } + } + } else { + sleep(); + gameBoard.moveRobot(gameBoard.getRobotOnPosition(conveyorBelt.getPosition()), + conveyorBelt.getObject().getDirection()); + } + } + } } \ No newline at end of file From 62d887fa76c72c6c44943cfc42e6f4ecbb10b882 Mon Sep 17 00:00:00 2001 From: torlunjen Date: Mon, 16 Mar 2020 17:35:53 +0100 Subject: [PATCH 09/11] Optimized imports --- src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 4fb731d..83afb3a 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -2,7 +2,6 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.*; import inf112.fiasko.roborally.utility.BoardLoaderUtil; -import javafx.geometry.Pos; import java.io.IOException; import java.util.ArrayList; From df180bf3721b923481e0affea20c74c353d09cda Mon Sep 17 00:00:00 2001 From: torlunjen Date: Mon, 16 Mar 2020 17:51:06 +0100 Subject: [PATCH 10/11] Adds helper method for conveyor belt method --- .../fiasko/roborally/objects/RoboRallyGame.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 83afb3a..4c8ea31 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -1,5 +1,6 @@ package inf112.fiasko.roborally.objects; + import inf112.fiasko.roborally.element_properties.*; import inf112.fiasko.roborally.utility.BoardLoaderUtil; @@ -210,6 +211,17 @@ public class RoboRallyGame implements IDrawableGame { } } + private Boolean listContainsTile(Tile tile) { + boolean containsTile = false; + for (BoardElementContainer conveyorBelt : conveyorBelts) { + if (conveyorBelt.getObject() == tile) { + containsTile = true; + break; + } + } + return containsTile; + } + /** * Moves robots standing on conveyor belts in the direction of the conveyor belt. * Rotates robots being moved to a turn on the conveyor belt. @@ -226,7 +238,7 @@ public class RoboRallyGame implements IDrawableGame { Direction currentDirection = conveyorBelt.getObject().getDirection(); Direction nextDirection = nextTile.getDirection(); RobotID robot = gameBoard.getRobotOnPosition(conveyorBelt.getPosition()); - if (conveyorBelts.contains(nextTile) && currentDirection != nextDirection) { + if (listContainsTile(nextTile) && currentDirection != nextDirection) { if (currentDirection.equals(Direction.NORTH)) { if (nextDirection.equals(Direction.WEST)) { sleep(); From 204b9c55855a3eb5b27646c0f6f564f5b3d15d92 Mon Sep 17 00:00:00 2001 From: torlunjen Date: Mon, 16 Mar 2020 17:55:38 +0100 Subject: [PATCH 11/11] Makes tile lists in RoboRallyGame private --- .../java/inf112/fiasko/roborally/objects/RoboRallyGame.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 4c8ea31..a322d89 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -14,8 +14,8 @@ import java.util.concurrent.TimeUnit; */ public class RoboRallyGame implements IDrawableGame { private Board gameBoard; - List> cogwheels; - List> conveyorBelts; + private List> cogwheels; + private List> conveyorBelts; public RoboRallyGame(boolean debug) { if (debug) {