Exemple #1
0
        private static void GenerateQuietMoves(this IPosition pos, MoveList moves, Emgf flags)
        {
            var currentSide = pos.State.SideToMove;
            var up          = currentSide == PlayerExtensions.White ? EDirection.North : EDirection.South;
            var notOccupied = ~pos.Pieces();
            var pushed      = (pos.Pieces(EPieceType.Pawn, currentSide) & ~currentSide.Rank7()).Shift(up) & notOccupied;

            pos.AddPawnMoves(moves, pushed, currentSide.PawnPushDistance(), EMoveType.Quiet, flags);

            pushed &= currentSide.Rank3();
            pos.AddPawnMoves(moves, pushed.Shift(up) & notOccupied, currentSide.PawnDoublePushDistance(), EMoveType.Doublepush, flags);

            pos.AddMoves(moves, notOccupied, flags);

            if (pos.InCheck)
            {
                return;
            }

            for (var castleType = ECastleling.Short; castleType < ECastleling.CastleNb; castleType++)
            {
                if (pos.CanCastle(castleType))
                {
                    pos.AddCastleMove(moves, pos.GetKingCastleFrom(currentSide, castleType), castleType.GetKingCastleTo(currentSide), flags);
                }
            }
        }