Пример #1
0
  @Test
  public void threatTest() {
    Square square = this.board.getSquare('e', 1);
    square.setPiece(wPawn);
    SquareList squares = square.getPiece().whatThreats(board, square);
    SquareList list = new SquareList();
    list.add(this.board.getSquare('d', 2));
    list.add(this.board.getSquare('f', 2));
    boolean ok = true;
    for (Square sqr : list.getList()) {
      if (!squares.contains(sqr)) {
        ok = false;
      }
    }
    assertEquals(true, squares.size() == list.size());

    square = this.board.getSquare('e', 8);
    square.setPiece(bPawn);
    squares = square.getPiece().whatThreats(board, square);
    list = new SquareList();
    list.add(this.board.getSquare('d', 7));
    list.add(this.board.getSquare('f', 7));
    for (Square sqr : list.getList()) {
      if (!squares.contains(sqr)) {
        ok = false;
      }
    }
    assertEquals(true, ok);
    assertEquals(true, squares.size() == list.size());
  }
Пример #2
0
 @Test
 public void basicMovesTest() {
   this.board.getSquare('e', 4).setPiece(wRook);
   this.board.getSquare('d', 5).setPiece(bRook);
   SquareList wSquares = wRook.whereToMove(board, board.getSquare('e', 4));
   boolean ok = true;
   ArrayList<String> squares = new ArrayList();
   squares.add("e5");
   squares.add("e3");
   squares.add("a4");
   squares.add("b4");
   squares.add("c4");
   squares.add("d4");
   squares.add("h4");
   squares.add("g4");
   squares.add("f4");
   squares.add("e7");
   squares.add("e6");
   for (Square square : wSquares.getList()) {
     String s = square.toString();
     if (!squares.contains(s)) {
       ok = false;
     }
   }
   if (squares.size() != wSquares.size()) {
     ok = false;
   }
   assertEquals(true, ok);
   assertEquals(0, bRook.whereToMove(board, board.getSquare('h', 8)).size());
 }
Пример #3
0
 @Test
 public void FirstPawnMovesTest() {
   SquareList wSquares = wPawn.whereToMove(board, board.getSquare('e', 2));
   SquareList bSquares = bPawn.whereToMove(board, board.getSquare('e', 7));
   boolean ok = true;
   if (wSquares.size() != 2 || bSquares.size() != 2) {
     ok = false;
   }
   String s1 = "e3";
   String s2 = "e4";
   for (Square square : wSquares.getList()) {
     if (!square.toString().equals(s1) && !square.toString().equals(s2)) {
       ok = false;
     }
   }
   s1 = "e6";
   s2 = "e5";
   for (Square square : bSquares.getList()) {
     if (!square.toString().equals(s1) && !square.toString().equals(s2)) {
       ok = false;
     }
   }
   assertEquals(true, ok);
 }