示例#1
0
        private static EMoveAmbiguity Ambiguity(this Move move, BitBoard similarTypeAttacks, IPosition position)
        {
            var ambiguity = EMoveAmbiguity.None;

            foreach (var square in similarTypeAttacks)
            {
                var pinned = position.GetPinnedPieces(square, move.GetMovingSide());

                if (similarTypeAttacks & pinned)
                {
                    continue;
                }

                if (move.GetMovingPieceType() != position.GetPieceType(square))
                {
                    continue;
                }

                if (position.OccupiedBySide[move.GetMovingSide().Side] & square)
                {
                    if (square.File() == move.GetFromSquare().File())
                    {
                        ambiguity |= EMoveAmbiguity.File;
                    }
                    else if (square.Rank() == move.GetFromSquare().Rank())
                    {
                        ambiguity |= EMoveAmbiguity.Rank;
                    }

                    ambiguity |= EMoveAmbiguity.Move;
                }
            }

            return(ambiguity);
        }
示例#2
0
        private static BitBoard GetSimilarAttacks(this IPosition position, Move move)
        {
            var pt = move.GetMovingPieceType();

            return(pt == EPieceType.Pawn || pt == EPieceType.King
                ? BitBoards.ZeroBb
                : move.GetToSquare().GetAttacks(pt, position.Pieces()) ^ move.GetFromSquare());
        }
示例#3
0
        private static string ToRan(Move move, IPosition pos)
        {
            var from = move.GetFromSquare();
            var to   = move.GetToSquare();

            var notation = new StringBuilder(12);

            if (move.IsCastlelingMove())
            {
                notation.Append(ECastlelingExtensions.GetCastlelingString(to, from));
            }
            else
            {
                var pt = move.GetMovingPieceType();

                if (pt != EPieceType.Pawn)
                {
                    notation.Append(pt.GetPieceChar());
                }

                notation.Append(from.ToString());

                if (move.IsEnPassantMove())
                {
                    notation.Append("ep");
                    notation.Append(from.FileChar());
                }
                else if (move.IsCaptureMove())
                {
                    if (pt == EPieceType.Pawn)
                    {
                        notation.Append(from.FileChar());
                    }

                    notation.Append('x');
                    notation.Append(move.GetCapturedPiece().Type().GetPieceChar());
                }
                else
                {
                    notation.Append('-');
                }

                notation.Append(to.ToString());

                if (move.IsPromotionMove())
                {
                    notation.Append('=');
                    notation.Append(move.GetPromotedPiece().GetUnicodeChar());
                }
            }

            if (pos.InCheck)
            {
                notation.Append(pos.GetCheckChar());
            }

            return(notation.ToString());
        }
示例#4
0
        public static (bool, Move) Locate(this Move move, IPosition pos)
        {
            // force position to contain the latest moves for the position moves to be searched in
            var moveList = pos.GenerateMoves();

            var element = moveList.GetMove(move.GetFromSquare(), move.GetToSquare());

            return(element == null ? (false, EmptyMove) : (true, element));
        }
示例#5
0
        public static (bool, Move) Locate(this Move move, IPosition pos)
        {
            // force position to contain the latest moves for the position moves to be searched in
            var mg = new MoveGenerator(pos);

            mg.GenerateMoves();

            var element = mg.Moves.FirstOrDefault(x => x.GetFromSquare() == move.GetFromSquare() && x.GetToSquare() == move.GetToSquare());

            return(element == null ? (false, EmptyMove) : (true, element));
        }
示例#6
0
        private static string ToSan(this Move move, MoveGenerator moveGenerator)
        {
            var from = move.GetFromSquare();
            var to   = move.GetToSquare();

            var notation = new StringBuilder(12);

            if (move.IsCastlelingMove())
            {
                notation.Append(ECastlelingExtensions.GetCastlelingString(to, from));
            }
            else
            {
                var pt = move.GetMovingPieceType();

                if (pt != EPieceType.Pawn)
                {
                    notation.Append(move.GetMovingPiece().GetPgnChar());
                    move.Disambiguation(from, moveGenerator.Position, notation);
                }

                if (move.IsEnPassantMove())
                {
                    notation.Append("ep");
                    notation.Append(from.FileChar());
                }
                else if (move.IsCaptureMove())
                {
                    if (pt == EPieceType.Pawn)
                    {
                        notation.Append(from.FileChar());
                    }

                    notation.Append('x');
                }

                notation.Append(to.ToString());

                if (move.IsPromotionMove())
                {
                    notation.Append('=');
                    notation.Append(move.GetPromotedPiece().GetPgnChar());
                }
            }

            if (moveGenerator.InCheck)
            {
                notation.Append(moveGenerator.GetCheckChar());
            }

            return(notation.ToString());
        }
示例#7
0
        public static (bool, Move) Locate(this Move move, Game game)
        {
            // force position to contain the latest moves for the position moves to be searched in
            game.State.GenerateMoves();

            var element = game.State.Moves.FirstOrDefault(x => x.GetFromSquare() == move.GetFromSquare() && x.GetToSquare() == move.GetToSquare());

            return(element == null ? (false, EmptyMove) : (true, element));

            //for (int i = 0; i < game.State.Moves.Count; i++) {
            //    if (move.GetFromSquare() == game.State.Moves[i].GetFromSquare() && move.GetToSquare() == game.State.Moves[i].GetToSquare())
            //        return (true, game.State.Moves[i]);
            //}

            //return (false, EmptyMove);
        }