예제 #1
0
        public void testQueenMovementWithCapture()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            squarePos srcSquare = new squarePos(3, 3);

            ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y);
            queenSquare queenie = (queenSquare)ourBoard[srcSquare];

            // Place a black pawn on the board, and ensure that we can capture it, and
            // that we cannot move through it.
            ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 1);

            sizableArray<move> possibleMoves = queenie.getPossibleMoves(ourBoard);
            List<move> expectedmoves = getExpectedMoveSquares(queenie);

            // We don't expect to be able to move to (0,0), since that square is behind an
            // enemy pawn..
            bool found = false;
            for (int i = 0; i < expectedmoves.Count; i++)
            {
                if (expectedmoves[i].dstPos.x == 0 && expectedmoves[i].dstPos.y == 0)
                {
                    expectedmoves.RemoveAt(i);
                    found = true;
                    break;
                }
            }
            if (!found)
                throw new ArgumentOutOfRangeException();

            VectorMovementTests.testListsAreOfSameMoves(expectedmoves, possibleMoves);
        }
예제 #2
0
        public static DoktorChessAIBoard makeFromFEN(string FENString, gameType newType, boardSearchConfig searchConfig)
        {
            DoktorChessAIBoard newBoard = new DoktorChessAIBoard(newType, searchConfig);

            newBoard.makeFromFEN(FENString);

            return newBoard;
        }
예제 #3
0
        public void testCheckDetectionAsWhite()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            ourBoard.addPiece(pieceType.rook, pieceColour.black, 1, 1);
            ourBoard.addPiece(pieceType.king, pieceColour.white, 3, 1);

            Assert.IsTrue(ourBoard.isPlayerInCheck(pieceColour.white));
        }
        public void testQueensideCastlingNotation()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0);
            ourBoard.addPiece(pieceType.rook, pieceColour.white, 0, 0);

            move theMove = new move(ourKing, new square(2, 0));

            Assert.AreEqual("O-O-O", theMove.ToString(moveStringStyle.chessNotation));
        }
        public void testPieceMoveNotation()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square bish = new bishopSquare(new squarePos(0, 0), pieceColour.black);
            square targetSpace = new square( new squarePos(0, 1) );

            move theMove = new move(bish, targetSpace);

            Assert.AreEqual("Ba2", theMove.ToString(moveStringStyle.chessNotation));
        }
예제 #6
0
        public threatMap(DoktorChessAIBoard newBoard)
        {
            _parentBoard = newBoard;

            for (int y = 0; y < DoktorChessAIBoard.sizeY; y++)
            {
                for (int x = 0; x < DoktorChessAIBoard.sizeX; x++)
                {
                    // Spawn lists of pieces which threaten each square
                    piecesWhichThreatenSquare[x, y] = new speedySquareList();
                }
            }
        }
예제 #7
0
        public void testQueenMovement()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            squarePos srcSquare = new squarePos(3, 3);

            ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y);
            queenSquare queenie = (queenSquare) ourBoard[srcSquare];

            sizableArray<move> possibleMoves = queenie.getPossibleMoves(ourBoard);
            List<move> expectedmoves = getExpectedMoveSquares(queenie);

            VectorMovementTests.testListsAreOfSameMoves(expectedmoves, possibleMoves);
        }
        public void testKingsideCastlingMoveIsExecutedCorrectly()
        {
            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);

            // Make our castling move..
            move castlingMove = new move(ourKing, ourBoard[6, 0]);
            ourBoard.doMove(castlingMove);

            // Verify that the rook and king have both moved to their correct squares.
            Assert.IsTrue(ourBoard[6, 0] == ourKing);
            Assert.IsTrue(ourBoard[5, 0] == ourRook);
        }
