Example #1
0
        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");
        }
Example #3
0
        public void testMoveUndoingThreatmap_Castling()
        {
            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);

            square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 6, 6);

            string origThreatMap = ourBoard.coverLevel.ToString();

            int[,] threatCounts = new int[DoktorChessAIBoard.sizeX,DoktorChessAIBoard.sizeY];
            for (int x = 0; x < DoktorChessAIBoard.sizeX; x++)
            {
                for (int y = 0; y < DoktorChessAIBoard.sizeY; y++)
                {
                    threatCounts[x, y] = ourBoard[x, y].coveredSquares.Count;
                }
            }

            move castling = new move(ourKing, ourBoard[6, 0]);

            ourBoard.doMove(castling);

            if (ourBoard.coverLevel.ToString() == origThreatMap)
                throw new AssertFailedException("After a move, the threat map has not changed");

            ourBoard.undoMove(castling);

            if (ourBoard.coverLevel.ToString() != origThreatMap)
            {
                Debug.WriteLine("Expected:");
                Debug.WriteLine(origThreatMap);
                Debug.WriteLine("Actual:");
                Debug.WriteLine(ourBoard.coverLevel.ToString());
                throw new AssertFailedException("After a move undo, the threat map has changed");
            }

            for (int x = 0; x < DoktorChessAIBoard.sizeX; x++)
            {
                for (int y = 0; y < DoktorChessAIBoard.sizeY; y++)
                {
                    if (threatCounts[x, y] != ourBoard[x, y].coveredSquares.Count)
                        throw new AssertFailedException("Piece covered count incorrect");
                }
            }
        }