Exemplo n.º 1
0
  @Test
  public void testMoveNextToSurroundedByRobots() {
    Board board = facade.createBoard(16, 26);
    Robot robot1 = facade.createRobot(0, 6000);
    Robot robot2 = facade.createRobot(0, 3000);

    facade.putRobot(board, 7, 15, robot1);
    facade.putRobot(board, 12, 23, robot2);

    Set<Position> robotsRoundRobot2Positions = new HashSet<Position>();
    for (long x = 10; x < 15; x++) {
      robotsRoundRobot2Positions.add(Position.newPosition(x, 21, board));
      robotsRoundRobot2Positions.add(Position.newPosition(x, 26, board));
    }
    for (long y = 22; y < 26; y++) {
      robotsRoundRobot2Positions.add(Position.newPosition(10, y, board));
      robotsRoundRobot2Positions.add(Position.newPosition(14, y, board));
    }
    for (Position robotPosition : robotsRoundRobot2Positions)
      board.putElement(robotPosition, new Robot(new Energy(1000, unitOfPower.Ws), Orientation.UP));

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().equals(Position.newPosition(12, 20, board)));
    assertTrue(robot2.getPosition().equals(Position.newPosition(12, 22, board)));
    assertEquals(800, robot1.getAmountOfEnergy(), epsilon);
    assertEquals(2500, robot2.getAmountOfEnergy(), epsilon);
  }
Exemplo n.º 2
0
  @Test
  public void testMoveNextToRobotNotOnBoard() {
    Board board = facade.createBoard(16, 26);
    Board board2 = facade.createBoard(35, 46);
    Robot robot1 = facade.createRobot(0, 3000);
    Robot robot2 = facade.createRobot(1, 3000);

    facade.putRobot(board, 7, 15, robot1);

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().equals(Position.newPosition(7, 15, board)));
    assertEquals(3000, robot1.getAmountOfEnergy(), epsilon);

    facade.moveNextTo(robot2, robot1);

    assertNull(robot2.getPosition());
    assertEquals(3000, robot2.getAmountOfEnergy(), epsilon);

    facade.putRobot(board2, 12, 23, robot2);

    robot1.moveNextTo(robot2);

    assertTrue(robot1.getPosition().equals(Position.newPosition(7, 15, board)));
    assertEquals(3000, robot1.getAmountOfEnergy(), epsilon);
  }
Exemplo n.º 3
0
  @Test
  public void testMoveNextToBestEffortOverlap() {
    Board board = facade.createBoard(16, 26);
    Robot robot1 = facade.createRobot(0, 3000);
    Robot robot2 = facade.createRobot(1, 3000);

    facade.putRobot(board, 7, 15, robot1);
    facade.putRobot(board, 9, 20, robot2);

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().getNeighbours().contains(robot2.getPosition()));
  }
Exemplo n.º 4
0
  @Test
  public void testMoveNextToBestEffort() {
    Board board = facade.createBoard(16, 26);
    Robot robot1 = facade.createRobot(0, 3000);
    Robot robot2 = facade.createRobot(1, 3000);

    facade.putRobot(board, 7, 15, robot1);
    facade.putRobot(board, 12, 23, robot2);

    facade.moveNextTo(robot1, robot2);

    assertEquals(3, robot1.getPosition().manhattanDistance(robot2.getPosition()), epsilon);
    assertEquals(400, robot1.getAmountOfEnergy(), epsilon);
    assertEquals(400, robot2.getAmountOfEnergy(), epsilon);
  }
Exemplo n.º 5
0
  @Test
  public void testMoveNextToNoObstacles() {
    Board board = facade.createBoard(16, 26);
    Robot robot1 = facade.createRobot(0, 3000);
    Robot robot2 = facade.createRobot(1, 3000);

    facade.putRobot(board, 7, 15, robot1);
    facade.putRobot(board, 9, 12, robot2);

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().getNeighbours().contains(robot2.getPosition()));
    assertTrue(
        robot1.getPosition().equals(Position.newPosition(8, 12, board))
            || robot1.getPosition().equals(Position.newPosition(9, 13, board)));
  }
