示例#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);
                }
            }
        }
示例#2
0
        private void GenerateQuietMoves(MoveList moves)
        {
            var currentSide = _position.State.SideToMove;
            var up          = currentSide == PlayerExtensions.White ? EDirection.North : EDirection.South;
            var notOccupied = ~_position.Pieces();
            var pushed      = (_position.Pieces(EPieceType.Pawn, currentSide) & ~currentSide.Rank7()).Shift(up) & notOccupied;

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

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

            AddMoves(moves, notOccupied);

            if (_position.InCheck)
            {
                return;
            }

            for (var castleType = ECastleling.Short; castleType < ECastleling.CastleNb; castleType++)
            {
                if (_position.CanCastle(castleType))
                {
                    AddCastleMove(moves, _position.GetKingCastleFrom(currentSide, castleType), castleType.GetKingCastleTo(currentSide));
                }
            }
        }
示例#3
0
        private string ValidateCastleling(string error)
        {
            Span <Player>           players = stackalloc Player[] { Player.White, Player.Black };
            Span <CastlelingRights> crs     = stackalloc CastlelingRights[] { CastlelingRights.None, CastlelingRights.None };

            foreach (var c in players)
            {
                crs[0] = CastlelingRights.KingSide.MakeCastlelingRights(c);
                crs[1] = CastlelingRights.QueenSide.MakeCastlelingRights(c);

                var ourRook = PieceTypes.Rook.MakePiece(c);
                foreach (var cr in crs)
                {
                    if (!_pos.CanCastle(cr))
                    {
                        continue;
                    }

                    var rookSq = _pos.CastlingRookSquare(cr);

                    if (_board.PieceAt(rookSq) != ourRook)
                    {
                        error = AddError(error, $"rook does not appear on its position for {c}");
                    }

                    if (_pos.GetCastlelingRightsMask(rookSq) != cr)
                    {
                        error = AddError(error, $"castleling rights mask at {rookSq} does not match for player {c}");
                    }

                    if ((_pos.GetCastlelingRightsMask(_pos.GetKingSquare(c).AsInt()) & cr) != cr)
                    {
                        error = AddError(error, $"castleling rights mask at {_pos.GetKingSquare(c)} does not match for player {c}");
                    }
                }
            }

            return(error);
        }