Ejemplo n.º 1
0
        static void GenerateWhiteCastlingMoves(byte[] cells, int fromSquare, Castlings availableCastlings, List <GeneratedMove> collector)
        {
            if (fromSquare != Cells.E1)
            {
                return;
            }

            if ((availableCastlings & Castlings.WQ) != 0)
            {
                if (cells[Cells.D1] == 0 && cells[Cells.C1] == 0 && cells[Cells.B1] == 0)
                {
                    if (!cells.IsSquareAttackedByBlack(Cells.E1) && !cells.IsSquareAttackedByBlack(Cells.D1) && !cells.IsSquareAttackedByBlack(Cells.C1))
                    {
                        collector.Add(new GeneratedMove(Cells.E1, Cells.C1, MoveAnnotations.WQ));
                    }
                }
            }

            if ((availableCastlings & Castlings.WK) != 0)
            {
                if (cells[Cells.F1] == 0 && cells[Cells.G1] == 0)
                {
                    if (!cells.IsSquareAttackedByBlack(Cells.E1) && !cells.IsSquareAttackedByBlack(Cells.F1) && !cells.IsSquareAttackedByBlack(Cells.G1))
                    {
                        collector.Add(new GeneratedMove(Cells.E1, Cells.G1, MoveAnnotations.WK));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void GenerateBlackCastlingMoves(byte[] cells, int fromSquare, Castlings availableCastlings, List <GeneratedMove> collector)
        {
            if (fromSquare != Cells.E8)
            {
                return;
            }

            if ((availableCastlings & Castlings.BQ) != 0)
            {
                if (cells[Cells.D8] == 0 && cells[Cells.C8] == 0 && cells[Cells.B8] == 0)
                {
                    if (!cells.IsSquareAttackedByWhite(Cells.E8) && !cells.IsSquareAttackedByWhite(Cells.D8) && !cells.IsSquareAttackedByWhite(Cells.C8))
                    {
                        collector.Add(new GeneratedMove(Cells.E8, Cells.C8, MoveAnnotations.BQ));
                    }
                }
            }

            if ((availableCastlings & Castlings.BK) != 0)
            {
                if (cells[Cells.F8] == 0 && cells[Cells.G8] == 0)
                {
                    if (!cells.IsSquareAttackedByWhite(Cells.E8) && !cells.IsSquareAttackedByWhite(Cells.F8) && !cells.IsSquareAttackedByWhite(Cells.G8))
                    {
                        collector.Add(new GeneratedMove(Cells.E8, Cells.G8, MoveAnnotations.BK));
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public PositionCore(byte[] cells, Color turn, Castlings availableCastlings, int?enPassant, int whiteKing, int blackKing)
 {
     Debug.Assert(cells.Length == BytesCount);
     Cells = cells;
     Turn  = turn;
     CastlingAvailability = availableCastlings;
     EnPassant            = enPassant;
     WhiteKing            = whiteKing;
     BlackKing            = blackKing;
 }
Ejemplo n.º 4
0
        static void GenerateWhiteCastlingMoves(byte[] cells, int fromSquare, Castlings availableCastlings, List<GeneratedMove> collector)
        {
            if (fromSquare != Cells.E1) return;

            if ((availableCastlings & Castlings.WQ) != 0)
                if (cells[Cells.D1] == 0 && cells[Cells.C1] == 0 && cells[Cells.B1] == 0)
                    if (!cells.IsSquareAttackedByBlack(Cells.E1) && !cells.IsSquareAttackedByBlack(Cells.D1) && !cells.IsSquareAttackedByBlack(Cells.C1))
                        collector.Add(new GeneratedMove(Cells.E1, Cells.C1, MoveAnnotations.WQ));

            if ((availableCastlings & Castlings.WK) != 0)
                if (cells[Cells.F1] == 0 && cells[Cells.G1] == 0)
                    if (!cells.IsSquareAttackedByBlack(Cells.E1) && !cells.IsSquareAttackedByBlack(Cells.F1) && !cells.IsSquareAttackedByBlack(Cells.G1))
                        collector.Add(new GeneratedMove(Cells.E1, Cells.G1, MoveAnnotations.WK));
        }
Ejemplo n.º 5
0
        static void GenerateBlackCastlingMoves(byte[] cells, int fromSquare, Castlings availableCastlings, List<GeneratedMove> collector)
        {
            if (fromSquare != Cells.E8) return;

            if ((availableCastlings & Castlings.BQ) != 0)
                if (cells[Cells.D8] == 0 && cells[Cells.C8] == 0 && cells[Cells.B8] == 0)
                    if (!cells.IsSquareAttackedByWhite(Cells.E8) && !cells.IsSquareAttackedByWhite(Cells.D8) && !cells.IsSquareAttackedByWhite(Cells.C8))
                        collector.Add(new GeneratedMove(Cells.E8, Cells.C8, MoveAnnotations.BQ));

            if ((availableCastlings & Castlings.BK) != 0)
                if (cells[Cells.F8] == 0 && cells[Cells.G8] == 0)
                    if (!cells.IsSquareAttackedByWhite(Cells.E8) && !cells.IsSquareAttackedByWhite(Cells.F8) && !cells.IsSquareAttackedByWhite(Cells.G8))
                        collector.Add(new GeneratedMove(Cells.E8, Cells.G8, MoveAnnotations.BK));
        }
Ejemplo n.º 6
0
        public static void GenerateMoves(byte[] cells, 
			 int whiteKingSquare, int blackKingSquare, Piece piece, int fromSquare,
             int? enPassantFile, Castlings availableCastlings, List<GeneratedMove> collector)
        {
            switch (piece)
            {
                #region ' White Pawn '
                case Piece.WhitePawn:
                    GenerateWhitePawnMoves(cells, whiteKingSquare, fromSquare, enPassantFile, collector);
                    break;
                #endregion

                #region ' White Bishop '
                case Piece.WhiteBishop:
                    for (var to = fromSquare + 17; (to & 0x88) == 0; to += 17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -15; (to & 0x88) == 0; to += -15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -17; (to & 0x88) == 0; to += -17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 15; (to & 0x88) == 0; to += 15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteBishop;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' White Knight '
                case Piece.WhiteKnight:
                    {
                        var to = fromSquare + 33;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 31;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -31;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -33;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 18;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 14;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -14;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -18;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.WhiteKnight;
                                if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.WhiteKnight;
                            }
                        }
                    }
                    break;
                #endregion

                #region ' White Rook '
                case Piece.WhiteRook:
                    for (var to = fromSquare + 16; (to & 0x88) == 0; to += 16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 1; (to & 0x88) == 0; to += 1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -16; (to & 0x88) == 0; to += -16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -1; (to & 0x88) == 0; to += -1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteRook;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' White Queen '
                case Piece.WhiteQueen:
                    for (var to = fromSquare + 16; (to & 0x88) == 0; to += 16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 1; (to & 0x88) == 0; to += 1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -16; (to & 0x88) == 0; to += -16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -1; (to & 0x88) == 0; to += -1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 17; (to & 0x88) == 0; to += 17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -15; (to & 0x88) == 0; to += -15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -17; (to & 0x88) == 0; to += -17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 15; (to & 0x88) == 0; to += 15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.WhiteQueen;
                            if (!cells.IsSquareAttackedByBlack(whiteKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.WhiteQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' White King '
                case Piece.WhiteKing:
                    {
                        var to = fromSquare + 16;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 17;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 1;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -15;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -16;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -17;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -1;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 15;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.White)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByBlack(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.WhiteKing;
                            }
                        }
                    }
                    GenerateWhiteCastlingMoves(cells, fromSquare, availableCastlings, collector);
                    break;
                #endregion

                #region ' Black Pawn '
                case Piece.BlackPawn:
                    GenerateBlackPawnMoves(cells, blackKingSquare, fromSquare, enPassantFile, collector);
                    break;
                #endregion

                #region ' Black Bishop '
                case Piece.BlackBishop:
                    for (var to = fromSquare + 17; (to & 0x88) == 0; to += 17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -15; (to & 0x88) == 0; to += -15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -17; (to & 0x88) == 0; to += -17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 15; (to & 0x88) == 0; to += 15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackBishop;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Bishop | Capture));
                            cells[fromSquare] = (byte)Piece.BlackBishop;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' Black Knight '
                case Piece.BlackKnight:
                    {
                        var to = fromSquare + 33;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 31;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -31;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -33;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 18;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 14;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -14;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -18;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                cells[to] = (byte)Piece.BlackKnight;
                                if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                    collector.Add(new GeneratedMove(fromSquare, to, Knight | Capture));
                                cells[to] = toPiece;
                                cells[fromSquare] = (byte)Piece.BlackKnight;
                            }
                        }
                    }
                    break;
                #endregion

                #region ' Black Rook '
                case Piece.BlackRook:
                    for (var to = fromSquare + 16; (to & 0x88) == 0; to += 16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 1; (to & 0x88) == 0; to += 1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -16; (to & 0x88) == 0; to += -16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -1; (to & 0x88) == 0; to += -1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackRook;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Rook | Capture));
                            cells[fromSquare] = (byte)Piece.BlackRook;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' Black Queen '
                case Piece.BlackQueen:
                    for (var to = fromSquare + 16; (to & 0x88) == 0; to += 16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 1; (to & 0x88) == 0; to += 1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -16; (to & 0x88) == 0; to += -16)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -1; (to & 0x88) == 0; to += -1)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 17; (to & 0x88) == 0; to += 17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -15; (to & 0x88) == 0; to += -15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + -17; (to & 0x88) == 0; to += -17)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    for (var to = fromSquare + 15; (to & 0x88) == 0; to += 15)
                    {
                        var toPiece = cells[to];
                        if (toPiece == 0)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                        }
                        else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                        {
                            cells[fromSquare] = (byte)Piece.EmptyCell;
                            cells[to] = (byte)Piece.BlackQueen;
                            if (!cells.IsSquareAttackedByWhite(blackKingSquare))
                                collector.Add(new GeneratedMove(fromSquare, to, Queen | Capture));
                            cells[fromSquare] = (byte)Piece.BlackQueen;
                            cells[to] = toPiece;
                            break;
                        }
                        else break;
                    }
                    break;
                #endregion

                #region ' Black King '
                case Piece.BlackKing:
                    {
                        var to = fromSquare + 16;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 17;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 1;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -15;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -16;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -17;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + -1;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    {
                        var to = fromSquare + 15;
                        if ((to & 0x88) == 0)
                        {
                            var toPiece = cells[to];
                            if (toPiece == 0)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                            else if ((Color)(toPiece & (byte)Color.Black) != Color.Black)
                            {
                                cells[fromSquare] = (byte)Piece.EmptyCell;
                                if (!cells.IsSquareAttackedByWhite(to))
                                    collector.Add(new GeneratedMove(fromSquare, to, King | Capture));
                                cells[fromSquare] = (byte)Piece.BlackKing;
                            }
                        }
                    }
                    GenerateBlackCastlingMoves(cells, fromSquare, availableCastlings, collector);
                    break;
                #endregion

            }
        }
Ejemplo n.º 7
0
        private static MoveAnnotations ValidateMove(byte[] cells, Piece piece, int fromSquare, int toSquare, Piece capture, Castlings availableCastlings)
        {
            switch (piece)
            {
                case Piece.WhitePawn:
                    return ValidateWhitePawnMove(cells, fromSquare, toSquare, capture);

                case Piece.WhiteBishop:
                    return ValidateWhiteBishopMove(cells, fromSquare, toSquare);

                case Piece.WhiteKnight:
                    return ValidateWhiteKnightMove(fromSquare, toSquare);

                case Piece.WhiteRook:
                    return ValidateWhiteRookMove(cells, fromSquare, toSquare);

                case Piece.WhiteQueen:
                    return ValidateWhiteQueenMove(cells, fromSquare, toSquare);

                case Piece.WhiteKing:
                    if (ValidateWhiteKingMove(fromSquare, toSquare) == King)
                        return King;
                    return ValidateWhiteCastlingMove(cells, fromSquare, toSquare, availableCastlings);

                case Piece.BlackPawn:
                    return ValidateBlackPawnMove(cells, fromSquare, toSquare, capture);

                case Piece.BlackBishop:
                    return ValidateBlackBishopMove(cells, fromSquare, toSquare);

                case Piece.BlackKnight:
                    return ValidateBlackKnightMove(fromSquare, toSquare);

                case Piece.BlackRook:
                    return ValidateBlackRookMove(cells, fromSquare, toSquare);

                case Piece.BlackQueen:
                    return ValidateBlackQueenMove(cells, fromSquare, toSquare);

                case Piece.BlackKing:
                    if (ValidateBlackKingMove(fromSquare, toSquare) == King)
                        return King;
                    return ValidateBlackCastlingMove(cells, fromSquare, toSquare, availableCastlings);

                default: throw new System.InvalidOperationException("Unknown piece: " + piece);
            }
        }
Ejemplo n.º 8
0
        static MoveAnnotations ValidateBlackCastlingMove(byte[] cells, int fromSquare, int toSquare, Castlings availableCastlings)
        {
            if (fromSquare != S.E8)
            {
                return(King | DoesNotMoveThisWay);
            }
            switch (toSquare)
            {
            case S.C8:     // Queenside
                if (cells[S.D8] != 0 || cells[S.B8] != 0)
                {
                    return(King | DoesNotJump | BQ);
                }
                if (cells[S.C8] != 0)
                {
                    return(King | Capture | DoesNotCaptureThisWay | BQ);
                }
                if ((availableCastlings & Castlings.BQ) == 0)
                {
                    return(King | BQ | HasNoCastling);
                }
                if (cells.IsSquareAttackedByWhite(S.E8))
                {
                    return(King | CastleFromCheck | BQ);
                }
                if (cells.IsSquareAttackedByWhite(S.D8))
                {
                    return(King | CastleThroughCheck | BQ);
                }
                return(King | BQ);

            case S.G8:     // Kingside
                if (cells[S.F8] != 0)
                {
                    return(King | DoesNotJump | BK);
                }
                if (cells[S.G8] != 0)
                {
                    return(King | Capture | DoesNotCaptureThisWay | BK);
                }
                if ((availableCastlings & Castlings.BK) == 0)
                {
                    return(King | BK | HasNoCastling);
                }
                if (cells.IsSquareAttackedByWhite(S.E8))
                {
                    return(King | CastleFromCheck | BK);
                }
                if (cells.IsSquareAttackedByWhite(S.F8))
                {
                    return(King | CastleThroughCheck | BK);
                }
                return(King | BK);
            }
            return(King | DoesNotMoveThisWay);
        }
Ejemplo n.º 9
0
        static MoveAnnotations ValidateWhiteCastlingMove(byte[] cells, int fromSquare, int toSquare, Castlings availableCastlings)
        {
            if (fromSquare != S.E1)
            {
                return(King | DoesNotMoveThisWay);
            }
            switch (toSquare)
            {
            case S.C1:     // Queenside
                if (cells[S.D1] != 0 || cells[S.B1] != 0)
                {
                    return(King | DoesNotJump | WQ);
                }
                if (cells[S.C1] != 0)
                {
                    return(King | Capture | DoesNotCaptureThisWay | WQ);
                }
                if ((availableCastlings & Castlings.WQ) == 0)
                {
                    return(King | WQ | HasNoCastling);
                }
                if (cells.IsSquareAttackedByBlack(S.E1))
                {
                    return(King | CastleFromCheck | WQ);
                }
                if (cells.IsSquareAttackedByBlack(S.D1))
                {
                    return(King | CastleThroughCheck | WQ);
                }
                return(King | WQ);

            case S.G1:     // Kingside
                if (cells[S.F1] != 0)
                {
                    return(King | DoesNotJump | WK);
                }
                if (cells[S.G1] != 0)
                {
                    return(King | Capture | DoesNotCaptureThisWay | WK);
                }
                if ((availableCastlings & Castlings.WK) == 0)
                {
                    return(King | WK | HasNoCastling);
                }
                if (cells.IsSquareAttackedByBlack(S.E1))
                {
                    return(King | CastleFromCheck | WK);
                }
                if (cells.IsSquareAttackedByBlack(S.F1))
                {
                    return(King | CastleThroughCheck | WK);
                }
                return(King | WK);
            }
            return(King | DoesNotMoveThisWay);
        }
Ejemplo n.º 10
0
 static MoveAnnotations ValidateBlackCastlingMove(byte[] cells, int fromSquare, int toSquare, Castlings availableCastlings)
 {
     if (fromSquare != S.E8) return King | DoesNotMoveThisWay;
     switch (toSquare)
     {
         case S.C8: // Queenside
             if (cells[S.D8] != 0 || cells[S.B8] != 0) return King | DoesNotJump | BQ;
             if (cells[S.C8] != 0) return King | Capture | DoesNotCaptureThisWay | BQ;
             if ((availableCastlings & Castlings.BQ) == 0) return King | BQ | HasNoCastling;
             if (cells.IsSquareAttackedByWhite(S.E8)) return King | CastleFromCheck | BQ;
             if (cells.IsSquareAttackedByWhite(S.D8)) return King | CastleThroughCheck | BQ;
             return King | BQ;
         case S.G8: // Kingside
             if (cells[S.F8] != 0) return King | DoesNotJump | BK;
             if (cells[S.G8] != 0) return King | Capture | DoesNotCaptureThisWay | BK;
             if ((availableCastlings & Castlings.BK) == 0) return King | BK | HasNoCastling;
             if (cells.IsSquareAttackedByWhite(S.E8)) return King | CastleFromCheck | BK;
             if (cells.IsSquareAttackedByWhite(S.F8)) return King | CastleThroughCheck | BK;
             return King | BK;
     }
     return King | DoesNotMoveThisWay;
 }
Ejemplo n.º 11
0
 static MoveAnnotations ValidateWhiteCastlingMove(byte[] cells, int fromSquare, int toSquare, Castlings availableCastlings)
 {
     if (fromSquare != S.E1) return King | DoesNotMoveThisWay;
     switch (toSquare)
     {
         case S.C1: // Queenside
             if (cells[S.D1] != 0 || cells[S.B1] != 0) return King | DoesNotJump | WQ;
             if (cells[S.C1] != 0) return King | Capture | DoesNotCaptureThisWay | WQ;
             if ((availableCastlings & Castlings.WQ) == 0) return King | WQ | HasNoCastling;
             if (cells.IsSquareAttackedByBlack(S.E1)) return King | CastleFromCheck | WQ;
             if (cells.IsSquareAttackedByBlack(S.D1)) return King | CastleThroughCheck | WQ;
             return King | WQ;
         case S.G1: // Kingside
             if (cells[S.F1] != 0) return King | DoesNotJump | WK;
             if (cells[S.G1] != 0) return King | Capture | DoesNotCaptureThisWay | WK;
             if ((availableCastlings & Castlings.WK) == 0) return King | WK | HasNoCastling;
             if (cells.IsSquareAttackedByBlack(S.E1)) return King | CastleFromCheck | WK;
             if (cells.IsSquareAttackedByBlack(S.F1)) return King | CastleThroughCheck | WK;
             return King | WK;
     }
     return King | DoesNotMoveThisWay;
 }
Ejemplo n.º 12
0
        private static MoveAnnotations ValidateMove(byte[] cells, Piece piece, int fromSquare, int toSquare, Piece capture, Castlings availableCastlings)
        {
            switch (piece)
            {
            case Piece.WhitePawn:
                return(ValidateWhitePawnMove(cells, fromSquare, toSquare, capture));

            case Piece.WhiteBishop:
                return(ValidateWhiteBishopMove(cells, fromSquare, toSquare));

            case Piece.WhiteKnight:
                return(ValidateWhiteKnightMove(fromSquare, toSquare));

            case Piece.WhiteRook:
                return(ValidateWhiteRookMove(cells, fromSquare, toSquare));

            case Piece.WhiteQueen:
                return(ValidateWhiteQueenMove(cells, fromSquare, toSquare));

            case Piece.WhiteKing:
                if (ValidateWhiteKingMove(fromSquare, toSquare) == King)
                {
                    return(King);
                }
                return(ValidateWhiteCastlingMove(cells, fromSquare, toSquare, availableCastlings));

            case Piece.BlackPawn:
                return(ValidateBlackPawnMove(cells, fromSquare, toSquare, capture));

            case Piece.BlackBishop:
                return(ValidateBlackBishopMove(cells, fromSquare, toSquare));

            case Piece.BlackKnight:
                return(ValidateBlackKnightMove(fromSquare, toSquare));

            case Piece.BlackRook:
                return(ValidateBlackRookMove(cells, fromSquare, toSquare));

            case Piece.BlackQueen:
                return(ValidateBlackQueenMove(cells, fromSquare, toSquare));

            case Piece.BlackKing:
                if (ValidateBlackKingMove(fromSquare, toSquare) == King)
                {
                    return(King);
                }
                return(ValidateBlackCastlingMove(cells, fromSquare, toSquare, availableCastlings));

            default: throw new System.InvalidOperationException("Unknown piece: " + piece);
            }
        }