@Test public void testKing() { Board b = new Board(true); Piece water = new Piece(false, b, 2, 2, "bomb"); Piece fire = new Piece(true, b, 1, 1, "pawn"); Piece fire2 = new Piece(true, b, 2, 6, "shield"); b.place(water, 2, 2); b.place(fire, 1, 1); b.place(fire2, 2, 6); assertEquals(false, water.isKing()); assertEquals(false, fire2.isKing()); assertEquals(fire, b.pieceAt(1, 1)); fire2.move(3, 7); assertEquals(true, fire2.isKing()); assertEquals(true, fire2.isFire()); assertEquals(fire2, b.pieceAt(3, 7)); water.move(0, 0); assertEquals(true, water.isKing()); assertEquals(true, fire2.isKing()); assertEquals(null, b.pieceAt(1, 1)); assertEquals(null, b.pieceAt(0, 0)); b.select(3, 7); assertEquals(true, b.canSelect(4, 6)); // fire can now move down assertEquals(false, b.canSelect(4, 8)); // out of bounds }
@Test public void testBombandShield() { Board b = new Board(true); Piece fire = new Piece(true, b, 5, 5, "bomb"); Piece water = new Piece(false, b, 4, 6, "shield"); Piece water2 = new Piece(false, b, 2, 6, "pawn"); b.place(fire, 5, 5); b.place(water, 4, 6); b.place(water2, 2, 6); fire.move(3, 7); assertEquals(null, b.pieceAt(4, 7)); assertEquals(null, b.pieceAt(3, 6)); assertEquals(null, b.pieceAt(5, 6)); fire = new Piece(true, b, 4, 4, "bomb"); water = new Piece(false, b, 3, 5, "shield"); water2 = new Piece(false, b, 3, 7, "pawn"); Piece water3 = new Piece(false, b, 1, 7, "pawn"); Piece water4 = new Piece(false, b, 1, 5, "bomb"); b.place(fire, 4, 4); b.place(water, 3, 5); b.place(water2, 3, 7); b.place(water3, 1, 7); b.place(water4, 1, 5); fire.move(2, 6); assertEquals(null, b.pieceAt(3, 5)); assertEquals(null, b.pieceAt(3, 7)); assertEquals(null, b.pieceAt(1, 7)); assertEquals(null, b.pieceAt(1, 5)); }
/** Test of isWhite method, of class Piece. */ @Test public void testIsWhite() { System.out.println("isWhite"); assertEquals(false, Piece.isWhite(Piece.BBISHOP)); assertEquals(true, Piece.isWhite(Piece.WBISHOP)); assertEquals(true, Piece.isWhite(Piece.WKING)); assertEquals(false, Piece.isWhite(Piece.BKING)); }
@Test public void testCannotMoveToSameSquare() { Square currentSquare = new Square("a1"); Square emptySquare = new Square("a1"); board.placePiece(currentSquare, queen); assertFalse(queen.canMove(board, currentSquare, emptySquare)); }
@Test public void testCanMoveDiagonallyDownAndRight() { Square currentSquare = new Square("d5"); Square emptySquare = new Square("f3"); board.placePiece(currentSquare, queen); assertTrue(queen.canMove(board, currentSquare, emptySquare)); }
@Test public void testCannotAttackEmptySquare() { Square currentSquare = new Square("a1"); Square emptySquare = new Square("c1"); board.placePiece(currentSquare, queen); assertFalse(queen.canAttack(board, currentSquare, emptySquare)); }
@Test public void testCanMoveStraightRight() { Square currentSquare = new Square("d5"); Square emptySquare = new Square("h5"); board.placePiece(currentSquare, queen); assertTrue(queen.canMove(board, currentSquare, emptySquare)); }
@Test public void testCannotAttackSameSquare() { Square currentSquare = new Square("a1"); Square occupiedSquare = new Square("a1"); board.placePiece(currentSquare, queen); assertFalse(queen.canAttack(board, currentSquare, occupiedSquare)); }
@Test public void testCannotMoveToNonStraightOrDiagonalSquare() { Square currentSquare = new Square("a1"); Square emptySquare = new Square("b8"); board.placePiece(currentSquare, queen); assertFalse(queen.canMove(board, currentSquare, emptySquare)); }
@Test public void testCanAttackStraightDown() { Square currentSquare = new Square("d5"); Square occupiedSquare = new Square("d1"); board.placePiece(currentSquare, queen); board.placePiece(occupiedSquare, new Queen(Color.BLACK)); assertTrue(queen.canAttack(board, currentSquare, occupiedSquare)); }
@Test public void testCannotMoveWhenBlocked() { Square currentSquare = new Square("a1"); Square emptySquare = new Square("c1"); board.placePiece(currentSquare, queen); board.placePiece(new Square("b1"), new Queen(Color.WHITE)); assertFalse(queen.canMove(board, currentSquare, emptySquare)); }
@Test public void testCannotMoveToOccupiedSquare() { Square currentSquare = new Square("a1"); Square occupiedSquare = new Square("b1"); board.placePiece(currentSquare, queen); board.placePiece(occupiedSquare, new Queen(Color.WHITE)); assertFalse(queen.canMove(board, currentSquare, occupiedSquare)); }
@Test public void testCannotAttackNonStraightOrDiagonalSquare() { Square currentSquare = new Square("a1"); Square occupiedSquare = new Square("b8"); board.placePiece(currentSquare, queen); board.placePiece(occupiedSquare, new Queen(Color.BLACK)); assertFalse(queen.canMove(board, currentSquare, occupiedSquare)); }
@Test public void testCanAttackDiagonallyDownAndRight() { Square currentSquare = new Square("d5"); Square occupiedSquare = new Square("f3"); board.placePiece(currentSquare, queen); board.placePiece(occupiedSquare, new Queen(Color.BLACK)); assertTrue(queen.canAttack(board, currentSquare, occupiedSquare)); }
@Test public void testCannotAttackWhenBlocked() { Square currentSquare = new Square("a1"); Square occupiedSquare = new Square("c1"); board.placePiece(currentSquare, queen); board.placePiece(new Square("b1"), new Queen(Color.WHITE)); board.placePiece(occupiedSquare, new Queen(Color.BLACK)); assertFalse(queen.canAttack(board, currentSquare, occupiedSquare)); }
@Test public void testCloneBoard() throws Exception { Player p1 = new Player("P1"); Player p2 = new Player("P2"); Cell[][] boardA = Utils.generateInitialBoard(8, 8, p1, p2); Cell cellA = boardA[1][0]; Piece pieceA = cellA.getContents(); Player playerA = pieceA.getPlayer(); Cell[][] boardB = Utils.cloneBoard(boardA); Cell cellB = boardB[1][0]; Piece pieceB = cellB.getContents(); Player playerB = pieceB.getPlayer(); assertNotSame(cellA, cellB); assertNotSame(pieceA, pieceB); assertSame(playerA, playerB); }
@Test public void testMoveandCapture() { Board b = new Board(true); Piece fire = new Piece(true, b, 0, 0, "pawn"); Piece water = new Piece(false, b, 1, 1, "pawn"); Piece water2 = new Piece(false, b, 3, 3, "pawn"); b.place(fire, 0, 0); b.place(water, 1, 1); b.place(water2, 3, 3); fire.move(2, 2); assertEquals(true, fire.hasCaptured()); assertEquals(fire, b.pieceAt(2, 2)); assertEquals(null, b.pieceAt(1, 1)); fire.move(4, 4); assertEquals(true, fire.hasCaptured()); assertEquals(fire, b.pieceAt(4, 4)); assertEquals(null, b.pieceAt(3, 3)); }
@Test public void testWinner() { Board b = new Board(true); Piece water = new Piece(false, b, 2, 2, "bomb"); Piece fire = new Piece(true, b, 1, 1, "pawn"); Piece water2 = new Piece(false, b, 2, 2, "shield"); b.place(water, 2, 2); b.place(fire, 1, 1); assertEquals(null, b.winner()); water.move(0, 0); assertEquals("No one", b.winner()); b.place(fire, 1, 1); b.place(water2, 2, 2); assertEquals(null, b.winner()); fire.move(3, 3); assertEquals("fire", b.winner()); Piece water3 = new Piece(false, b, 4, 4, "pawn"); b.place(water3, 4, 4); assertEquals(null, b.winner()); water3.move(2, 2); assertEquals("water", b.winner()); }
@Test public void testCloneBoardPiecePropertiesClones() throws Exception { Player p1 = new Player("P1"); Player p2 = new Player("P2"); Cell[][] boardA = Utils.generateInitialBoard(8, 8, p1, p2); Piece pieceA = boardA[1][0].getContents(); Cell[][] boardB = Utils.cloneBoard(boardA); Piece pieceB = boardB[1][0].getContents(); assertEquals(pieceA.isCrowned(), pieceB.isCrowned()); pieceA.crown(); assertTrue(pieceA.isCrowned()); assertFalse(pieceB.isCrowned()); Cell[][] boardC = Utils.cloneBoard(boardA); Piece pieceC = boardC[1][0].getContents(); assertTrue(pieceC.isCrowned()); }
@Test public void testPieces() { Board b = new Board(true); Piece fire = new Piece(true, b, 0, 0, "pawn"); Piece water = new Piece(false, b, 1, 1, "shield"); assertEquals(true, fire.isFire()); assertEquals(false, water.isFire()); assertEquals(false, fire.isShield()); assertEquals(true, water.isShield()); assertEquals(false, fire.isBomb()); assertEquals(false, water.isBomb()); assertEquals(0, fire.side()); assertEquals(1, water.side()); Piece fire2 = new Piece(true, b, 6, 6, "bomb"); // move makes it a king, not place b.place(fire2, 6, 6); fire2.move(7, 7); assertEquals(true, fire2.isKing()); assertEquals(false, water.isKing()); }