Exemplo n.º 6
0
  @Test
  public void testShoot() {
    Board board = facade.createBoard(35, 47);
    Energy enoughEnergy = new Energy(5000, unitOfPower.Ws);
    Energy enoughEnergy2 = new Energy(5000, unitOfPower.Ws);
    Energy notEnoughEnergy = new Energy(500, unitOfPower.Ws);
    Robot robotEnoughEnergy = new Robot(enoughEnergy, Orientation.RIGHT);
    Robot robotNotEnoughEnergy = new Robot(notEnoughEnergy, Orientation.LEFT);
    Robot robotShootAtBoardEdge = new Robot(enoughEnergy2, Orientation.LEFT);
    Position positionRobotEnoughEnergy = Position.newPosition(0, 0, board);
    Position positionRobotNotEnoughEnergy = Position.newPosition(20, 0, board);
    Position positionRobotShootAtBoardEdge = Position.newPosition(3, 2, board);

    robotEnoughEnergy.setPosition(positionRobotEnoughEnergy);
    robotNotEnoughEnergy.setPosition(positionRobotNotEnoughEnergy);
    robotShootAtBoardEdge.setPosition(positionRobotShootAtBoardEdge);

    assertTrue(positionRobotEnoughEnergy.equals(robotEnoughEnergy.getPosition()));

    try {
      facade.shoot(robotNotEnoughEnergy);
    } catch (AssertionError ae) {
      System.err.println("testShoot(facadetest): This assertionerror is to be expected.");
    }

    assertTrue(positionRobotEnoughEnergy.equals(robotEnoughEnergy.getPosition()));
    assertTrue(positionRobotNotEnoughEnergy.equals(robotNotEnoughEnergy.getPosition()));
    assertEquals(
        notEnoughEnergy.getAmountOfEnergy(), robotNotEnoughEnergy.getAmountOfEnergy(), epsilon);
    assertEquals(enoughEnergy.getAmountOfEnergy(), robotEnoughEnergy.getAmountOfEnergy(), epsilon);

    facade.shoot(robotEnoughEnergy);

    assertTrue(positionRobotEnoughEnergy.equals(robotEnoughEnergy.getPosition()));
    assertEquals(
        notEnoughEnergy.getAmountOfEnergy(), robotNotEnoughEnergy.getAmountOfEnergy(), epsilon);
    assertEquals(16000, robotNotEnoughEnergy.getMaxEnergy().getAmountOfEnergy(), epsilon);
    assertEquals(4000, robotEnoughEnergy.getAmountOfEnergy(), epsilon);

    facade.shoot(robotShootAtBoardEdge);

    assertEquals(4000, robotShootAtBoardEdge.getAmountOfEnergy(), epsilon);
  }
Exemplo n.º 7
0
  @Test
  public void testMoveNextToDifferentCarriedWeight() {
    Board board = facade.createBoard(16, 26);
    Robot robot1 = facade.createRobot(0, 6000);
    Robot robot2 = facade.createRobot(2, 1000);
    Battery battery =
        new Battery(
            Position.newPosition(7, 15, board),
            new Energy(1000, unitOfPower.Ws),
            new Weight(10, unitOfMass.kg));

    facade.putRobot(board, 7, 15, robot1);
    facade.putRobot(board, 10, 13, robot2);
    facade.pickUpBattery(robot1, battery);

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().equals(Position.newPosition(9, 15, board)));
    assertTrue(robot2.getPosition().equals(Position.newPosition(10, 15, board)));
    assertEquals(3900, robot1.getAmountOfEnergy(), epsilon);
    assertEquals(0, robot2.getAmountOfEnergy(), epsilon);
  }
Exemplo n.º 8
0
  @Test
  public void testMoveNextToObstacles() {
    Board board = facade.createBoard(35, 47);
    Robot robot1 = facade.createRobot(0, 6600);
    Robot robot2 = facade.createRobot(0, 1800);

    facade.putRobot(board, 5, 5, robot1);
    facade.putRobot(board, 15, 5, robot2);

    Set<Position> maze = new HashSet<Position>();
    for (long x = 3; x < 18; x++) {
      maze.add(Position.newPosition(x, 3, board));
      maze.add(Position.newPosition(x, 7, board));
    }
    for (long y = 4; y < 7; y++) {
      maze.add(Position.newPosition(3, y, board));
      maze.add(Position.newPosition(17, y, board));
    }
    maze.add(Position.newPosition(7, 4, board));
    maze.add(Position.newPosition(7, 5, board));
    maze.add(Position.newPosition(10, 5, board));
    maze.add(Position.newPosition(10, 6, board));
    maze.add(Position.newPosition(13, 4, board));
    maze.add(Position.newPosition(13, 5, board));

    for (Position position : maze) {
      board.putElement(position, new Wall());
    }

    facade.moveNextTo(robot1, robot2);

    assertTrue(robot1.getPosition().equals(Position.newPosition(12, 6, board)));
    assertTrue(robot2.getPosition().equals(Position.newPosition(13, 6, board)));
    assertEquals(0, robot1.getAmountOfEnergy(), epsilon);
    assertEquals(0, robot2.getAmountOfEnergy(), epsilon);
  }