@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()); }
/** * Method removes squares where this king can't move. * * @param squares squares what king threats * @param danger squares where king can't move * @param mySquares * @param remove squares that needs to remove */ private void removeSquares( SquareList squares, SquareList danger, SquareList mySquares, SquareList remove) { for (Square square : squares.getList()) { if (danger.contains(square) || mySquares.contains(square)) { remove.add(square); } } for (Square square : remove.getList()) { squares.remove(square); } }
@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()); }
@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); }