コード例 #1
0
 @Test
 public void testThatDefaultConstructorForGameBoardInitializesCorrectly() {
   GameBoard gb = new GameBoard();
   Assert.assertEquals(10, gb.getWidth());
   Assert.assertEquals(10, gb.getHeight());
   Assert.assertEquals(5, gb.getNumberOfShips());
 }
コード例 #2
0
 @Test
 public void testThatMakesSureMoreShipsThanAllowedCanNotBePlaced() {
   GameBoard gb = new GameBoard(10, 10, 2);
   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));
   Assert.assertFalse(gb.checkAndPlaceShips(ships, "bottom"));
 }
コード例 #3
0
 @Test
 public void testThatGameBoardIsNotEmptyAfterAddingShips() {
   GameBoard gb = new GameBoard(10, 10, 2);
   ArrayList<Ship> ships = new ArrayList<Ship>();
   ships.add(new Ship(3, 3, 3, true));
   ships.add(new Ship(4, 6, 2, true));
   gb.checkAndPlaceShips(ships, "bottom");
   Assert.assertFalse(gb.isEmpty());
 }
コード例 #4
0
 @Test
 public void testThatMakesSureShipsCanBeAddedUsingMultipleCallsToCheckAndPlaceShips() {
   GameBoard gb = new GameBoard(10, 10, 1);
   ArrayList<Ship> ships = new ArrayList<Ship>();
   ships.add(new Ship(3, 3, 3, true));
   Assert.assertTrue(gb.checkAndPlaceShips(ships, "bottom"));
   ships.removeAll(ships);
   ships.add(new Ship(4, 6, 2, true));
   Assert.assertTrue(gb.checkAndPlaceShips(ships, "bottom"));
 }
コード例 #5
0
ファイル: TestGameBoard.java プロジェクト: tovan/java-othello
  @Test
  public void testOnlyValidMovesAreMade() {
    GameBoard gameBoard = new GameBoard();
    GamePiece[][] board = gameBoard.getBoard();

    board[2][2] = new GamePiece(2, 2, Color.BLACK);
    gameBoard.makeMove(Color.CYAN, 2, 2);
    // make sure that piece already taken was not overridden by new piece
    // and new color
    assertEquals(board[2][2].getColor(), Color.BLACK);

    gameBoard.makeMove(Color.CYAN, 3, 3);
    // make sure that an invalid move is not taken
    assertEquals(board[3][3].getColor(), null);
  }
コード例 #6
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);
  }
コード例 #7
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);
  }
コード例 #8
0
ファイル: TestGameBoard.java プロジェクト: tovan/java-othello
  @Test
  public void testFlipPieces() {
    GameBoard board = new GameBoard();
    board.setUpBoard();
    System.out.println(board.toString());
    board.makeComputerMove(Color.BLACK);

    assertTrue(board.getBoard()[4][5].getColor() == Color.BLACK);
    System.out.println(board.toString());
  }
コード例 #9
0
 @Test
 public void testIsGameBoardEmpty() {
   GameBoard gb = new GameBoard(10, 10, 5);
   Assert.assertTrue(gb.isEmpty());
 }