public void testMoveDoingUndoingWithPawnPromotion() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 6); string origBoard = ourBoard.ToString(); sizableArray<move> potentialMoves = ourBoard.getMoves(pieceColour.white); if (potentialMoves.Length == 0) Assert.Inconclusive("No pawn moves found"); // Find promotion moves move[] promotionMoves = Array.FindAll(potentialMoves.getArray(), a => a.isPawnPromotion); if (promotionMoves.Length == 0) Assert.Inconclusive("No promotion moves found"); foreach (move thisMove in promotionMoves) { ourBoard.doMove(thisMove); if (ourBoard.ToString() == origBoard) throw new AssertFailedException("After a pawn promotion move, the board has not changed"); // Additionally, verify that the pawn has been promoted if (ourBoard[thisMove.dstPos].type != thisMove.typeToPromoteTo) throw new AssertFailedException("Pawn was not promoted"); if (ourBoard[thisMove.dstPos].GetType() == typeof(pawnSquare)) throw new AssertFailedException("Pawn was not promoted, but type has changed"); if (ourBoard[thisMove.dstPos].colour != pieceColour.white) throw new AssertFailedException("Pawn was promoted to wrong colour"); ourBoard.undoMove(thisMove); if (ourBoard.ToString() != origBoard) throw new AssertFailedException("After a pawn promotion move undo, the board has changed"); } }
public void testKingsideCastlingMoveIsUnExecutedCorrectly() { DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig()); square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0); square ourRook = ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0); ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0); string origBoard = ourBoard.ToString(); // Make out castling move move castlingMove = new move(ourKing, ourBoard[6, 0]); ourBoard.doMove(castlingMove); Assert.AreNotEqual(origBoard, ourBoard.ToString(), "Castling did not affect the board"); // Now undo our castling and verify that we get back to the original position. ourBoard.undoMove(castlingMove); Assert.AreEqual(origBoard, ourBoard.ToString(), "Castling and then un-castling did not return the original board"); }