示例#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);
  }
示例#2
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);
  }