예제 #9
0
        public void testFinishedGameScoreNoPieces()
        {
            // Generate a board which is lost via the 'no pieces remain' rule, and verify
            // we get the correct score.
            DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 1, 1);

            // position is lost for white..
            BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers());
            Assert.AreEqual(BoardScorer.lowest, whiteScorer.getScore());

            // and won for black.
            BoardScorer blackScorer = new BoardScorer(ourboard, pieceColour.black, new scoreModifiers());
            Assert.AreEqual(BoardScorer.highest, blackScorer.getScore());
        }
예제 #10
0
        public void testThatKingWillNotMoveInToCheck()
        {
            boardSearchConfig config = boardSearchConfig.getDebugConfig();
            config.searchDepth = 0;
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, config);
            square blackKing = ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0);
            ourBoard.addPiece(pieceType.rook, pieceColour.white, 1, 7);
            ourBoard.addPiece(pieceType.king, pieceColour.white, 7, 7);

            // Ensure that black cannot move in to the rook's line of fire.
            sizableArray<move> moves = blackKing.getPossibleMoves(ourBoard);

            foreach (move thisMove in moves)
                Assert.IsTrue(thisMove.dstPos.x == 0, "King moved in to check");

            Assert.IsTrue(moves.Length == 1);
        }
예제 #11
0
        public void testFinishedGameScorePawnToOtherEnd()
        {
            // We make two different boards here to test two different scenarios - if a black
            // pawn is at rank 0 and a white at rank 7.
            DoktorChessAIBoard pawnAt0 = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            pawnAt0.addPiece(pieceType.pawn, pieceColour.black, 1, 0);

            // Should be a black win.
            verifyWonForWhite(pawnAt0, pieceColour.black);

            // Now the white pawn at rank 7.
            DoktorChessAIBoard pawnAt7 = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            pawnAt7.addPiece(pieceType.pawn, pieceColour.white, 1, 7);

            // Should be a white win.
            verifyWonForWhite(pawnAt7, pieceColour.white);
        }
        public void testKingsideCastlingMoveIsNotAfterRookHasMoved()
        {
            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, 6, 0);
            ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0);

            // Move the rook to 7,0.
            ourBoard.doMove(new move(ourRook, ourBoard[7,0]));

            // Now make sure we cannot castle.
            sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard);

            // None of these moves should end up at (6,0).
            if (Array.Find(possibleMoves.getArray(), a => a.dstPos.isSameSquareAs(new squarePos(6, 0))) != null)
                throw new AssertFailedException("Castling found after rook has moved");
        }
예제 #13
0
        public void testNonInitialPawnMovement()
        {
            // Pawns can only move one square after their initial move.
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 1);

            // Mark pawn as having moved
            ourPawn.movedCount++;

            sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard);

            // We expect that the pawn can move one space forward only.
            List<move> expected = new List<move>
                                      {
                                          new move(ourPawn, ourBoard[1, 2])
                                      };

            VectorMovementTests.testListsAreOfSameMoves(expected, actual);
        }
예제 #14
0
        public void testInitialPawnMovement()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 1);
            square ourPawn = ourBoard[1, 1];

            sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard);

            // We expect that the pawn can move two spaces forward, or one space forward.
            List<move> expected = new List<move>
                                      {
                                          new move(ourPawn, ourBoard[1, 2]),
                                          new move(ourPawn, ourBoard[1, 3])
                                      };

            VectorMovementTests.testListsAreOfSameMoves(expected, actual);

            if (ourPawn.movedCount != 0)
                throw new Exception("Pawn not move count not incremented");
        }
        public void testKingsideCastlingMoveIsFound()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0);
            ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0);
            ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0);

            sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard);

            // One of these moves should be a non-capturing move of the king to (6,0).
            move[] castlingMoveList = Array.FindAll(possibleMoves.getArray(), a => !a.isCapture && a.dstPos.isSameSquareAs(new squarePos(6, 0)));

            Assert.AreNotEqual(0, castlingMoveList.Length, "Castling move was not found");
            Assert.AreEqual(1, castlingMoveList.Length, "Multiple castling moves were found");

            // Verify some other stuff on the move.
            move castlingMove = castlingMoveList[0];
            if (!castlingMove.srcPos.isSameSquareAs(ourKing.position))
                throw new AssertFailedException("Castling move has incorrect source square");
        }
