예제 #1
0
  @Test
  public void testThatAIPlacesShips() {
    GameBoard gb = new GameBoard();
    int[] blank = {5, 4, 3, 2, 1};
    AI ai = new AI(gb, blank);
    ai.placeShips();
    Boolean result = false;

    for (int r = 0; r < gb.getHeight(); r++) {
      for (int c = 0; c < gb.getWidth(); c++) {
        result = result || !(gb.getTopGrid().getGrid()[r][c] instanceof ShipCell);
      }
    }

    Assert.assertTrue(result);
  }
예제 #2
0
  @Test
  public void testThatAIShoots() {
    GameBoard gb = new GameBoard(10, 10, 3);
    ArrayList<Ship> ships = new ArrayList<Ship>();
    ships.add(new Ship(3, 3, 3, true));
    ships.add(new Ship(4, 6, 2, true));
    ships.add(new Ship(1, 1, 5, false));
    gb.checkAndPlaceShips(ships, "Bottom");
    int[] blank = {3, 2, 1};
    AI ai = new AI(gb, blank);
    ai.placeShips();
    Boolean result = false;
    ai.shoot();
    for (int r = 0; r < gb.getHeight(); r++) {
      for (int c = 0; c < gb.getWidth(); c++) {
        result =
            result
                || (gb.getBottomGrid().getGrid()[r][c] instanceof Hit)
                || (gb.getBottomGrid().getGrid()[r][c] instanceof Miss);
      }
    }

    Assert.assertTrue(result);
  }