public void E4_16Moves_8Captures_Correct()
        {
            var gameState = FenHelpers.Parse("K7/8/2p1p1p1/8/2p1Q1p1/8/2p1p1p1/k7 w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveCount    = moves.Count;
            var captureViews = GetCaptureMoveViews(moves);

            var capture1 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.C6.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture2 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.E6.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture3 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.G6.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture4 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.C4.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture5 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.G4.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture6 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.C2.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture7 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.E2.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture8 = MoveBuilder.Create(Colour.White, PieceType.Queen, SquareFlag.E4.ToSquare(), SquareFlag.G2.ToSquare(), PieceType.Pawn, MoveType.Ordinary);

            var captures = captureViews.Select(x => x.Value);

            Assert.Contains(capture1, captures);
            Assert.Contains(capture2, captures);
            Assert.Contains(capture3, captures);
            Assert.Contains(capture4, captures);
            Assert.Contains(capture5, captures);
            Assert.Contains(capture6, captures);
            Assert.Contains(capture7, captures);
            Assert.Contains(capture8, captures);
        }
Beispiel #2
0
        private void BitboardSquaresTestHelper(Position position, int depth)
        {
            Assert.DoesNotThrow(position.AssertBitboardsMatchSquares);
            if (depth <= 0)
            {
                return;
            }

            var moves = new List <Move>();

            _moveGenerator.Generate(moves, position);

            var tmpPosition = new Position();

            foreach (var move in moves)
            {
                var updatedBoard = Position.MakeMove(tmpPosition, move, position);

                if (!_moveGenerator.OnlyLegalMoves && updatedBoard.MovedIntoCheck())
                {
                    continue;
                }

                BitboardSquaresTestHelper(updatedBoard, depth - 1);
            }
        }
Beispiel #3
0
        public void White_FourCaptures_OnePush_Correct()
        {
            var gameState = FenHelpers.Parse("K6k/8/8/8/8/p1p2p1p/1P4P1/8 w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var move1 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.B2.ToSquare(), SquareFlag.B3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var move2 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.G2.ToSquare(), SquareFlag.G3.ToSquare(), PieceType.None, MoveType.Ordinary);

            var captures = moves.Where(x => x.GetCapturePieceType() != PieceType.None);

            var capture1 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.B2.ToSquare(), SquareFlag.A3.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture2 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.B2.ToSquare(), SquareFlag.C3.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture3 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.G2.ToSquare(), SquareFlag.F3.ToSquare(), PieceType.Pawn, MoveType.Ordinary);
            var capture4 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.G2.ToSquare(), SquareFlag.H3.ToSquare(), PieceType.Pawn, MoveType.Ordinary);

            Assert.Contains(move1, moves);
            Assert.Contains(move2, moves);

            Assert.Contains(capture1, moves);
            Assert.Contains(capture2, moves);
            Assert.Contains(capture3, moves);
            Assert.Contains(capture4, moves);
        }
Beispiel #4
0
        private void ApplyMove(Board board, Colour colour, MoveViewer move)
        {
            board.MakeMove(move.Value);

            Ply++;

            if (move.PieceType == PieceType.Pawn || move.CapturePieceType != PieceType.None)
            {
                HalfMoveClock = 0;
            }
            else
            {
                ++HalfMoveClock;
            }

            var gameState = GetGameState();

            var currentState = board.CurrentState;

            var historyItem = new GameHistoryNode(currentState, gameState);

            history.Push(historyItem);

            if (historyItem.IsIrreversible)
            {
                drawBuffer.Clear();
            }
            else
            {
                drawBuffer.Add(historyItem);
            }

            var isDrawn = IsDrawn(HalfMoveClock, drawBuffer);

            if (isDrawn)
            {
                Draw?.Invoke(this, new MoveAppliedEventArgs(move, gameState, Evaluate()));

                return;
            }

            var moves = new List <uint>();

            moveGenerator.Generate(board, colour.Opposite(), moves);

            AvailableMoves = moves.Select(x => new MoveViewer(x));

            if (!AvailableMoves.Any())
            {
                Checkmate?.Invoke(this, new MoveAppliedEventArgs(move, gameState, Evaluate()));

                return;
            }

            MoveApplied?.Invoke(this, new MoveAppliedEventArgs(move, gameState, Evaluate()));
        }