예제 #16
0
        public BoardScorer(DoktorChessAIBoard toScore, pieceColour newViewpoint, scoreModifiers newModifiers)
        {
            modifiers = newModifiers;
            viewpoint = newViewpoint;
            List<square> myPieces = toScore.getPiecesForColour(viewpoint);
            List<square> enemyPieces = toScore.getPiecesForColour(viewpoint == pieceColour.black ? pieceColour.white : pieceColour.black);

            parentBoard = toScore;

            if (viewpoint == pieceColour.black)
            {
                _myMaterialAdvantage = toScore.blackMaterialAdvantage;
                _myMaterialDisadvantage = toScore.whiteMaterialAdvantage;
            } else if (viewpoint == pieceColour.white)
            {
                _myMaterialAdvantage = toScore.whiteMaterialAdvantage;
                _myMaterialDisadvantage = toScore.blackMaterialAdvantage;
            }

            _status = toScore.getGameStatus(myPieces, enemyPieces);
        }
예제 #17
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 testKingsideCastlingMoveIsNotFoundThroughAPiece()
        {
            // Place an enemy pawn in the way which will prevent us from castling.
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square ourKing = ourBoard.addPiece(pieceType.king, pieceColour.white, 4, 0);
            ourBoard.addPiece(pieceType.rook, pieceColour.white, 7, 0);
            ourBoard.addPiece(pieceType.pawn, pieceColour.black, 6, 0);
            ourBoard.addPiece(pieceType.king, pieceColour.black, 0, 0);

            sizableArray<move> possibleMoves = ourKing.getPossibleMoves(ourBoard);

            // None of these moves should end up at (6, 0).
            if (Array.Find(possibleMoves.getArray(), a => a.dstPos.isSameSquareAs(new squarePos(6, 0))) != null)
                throw new AssertFailedException("Castling found through an enemy piece");
        }
예제 #19
0
        public void testScoreWithDangling()
        {
            DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 3);
            ourboard.addPiece(pieceType.queen, pieceColour.white, 2, 2);

            ourboard.addPiece(pieceType.king, pieceColour.black, 7, 7);
            ourboard.addPiece(pieceType.king, pieceColour.white, 5, 5);

            BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers());

            // White's queen is dangling, as is blacks pawn.
            int expected = whiteScorer.modifiers.materialModifier * (8 - 1);
            expected -= whiteScorer.modifiers.danglingModifier * 8;
            expected += whiteScorer.modifiers.danglingModifier * 1;

            Assert.AreEqual(expected, whiteScorer.getScore());
        }
예제 #20
0
        public void testVectorMovement(List<squarePos> expectedPos, vectorDirection dir)
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            squarePos srcSquare = new squarePos(3, 3);

            ourBoard.addPiece(pieceType.queen, pieceColour.white, srcSquare.x, srcSquare.y);
            queenSquare queenie = (queenSquare)ourBoard[srcSquare];

            List<move> expectedmoves = new List<move>(expectedPos.Count);

            foreach (squarePos thisPos in expectedPos)
                expectedmoves.Add(new move((square) queenie, ourBoard[thisPos]));

            sizableArray<move> possibleMoves = queenie.getMovesForVector(null, ourBoard, dir);

            testListsAreOfSameMoves(expectedmoves, possibleMoves);
        }
        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");
        }
예제 #22
0
        public void testMaterialAdvantage()
        {
            // Generate a boardScorer and present it with a queen (ours), and two pawns
            // (enemy). Verify the resultant score as 8-2 = 6.

            DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());

            ourboard.addPiece(pieceType.queen, pieceColour.white, 1, 1);
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 4);
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 3, 5);

            BoardScorer myscorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers());

            // Check only material advantage
            myscorer.modifiers.danglingModifier = 0;
            myscorer.modifiers.materialModifier = 1;
            Assert.AreEqual(8 - 2, myscorer.getScore());
        }
