Esempio n. 1
0
 @Test
 public void testToCreateARobotAndPlaceIt() {
   DIRECTIONS pos = DIRECTIONS.valueOf("NORTH");
   xy.setXY(0, 0);
   robot.place(pos, xy);
   assertEquals("0,0 NORTH", robot.report());
 }
Esempio n. 2
0
 @Test
 public void testTomoveRobotFacingEastAt00() {
   DIRECTIONS pos = DIRECTIONS.valueOf("EAST");
   xy.setXY(0, 0);
   robot.place(pos, xy);
   robot.move();
   assertEquals("1,0 EAST", robot.report());
 }
Esempio n. 3
0
 @Test
 public void testTomoveRobotFacingSouthAt00() {
   DIRECTIONS pos = DIRECTIONS.valueOf("SOUTH");
   xy.setXY(0, 0);
   robot.place(pos, xy);
   robot.move();
   assertEquals("0,-1 SOUTH", robot.report());
 }
Esempio n. 4
0
 @Test
 public void testToTurnLeftRobotFacingNorth() {
   DIRECTIONS pos = DIRECTIONS.valueOf("NORTH");
   xy.setXY(0, 0);
   robot.place(pos, xy);
   robot.turnLeft();
   assertEquals("0,0 WEST", robot.report());
 }
Esempio n. 5
0
 @Test
 public void testToTurnRobotFacingWestAndThenTurnRight() {
   DIRECTIONS pos = DIRECTIONS.valueOf("WEST");
   xy.setXY(0, 0);
   robot.place(pos, xy);
   robot.turnRight();
   assertEquals("0,0 NORTH", robot.report());
 }
Esempio n. 6
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);
  }
Esempio n. 7
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()));
  }
Esempio n. 8
0
  @Test
  public void testUseRepairKit() {
    Board board = facade.createBoard(16, 12);
    Robot robot = facade.createRobot(0, 500);
    robot.hit();
    robot.recharge(new Energy(1, unitOfPower.foe));
    facade.putRobot(board, 3, 6, robot);
    RepairKit repairKit = facade.createRepairKit(1000, 50);
    facade.putRepairKit(board, 3, 6, repairKit);
    facade.pickUpRepairKit(robot, repairKit);

    assertEquals(16000, facade.getEnergy(robot), epsilon);

    facade.useRepairKit(robot, repairKit);

    robot.recharge(new Energy(1, unitOfPower.foe));

    assertEquals(16500, facade.getEnergy(robot), epsilon);
  }
Esempio n. 9
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);
  }
Esempio n. 10
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);
  }
Esempio n. 11
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)));
  }
  @Test
  public void test() {
    Simulator sim = new Simulator(10, 20);
    SimObject s1 = new SimObject(1, 2, 2);
    sim.add(s1);
    SimObject s2 = new SimObject(10, 10, 2);
    sim.add(s2);

    Robot bot = new Robot(5, 10, 0);
    sim.add(bot);

    assertTrue(bot.withinSonar(s2));
    assertFalse(bot.withinSonar(s1));

    assertEquals(5.0, sim.findClosestEdge(), 0.01);
    bot.turn(Direction.FWD);
    for (int i = 0; i < 8; i++) bot.update();
    assertEquals(10.0, sim.findClosestEdge(), 0.01);
    for (int i = 0; i < 8; i++) bot.update();
    assertEquals(5.0, sim.findClosestEdge(), 0.01);
    for (int i = 0; i < 8; i++) bot.update();
    assertEquals(10.0, sim.findClosestEdge(), 0.01);
  }
Esempio n. 13
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);
  }
Esempio n. 14
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);
  }
Esempio n. 15
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);
  }
Esempio n. 16
0
  private ScribblePlayerHand doSmallGame(final RobotType robotType)
      throws BoardCreationException, InterruptedException {
    long currentTime = System.currentTimeMillis();
    assertNotNull("No room manager", scribbleBoardManager);
    final Visitor player = new DefaultVisitor(Language.RU);
    final ScribbleSettings settings =
        new ScribbleSettings("This is robots game", player.getLanguage(), 3, true, true);
    scribbleBoardManager.addBoardListener(
        new BoardListener() {
          @Override
          public void gameStarted(
              GameBoard<? extends GameSettings, ? extends GamePlayerHand, ? extends GameMove> b) {
            passGuestTurn(b);
          }

          @Override
          public void gameMoveDone(
              GameBoard<? extends GameSettings, ? extends GamePlayerHand, ? extends GameMove> b,
              GameMove move,
              GameMoveScore moveScore) {
            passGuestTurn(b);
          }

          @Override
          public void gameFinished(
              GameBoard<? extends GameSettings, ? extends GamePlayerHand, ? extends GameMove> b,
              GameResolution resolution,
              Collection<Personality> winners) {
            notifyGameFinished();
          }

          private void passGuestTurn(
              GameBoard<? extends GameSettings, ? extends GamePlayerHand, ? extends GameMove> b) {
            if (b.getPlayerTurn() == player) {
              ScribbleBoard sb = (ScribbleBoard) b;
              try {
                if (Math.random() < 0.5) {
                  final ScribblePlayerHand playerHand = sb.getPlayerHand(player);
                  final Tile[] tiles1 = playerHand.getTiles();
                  final int length = Math.min(tiles1.length, sb.getBankRemained());
                  if (length == 0) {
                    sb.passTurn(player);
                  } else {
                    int[] tiles = new int[length];
                    for (int i = 0; i < length; i++) {
                      tiles[i] = tiles1[i].getNumber();
                    }
                    sb.exchangeTiles(player, tiles);
                  }
                } else {
                  sb.passTurn(player);
                }
              } catch (GameMoveException e) {
                log.error("Something wrong", e);
                notifyGameFinished();
              }
            }
          }
        });

    final ScribbleBoard board = scribbleBoardManager.createBoard(settings, player, robotType);
    assertTrue("Game is not in progress state", board.isActive());

    gameFinishedLock.lock();
    while (board.isActive()) {
      gameFinishedCondition.await();
    }
    gameFinishedLock.unlock();

    log.info("Game was finished at {}ms ", +(System.currentTimeMillis() - currentTime));

    assertTrue("Board is not saved", board.getBoardId() > 0);
    assertFalse("Board is not finished", board.isActive());
    assertTrue("Board has no one move", board.getGameMoves().size() > 0);
    final Personality playerTurn = board.getPlayerTurn();
    if (board.getResolution() == GameResolution.RESIGNED
        || board.getResolution() == GameResolution.INTERRUPTED) {
      assertNotNull("Board has a player who has a turn: " + playerTurn, playerTurn);
    } else {
      assertNull("Board has a player who has a turn: " + playerTurn, playerTurn);
    }

    final Robot robot = (Robot) board.getPlayers().get(1);
    final ScribblePlayerHand playerHand = board.getPlayerHand(robot);
    assertTrue(playerHand.getPoints() > 0);
    assertTrue(playerHand.getOldRating() == robot.getRating());
    assertTrue(playerHand.getNewRating() > robot.getRating());
    return playerHand;
  }