Beispiel #5
0
        public void Black_FourBlocked_NoMoves_Correct()
        {
            var gameState = FenHelpers.Parse("K6k/1p1p1p1p/1P1P1P1P/8/8/8/8/8 b - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetPawnMoveViews(moves);

            Assert.Empty(moveViews);
        }
Beispiel #6
0
        public void KnightNotActuallyPinned(string fenString, int expectedMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetKnightMoveViews(moves);

            Assert.Equal(expectedMoveCount, moveViews.Count);
        }
Beispiel #7
0
        public void PawnPinnedByBishopButCanCapture(string fenString, int expectedMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetPawnMoveViews(moves);

            Assert.Equal(expectedMoveCount, moveViews.Count);
        }
        public void A1_H8_0Capture(string fenString, int moveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var movesViews = GetQueenMoveViews(moves);

            Assert.Equal(moveCount, movesViews.Count);
        }
        public void B2_21Moves_0Captures_Correct()
        {
            var gameState = FenHelpers.Parse("8/8/8/k7/8/8/1Q6/4K3 w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var movesViews = GetQueenMoveViews(moves);

            Assert.Equal(23, movesViews.Count);
        }
Beispiel #10
0
        public void AvoidsMovingIntoNonDiagonalCheck(string fenString, int expectedMovesCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var kingMoves = GetKingMoveViews(moves);

            Assert.Equal(expectedMovesCount, kingMoves.Count());
        }
Beispiel #11
0
        public void AllDirectionsBlocked(string fenString, int expectedMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetRookMoveViews(moves);

            Assert.Equal(expectedMoveCount, moveViews.Count);
        }
Beispiel #12
0
        public void Position3_Variants_EnPassantDiscovered(string fenString, int expectedMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetPawnMoveViews(moves);

            Assert.Equal(expectedMoveCount, moveViews.Count);
        }
Beispiel #13
0
        public void DiscoverCheckRook2(string fenString)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetPawnMoveViews(moves);

            Assert.Equal(5, moveViews.Count);
        }
Beispiel #14
0
        public void EvadesCheckByKnight(string fenString, int expectedMovesCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveCount = moves.Count;

            Assert.Equal(expectedMovesCount, moveCount);
        }
Beispiel #15
0
        public void FromCorners(string fenString, int expectedMovesCount)
        {
            // This is mainly checking the pawn check magic bitboards as it uses them
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveCount = moves.Count;

            Assert.Equal(expectedMovesCount, moveCount);
        }
Beispiel #16
0
        public void White_EnPassant_Capture_DiscoveredCheck()
        {
            var gameState = FenHelpers.Parse("8/8/8/q1rPp2K/8/7p/8/8 w - e6");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var enPassantCapture = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D6.ToSquare(), SquareFlag.E7.ToSquare(), PieceType.Pawn, MoveType.EnPassant);

            var movesView = moves.Select(x => new MoveViewer(x));

            Assert.DoesNotContain(enPassantCapture, moves);
        }
Beispiel #17
0
        public void DiscoverCheck(string fenString, SquareFlag fromSquare, SquareFlag toSquare)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveCount = moves.Count;

            var illegalMove = MoveBuilder.Create(Colour.White, PieceType.Pawn, fromSquare.ToSquare(), toSquare.ToSquare(), PieceType.None, MoveType.Ordinary);

            Assert.DoesNotContain(illegalMove, moves);
        }
Beispiel #18
0
        public void White_DiscoveredCheck()
        {
            var gameState = FenHelpers.Parse("8/2b5/3P4/4K3/8/8/8/7k w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var illegalMove = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D6.ToSquare(), SquareFlag.D7.ToSquare(), PieceType.None, MoveType.Ordinary);

            var movesView = moves.Select(x => new MoveViewer(x));

            Assert.DoesNotContain(illegalMove, moves);
        }
Beispiel #19
0
        public void White_Capture()
        {
            var gameState = FenHelpers.Parse("K6k/8/8/8/8/3p4/4P3/8 w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var capture = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.E2.ToSquare(), SquareFlag.D3.ToSquare(), PieceType.Pawn, MoveType.Ordinary);

            var movesView = moves.Select(x => new MoveViewer(x));

            Assert.Contains(capture, moves);
        }
Beispiel #20
0
        public void White_EnPassant_Capture()
        {
            var gameState = FenHelpers.Parse("K6k/8/8/3Pp3/8/8/8/8 w - e6");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var enPassantCapture = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D5.ToSquare(), SquareFlag.E6.ToSquare(), PieceType.Pawn, MoveType.EnPassant);

            var movesView = moves.Select(x => new MoveViewer(x));

            Assert.Contains(enPassantCapture, moves);
        }
Beispiel #21
0
        public void EvadesDoubleCheck()
        {
            var gameState = FenHelpers.Parse("k7/2Q5/8/4p3/3K1P2/2q5/8/8 w - - 0 1");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveCount = moves.Count;

            Assert.Equal(3, moveCount);

            Assert.Equal(2, moves.First().GetNumCheckers());
        }
Beispiel #22
0
        public void MidBoardOnlyOnePush(string fenString, SquareFlag toSquare)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var pawnMoveViews = GetPawnMoveViews(moves);

            var pawnMoves = pawnMoveViews.Select(x => x.Value);

            Assert.Collection(pawnMoves, x => Assert.Equal(toSquare, x.GetTo()));
        }