예제 #23
0
        public void testPawnMovementWithCaptureCol0()
        {
            // Spawn a black pawn at 0,3 and a white pawn at 1,4. Verify that the black
            // pawn can capture the white.

            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 0, 3);
            square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 4);

            sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard);

            checkContainsSingleCapture(possibleMoves.getArray(), ourPawn, enemyPawn);
        }
예제 #24
0
        private void verifyWonForWhite(DoktorChessAIBoard ourBoard, pieceColour wonCol)
        {
            pieceColour lostCol = DoktorChessAIBoard.getOtherSide(wonCol);

            // The position should be won/lost for white/black, respectively
            Assert.IsTrue(ourBoard.getGameStatus(wonCol) == gameStatus.won);
            Assert.IsTrue(ourBoard.getGameStatus(lostCol) == gameStatus.lost);

            // and this should be reflected in the scores
            BoardScorer whiteScorer = new BoardScorer(ourBoard, wonCol, new scoreModifiers());
            Assert.AreEqual(BoardScorer.highest, whiteScorer.getScore());

            // and won for black.
            BoardScorer blackScorer = new BoardScorer(ourBoard, lostCol, new scoreModifiers());
            Assert.AreEqual(BoardScorer.lowest, blackScorer.getScore());
        }
예제 #25
0
        public void testThatEnPassantOccursWhenItShouldAsBlack()
        {
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            // En passant requires that the enemy pawn has just advanced two squares. Because of this, we make this move on a board and then check that en passant can occur.
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 6, 3);
            square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 7, 1);

            // Advance the enemy pawn
            move advanceTwo = new move(enemyPawn, ourBoard[enemyPawn.position.up(2)]);
            ourBoard.doMove(advanceTwo);

            // Now verify that the enemy pawn is captured.
            sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard);
            move enPassantCapture = null;
            foreach (move thisMove in possibleMoves)
            {
                if (thisMove.isCapture)
                {
                    if (enPassantCapture != null)
                        throw new AssertFailedException("More than one capture was found");

                    // Note that our dest square is not the enemy square here.
                    Assert.IsTrue(thisMove.srcPos.isSameSquareAs(ourPawn.position));
                    Assert.IsTrue(thisMove.dstPos.isSameSquareAs(ourPawn.position.rightOne().downOne() ));
                    Assert.AreSame(thisMove.capturedSquare, enemyPawn);

                    enPassantCapture = thisMove;
                }
            }
            if (enPassantCapture == null)
                throw new AssertFailedException("En passant capture did not occur");

            // Make sure that the en passant capture ends up putting our pawn in the square above the enemy pawn
            Assert.IsTrue(enemyPawn.position.downOne().isSameSquareAs( enPassantCapture.dstPos) );
        }
예제 #26
0
        public void testPawnPromotionWithCapture()
        {
            // Verify promotion occurs when capturing in to the back row.
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 1, 6);
            ourPawn.movedCount++;
            ourBoard.addPiece(pieceType.knight, pieceColour.black, 1, 7);
            ourBoard.addPiece(pieceType.knight, pieceColour.black, 2, 7);

            sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard);

            // We expect a number of moves forward, all of which are promotions.
            List<move> expected = new List<move>
                                      {
                                            new move(ourPawn, ourBoard[2, 7], pieceType.bishop),
                                            new move(ourPawn, ourBoard[2, 7], pieceType.knight),
                                            new move(ourPawn, ourBoard[2, 7], pieceType.queen),
                                            new move(ourPawn, ourBoard[2, 7], pieceType.rook)
                                      };

            VectorMovementTests.testListsAreOfSameMoves(expected, actual);
        }
