Ejemplo 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);
  }
Ejemplo n.º 2
0
  @Test
  public void testMerge() {
    Board board1 = facade.createBoard(4, 13);
    Board board2 = facade.createBoard(2, 45);

    facade.merge(board1, board2);

    assertNotNull(board1);
    assertTrue(board2.isTerminated());

    facade.merge(board1, null);

    assertNotNull(board1);
  }
Ejemplo n.º 3
0
  @Test
  public void testGetWalls() {
    Board board = facade.createBoard(20, 25);
    facade.putRobot(board, 0, 0, facade.createRobot(0, 500));
    facade.putRobot(board, 1, 0, facade.createRobot(0, 500));
    facade.putBattery(board, 2, 0, facade.createBattery(0, 50));
    facade.putBattery(board, 3, 0, facade.createBattery(100, 50));
    facade.putBattery(board, 4, 0, facade.createBattery(100, 50));
    facade.putWall(board, 5, 0, facade.createWall());
    facade.putWall(board, 6, 0, facade.createWall());
    facade.putWall(board, 7, 0, facade.createWall());
    facade.putWall(board, 8, 0, facade.createWall());
    facade.putWall(board, 9, 0, facade.createWall());

    assertEquals(10, board.getNumberOfOccupiedPositions());
    assertEquals(5, facade.getWalls(board).size());
  }
Ejemplo n.º 4
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);
  }