Beispiel #23
0
        public void Black_EightPawns_OneAndTwoPushes()
        {
            var gameState = FenHelpers.Parse("K6k/pppppppp/8/8/8/8/8/8 b - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            // Purely for debugging
            var pawnMoves = GetPawnMoveViews(moves);

            var moveA3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.A7.ToSquare(), SquareFlag.A6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveA4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.A7.ToSquare(), SquareFlag.A5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveB3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.B7.ToSquare(), SquareFlag.B6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveB4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.B7.ToSquare(), SquareFlag.B5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveC3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.C7.ToSquare(), SquareFlag.C6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveC4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.C7.ToSquare(), SquareFlag.C5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveD3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.D6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveD4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.D5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveE3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.E7.ToSquare(), SquareFlag.E6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveE4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.E7.ToSquare(), SquareFlag.E5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveF3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.F7.ToSquare(), SquareFlag.F6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveF4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.F7.ToSquare(), SquareFlag.F5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveG3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.G7.ToSquare(), SquareFlag.G6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveG4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.G7.ToSquare(), SquareFlag.G5.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveH3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.H7.ToSquare(), SquareFlag.H6.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveH4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.H7.ToSquare(), SquareFlag.H5.ToSquare(), PieceType.None, MoveType.Ordinary);

            Assert.Contains(moveA3, moves);
            Assert.Contains(moveA4, moves);
            Assert.Contains(moveB3, moves);
            Assert.Contains(moveB4, moves);
            Assert.Contains(moveC3, moves);
            Assert.Contains(moveC4, moves);
            Assert.Contains(moveD3, moves);
            Assert.Contains(moveD4, moves);
            Assert.Contains(moveE3, moves);
            Assert.Contains(moveE4, moves);
            Assert.Contains(moveF3, moves);
            Assert.Contains(moveF4, moves);
            Assert.Contains(moveG3, moves);
            Assert.Contains(moveG4, moves);
            Assert.Contains(moveH3, moves);
            Assert.Contains(moveH4, moves);
        }
Beispiel #24
0
        public void LargeOccupancyOneCapture(string fenString, int expectedMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var moveViews = GetRookMoveViews(moves);

            var captureViews = GetCaptureMoveViews(moves);

            Assert.Equal(expectedMoveCount, moveViews.Count);
            Assert.Equal(1, captureViews.Count);
        }
Beispiel #25
0
        public void White_EightPawns_OneAndTwoPushes()
        {
            var gameState = FenHelpers.Parse("K6k/8/8/8/8/8/PPPPPPPP/8 w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var pawnMoves = GetPawnMoveViews(moves);

            var moveA3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.A2.ToSquare(), SquareFlag.A3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveA4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.A2.ToSquare(), SquareFlag.A4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveB3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.B2.ToSquare(), SquareFlag.B3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveB4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.B2.ToSquare(), SquareFlag.B4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveC3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.C2.ToSquare(), SquareFlag.C3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveC4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.C2.ToSquare(), SquareFlag.C4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveD3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.D2.ToSquare(), SquareFlag.D3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveD4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.D2.ToSquare(), SquareFlag.D4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveE3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.E2.ToSquare(), SquareFlag.E3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveE4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.E2.ToSquare(), SquareFlag.E4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveF3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.F2.ToSquare(), SquareFlag.F3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveF4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.F2.ToSquare(), SquareFlag.F4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveG3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.G2.ToSquare(), SquareFlag.G3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveG4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.G2.ToSquare(), SquareFlag.G4.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveH3 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.H2.ToSquare(), SquareFlag.H3.ToSquare(), PieceType.None, MoveType.Ordinary);
            var moveH4 = MoveBuilder.Create(gameState.ToPlay, PieceType.Pawn, SquareFlag.H2.ToSquare(), SquareFlag.H4.ToSquare(), PieceType.None, MoveType.Ordinary);

            Assert.Contains(moveA3, moves);
            Assert.Contains(moveA4, moves);
            Assert.Contains(moveB3, moves);
            Assert.Contains(moveB4, moves);
            Assert.Contains(moveC3, moves);
            Assert.Contains(moveC4, moves);
            Assert.Contains(moveD3, moves);
            Assert.Contains(moveD4, moves);
            Assert.Contains(moveE3, moves);
            Assert.Contains(moveE4, moves);
            Assert.Contains(moveF3, moves);
            Assert.Contains(moveF4, moves);
            Assert.Contains(moveG3, moves);
            Assert.Contains(moveG4, moves);
            Assert.Contains(moveH3, moves);
            Assert.Contains(moveH4, moves);
        }