예제 #27
0
        public void testPawnPromotionAsBlack()
        {
            // Pawns should be able to be promoted to any piece of their own colour, other than a
            // king.
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.normal, boardSearchConfig.getDebugConfig());
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 1, 1);
            ourPawn.movedCount++;

            sizableArray<move> actual = ourPawn.getPossibleMoves(ourBoard);

            // We expect a number of moves forward, all of which are promotions.
            List<move> expected = new List<move>
                                      {
                                            new move(ourPawn, ourBoard[1, 0], pieceType.bishop),
                                            new move(ourPawn, ourBoard[1, 0], pieceType.knight),
                                            new move(ourPawn, ourBoard[1, 0], pieceType.queen),
                                            new move(ourPawn, ourBoard[1, 0], pieceType.rook)
                                      };

            VectorMovementTests.testListsAreOfSameMoves(expected, actual);
        }
예제 #28
0
        public void testFinishedGameScoreStalemate()
        {
            // Generate a board two pawns, deadlocked in front of each other. This should
            // be a draw via stalemate. Add a third pawn to ensure that stalemate is causing
            // the '0' board score, not a materian mismatch.
            DoktorChessAIBoard ourboard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            // Two deadlocked pawns
            ourboard.addPiece(pieceType.pawn, pieceColour.white, 1, 2);
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 1, 3);
            // an outlier pawn
            ourboard.addPiece(pieceType.pawn, pieceColour.black, 4, 4);

            Assert.IsTrue(ourboard.getGameStatus(pieceColour.white) == gameStatus.drawn);
            Assert.IsTrue(ourboard.getGameStatus(pieceColour.black) == gameStatus.drawn);

            BoardScorer whiteScorer = new BoardScorer(ourboard, pieceColour.white, new scoreModifiers());
            Assert.AreEqual(0, whiteScorer.getScore());
            BoardScorer blackScorer = new BoardScorer(ourboard, pieceColour.black, new scoreModifiers());
            Assert.AreEqual(0, blackScorer.getScore());
        }
예제 #29
0
        public void testPawnMovementWithCaptureCol7()
        {
            // Now test the same, at the other end of the board. Test on the edge.
            DoktorChessAIBoard ourBoard = new DoktorChessAIBoard(gameType.queenAndPawns, boardSearchConfig.getDebugConfig());
            square ourPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.white, 6, 3);
            square enemyPawn = ourBoard.addPiece(pieceType.pawn, pieceColour.black, 7, 4);

            sizableArray<move> possibleMoves = ourPawn.getPossibleMoves(ourBoard);

            checkContainsSingleCapture(possibleMoves.getArray(), ourPawn, enemyPawn);
        }
예제 #30
0
        public void verifyFiftyMoveRule(DoktorChessAIBoard ourBoard, int moveOffset)
        {
            for (int n = 0; n < 100 - moveOffset; n++)
            {
                Assert.AreEqual(gameStatus.inProgress, ourBoard.getGameStatus(pieceColour.white), "Game declared drawn at move " + n.ToString());

                switch (n % 4)
                {
                    case 0:
                        // Play Nc3
                        ourBoard.doMove(new move(ourBoard[1, 0], ourBoard[2, 2]));
                        break;
                    case 1:
                        // Play Nc6
                        ourBoard.doMove(new move(ourBoard[1, 7], ourBoard[2, 5]));
                        break;
                    case 2:
                        // And move knights back again.
                        // Nb1
                        ourBoard.doMove(new move(ourBoard[2, 2], ourBoard[1, 0]));
                        break;
                    case 3:
                        // nb8
                        ourBoard.doMove(new move(ourBoard[2, 5], ourBoard[1, 7]));
                        break;
                    default:
                        throw new ArgumentException();
                }
            }
            // 50 moves have elapsed! It's a draw!
            Assert.AreEqual(gameStatus.drawn, ourBoard.getGameStatus(pieceColour.white));
        }