/** Test valid <code>Plies</code> in a normal setting (no move-preventing cells). */ public void testPliesNormal() { // For white Piece board.addPiece(whiteKnight, new int[] {4, 5}); Set<Ply> correctPlies = pliesAtFourFive; checkPlies(correctPlies, whiteKnight); // For black Piece board.removePiece(whiteKnight); board.addPiece(blackKnight, new int[] {4, 5}); checkPlies(correctPlies, blackKnight); }
/** * Test valid <code>Plies</code> among unusable cells (sides). The <code>Plies</code> should be * restricted by the limits of the <code>Board</code>. */ public void testPliesUnusableSides() { // For black Piece board.addPiece(blackKnight, new int[] {0, 7}); Set<Ply> correctPlies = new HashSet<Ply>(); correctPlies.add(new Move(new int[] {0, 7}, new int[] {1, 5})); correctPlies.add(new Move(new int[] {0, 7}, new int[] {2, 6})); checkPlies(correctPlies, blackKnight); }
/** * Test valid <code>Plies</code> among <code>Piece</code>s of the same color. The <code>Plies * </code> should exclude those that end in a cell occupied by another <code>Piece</code> of the * same color. */ public void testPliesSameColor() { // For white Piece Piece whitePawn = new Pawn(true, board); board.addPiece(whitePawn, new int[] {5, 7}); board.addPiece(whiteKnight, new int[] {4, 5}); Set<Ply> correctPlies = new HashSet<Ply>(); for (Ply ply : pliesAtFourFive) if (!ply.equals(new Move(new int[] {4, 5}, new int[] {5, 7}))) correctPlies.add(ply); checkPlies(correctPlies, whiteKnight); // For black Piece board.removePiece(whitePawn); board.removePiece(whiteKnight); Piece blackPawn = new Pawn(false, board); board.addPiece(blackPawn, new int[] {5, 7}); board.addPiece(blackKnight, new int[] {4, 5}); checkPlies(correctPlies, blackKnight); }
/** * Test valid <code>Plies</code> among <code>Piece</code>s of different color. The <code>Plies * </code> should not exclude anything. */ public void testPliesDiffColor() { // For white Piece Piece blackPawn = new Pawn(false, board); Piece blackBishop = new Bishop(false, board); board.addPiece(blackPawn, new int[] {5, 7}); board.addPiece(blackBishop, new int[] {3, 3}); board.addPiece(whiteKnight, new int[] {4, 5}); Set<Ply> correctPlies = pliesAtFourFive; checkPlies(correctPlies, whiteKnight); // For black Piece board.removePiece(blackPawn); board.removePiece(blackBishop); board.removePiece(whiteKnight); Piece whitePawn = new Pawn(true, board); Piece whiteBishop = new Bishop(true, board); board.addPiece(whitePawn, new int[] {5, 7}); board.addPiece(whiteBishop, new int[] {3, 3}); board.addPiece(blackKnight, new int[] {4, 5}); checkPlies(correctPlies, blackKnight); }
/** * Test valid <code>Plies</code> in a complex setting, i.e. a combination of the previous tests. */ public void testPliesComplex() { List<int[]> unusable = new ArrayList<int[]>(2); unusable.add(new int[] {5, 7}); unusable.add(new int[] {3, 3}); Board holedBoard = new RectangularBoard( RectangularBoard.defaultLength, RectangularBoard.defaultHeight, unusable); Piece whiteKnight = new Knight(true, holedBoard); Piece blackBishop = new Bishop(false, holedBoard); Piece newKnight = new Knight(true, holedBoard); holedBoard.addPiece(whiteKnight, new int[] {5, 3}); holedBoard.addPiece(blackBishop, new int[] {2, 6}); holedBoard.addPiece(newKnight, new int[] {4, 5}); Set<Ply> correctPlies = new HashSet<Ply>(); correctPlies.add(new Move(new int[] {4, 5}, new int[] {3, 7})); correctPlies.add(new Move(new int[] {4, 5}, new int[] {6, 6})); correctPlies.add(new Move(new int[] {4, 5}, new int[] {6, 4})); correctPlies.add(new Move(new int[] {4, 5}, new int[] {2, 4})); correctPlies.add(new Move(new int[] {4, 5}, new int[] {2, 6})); checkPlies(correctPlies, newKnight); }
/** * Test valid <code>Plies</code> among unusable cells (user-defined). The <code>Plies</code> * should exclude those that end in unusable cells. */ public void testPliesUnusableCenter() { // For white Piece with holes (unusable) List<int[]> unusable = new ArrayList<int[]>(2); unusable.add(new int[] {5, 7}); unusable.add(new int[] {3, 3}); Board holedBoard = new RectangularBoard( RectangularBoard.defaultLength, RectangularBoard.defaultHeight, unusable); Piece newKnight = new Knight(true, holedBoard); holedBoard.addPiece(newKnight, new int[] {4, 5}); Set<Ply> correctPlies = new HashSet<Ply>(); for (Ply ply : pliesAtFourFive) if (!ply.equals(new Move(new int[] {4, 5}, new int[] {5, 7})) && !ply.equals(new Move(new int[] {4, 5}, new int[] {3, 3}))) correctPlies.add(ply); checkPlies(correctPlies, newKnight); }