Beispiel #26
0
        public void Castle_BothSidesCreated()
        {
            var board = CreateBoard("r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1");

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, Colour.White, moves);

            var moveCount = moves.Count;

            var castleKing  = moves.Where(x => x.GetMoveType() == MoveType.CastleKing);
            var castleQueen = moves.Where(x => x.GetMoveType() == MoveType.CastleQueen);

            var castleKingCount  = castleKing.Count();
            var castleQueenCount = castleQueen.Count();

            Assert.Equal(1, castleKingCount);
            Assert.Equal(1, castleQueenCount);
        }
Beispiel #27
0
        public void Castle_BlockedByPassingThroughCheck(string partialFen, int castleKingExpectedCount, int castleQueenExpectedCount)
        {
            var board = CreateBoard($"r3k2r/8/8/8/8/8/{partialFen}/R3K2R w KQkq - 0 1");

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, Colour.White, moves);

            var moveCount = moves.Count;

            var castleKing  = moves.Where(x => x.GetMoveType() == MoveType.CastleKing);
            var castleQueen = moves.Where(x => x.GetMoveType() == MoveType.CastleQueen);

            var castleKingCount  = castleKing.Count();
            var castleQueenCount = castleQueen.Count();

            Assert.Equal(castleKingExpectedCount, castleKingCount);
            Assert.Equal(castleQueenExpectedCount, castleQueenCount);
        }
        public void E4_UnblockedCapture(string fenString, SquareFlag captureSquare, int expectedQueenMoveCount)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(fenString);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var queenMoves = GetQueenMoveViews(moves);

            var captures = GetCaptureMoveViews(moves);

            var capture1 = MoveBuilder.Create(gameState.ToPlay, PieceType.Queen, SquareFlag.E4.ToSquare(), captureSquare.ToSquare(), PieceType.Pawn, MoveType.Ordinary);

            Assert.Equal(expectedQueenMoveCount, queenMoves.Count);
            Assert.Contains(capture1, captures.Select(x => x.Value));
        }
Beispiel #29
0
        public void White_Capture_OneCapture_Promotion_Correct()
        {
            var gameState = FenHelpers.Parse("3nn3/3P4/8/8/8/8/8/K6k w - -");

            var board = CreateBoard(gameState);

            var moves = new List <uint>(10);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var promotion1 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.E8.ToSquare(), PieceType.Knight, MoveType.PromotionQueen);
            var promotion2 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.E8.ToSquare(), PieceType.Knight, MoveType.PromotionRook);
            var promotion3 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.E8.ToSquare(), PieceType.Knight, MoveType.PromotionBishop);
            var promotion4 = MoveBuilder.Create(Colour.White, PieceType.Pawn, SquareFlag.D7.ToSquare(), SquareFlag.E8.ToSquare(), PieceType.Knight, MoveType.PromotionKnight);

            Assert.Contains(promotion1, moves);
            Assert.Contains(promotion2, moves);
            Assert.Contains(promotion3, moves);
            Assert.Contains(promotion4, moves);
        }
Beispiel #30
0
        public void EvadesCheckByRook(string fenString, int expectedMovesCount, SquareFlag toSquare)
        {
            var gameState = FenHelpers.Parse(fenString);

            var board = CreateBoard(gameState);

            var moves = new List <uint>(20);

            MoveGenerator.Generate(board, gameState.ToPlay, moves);

            var kingMoves = GetKingMoveViews(moves);

            var captureViews = GetCaptureMoveViews(moves);

            var capture1 = MoveBuilder.Create(gameState.ToPlay, PieceType.King, SquareFlag.E4.ToSquare(), toSquare.ToSquare(), PieceType.Rook, MoveType.Ordinary, 1);

            Assert.Equal(expectedMovesCount, kingMoves.Count());

            Assert.Contains(capture1, captureViews.Select(x => x.Value));
        }