mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-11-03 03:03:43 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/inf112-v20/Fiasko
Conflicts: src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
This commit is contained in:
		
							
								
								
									
										15
									
								
								docs/team/referater/referat_16_03_2020.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								docs/team/referater/referat_16_03_2020.md
									
									
									
									
									
										Normal file
									
								
							@@ -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. 
 | 
			
		||||
@@ -175,6 +175,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
 | 
			
		||||
@@ -349,7 +362,7 @@ public class Board {
 | 
			
		||||
     * @param walls The walls you want all positions for
 | 
			
		||||
     * @return A list of BoardElementContainers
 | 
			
		||||
     */
 | 
			
		||||
    public List<BoardElementContainer<Wall>> getPositionsOfTileOnBoard(WallType ... walls) {
 | 
			
		||||
    public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType ... walls) {
 | 
			
		||||
        List<BoardElementContainer<Wall>> combinedList = new ArrayList<>();
 | 
			
		||||
        for (WallType wall : walls) {
 | 
			
		||||
            combinedList.addAll(makeTileList(wall, this.walls));
 | 
			
		||||
@@ -371,18 +384,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.");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ import inf112.fiasko.roborally.element_properties.Position;
 | 
			
		||||
 */
 | 
			
		||||
public class BoardElementContainer <K>{
 | 
			
		||||
    K obj;
 | 
			
		||||
    Position pos;
 | 
			
		||||
    private Position pos;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Initializes the BoardElementContainer
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ 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;
 | 
			
		||||
@@ -283,4 +284,19 @@ public class RoboRallyGame implements IDrawableGame {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks all flags for robots. Tries to update the flag of the robot.
 | 
			
		||||
     */
 | 
			
		||||
    private void checkAllFlags() {
 | 
			
		||||
        List<BoardElementContainer<Tile>> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
 | 
			
		||||
                TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
 | 
			
		||||
        for (BoardElementContainer<Tile> flag:listOfFlags) {
 | 
			
		||||
            Position flagPosition = flag.getPosition();
 | 
			
		||||
            if (gameBoard.hasRobotOnPosition(flagPosition)) {
 | 
			
		||||
                RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
 | 
			
		||||
                gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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<Robot> robotList;
 | 
			
		||||
    private Board board;
 | 
			
		||||
    private Board boardWithDifferentAmountOfAllTypes;
 | 
			
		||||
    private Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
 | 
			
		||||
    private Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    @BeforeClass
 | 
			
		||||
    public static void globalSetUp() {
 | 
			
		||||
@@ -61,7 +67,51 @@ 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);
 | 
			
		||||
 | 
			
		||||
        Grid<Tile> tileGridAllTypes = new Grid<>(6,6);
 | 
			
		||||
        Grid<Wall> wallGridAllTypes = new Grid<>(6,6);
 | 
			
		||||
        List<Robot> 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
 | 
			
		||||
    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
 | 
			
		||||
@@ -161,4 +211,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<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
 | 
			
		||||
 | 
			
		||||
        for (BoardElementContainer<Tile> 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<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE);
 | 
			
		||||
 | 
			
		||||
        for (BoardElementContainer<Tile> 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<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL);
 | 
			
		||||
 | 
			
		||||
        for (BoardElementContainer<Wall> 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<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
 | 
			
		||||
 | 
			
		||||
        for (BoardElementContainer<Wall> elem : boardElemList) {
 | 
			
		||||
            assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void getPositionsOfWallOnBoardHasCorrect() {
 | 
			
		||||
        List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
 | 
			
		||||
        Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER;
 | 
			
		||||
        boardElemList.removeIf(pred);
 | 
			
		||||
        assertEquals(0, boardElemList.size());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user