예제 #1
0
파일: Move.cs 프로젝트: landon/Chess
        public string ToAlgebraic(Board board, NotationModifiers notationModifier)
        {
            string algebraic;

            if (Modifier == MoveModifiers.KingSideCastle)
            {
                algebraic = "O-O";
            }
            else if (Modifier == MoveModifiers.QueenSideCastle)
            {
                algebraic = "O-O-O";
            }
            else
            {
                string movedPieceName = MovedPieceName(board);

                algebraic = SquareName(ToSquare);
                if (CapturedPiece == Pieces.None)
                {
                    if (!Pieces.IsPawn(MovedPiece))
                    {
                        algebraic = movedPieceName + algebraic;
                    }
                }
                else
                {
                    algebraic = "x" + algebraic;
                    if (Pieces.IsPawn(MovedPiece))
                    {
                        algebraic = FileName(FromSquare) + algebraic;
                    }
                    else
                    {
                        algebraic = movedPieceName + algebraic;
                    }
                }

                if (Modifier == MoveModifiers.EnPassant)
                {
                    // This appended notation doesn't seem to be used by many people.
                    //algebraic += " e.p.";
                }

                if (PromotionPiece != Pieces.None)
                {
                    algebraic += "=" + Pieces.ToFEN(PromotionPiece).ToUpper();
                }
            }

            algebraic += NotationModifierMap[notationModifier];

            return(algebraic);
        }
예제 #2
0
파일: Move.cs 프로젝트: landon/Chess
        string MovedPieceName(Board board)
        {
            string movedPieceName = Pieces.ToFEN(MovedPiece).ToUpper();

            // If we have no board, then we cannot disambiguate.
            if (board == null)
            {
                return(movedPieceName);
            }

            // FIXME_lwr: Add disambiguation code.
            return(movedPieceName);
        }
예제 #3
0
        protected virtual int QuiescenceSearch(int alpha, int beta, int currentPly, Sides currentSide)
        {
            _NodesEvaluated++;

            _PlyInfo[currentPly].PrincipalVariationLength = currentPly;

            if (currentPly >= PlyInfo.MaxPly)
            {
                return(beta);
            }

            int staticScore = _StaticEvaluator.Evaluate(_ScratchBoard, currentSide);

            if (staticScore >= beta)
            {
                return(beta);
            }

            if (staticScore > alpha)
            {
                alpha = staticScore;
            }

            List <Move> moves;

            GenerateQuiescenceMoves(currentPly, currentSide, out moves);

            _PlyInfo[currentPly].Board.CopyFrom(_ScratchBoard);

            foreach (Move move in moves)
            {
                if (move.IsCapture)
                {
                    var value = _StaticEvaluator.PieceValue[Pieces.GetKind(move.CapturedPiece)];
                    if (move.IsPromotion)
                    {
                        value += _StaticEvaluator.PieceValue[Pieces.GetKind(move.PromotionPiece)];
                    }

                    value += _StaticEvaluator.PieceValue[Pieces.Pawn];

                    if (staticScore + value < alpha)
                    {
                        continue;
                    }
                }

                if (_ScratchBoard.MakeMove(move) == MakeMoveResults.UndoMove)
                {
                    UndoMove(currentPly);
                    continue;
                }

                int score = -QuiescenceSearch(-beta, -alpha, currentPly + 1, Board.OtherSide(currentSide));

                UndoMove(currentPly);

                if (score >= beta)
                {
                    return(score);
                }

                if (score > alpha)
                {
                    alpha = score;

                    UpdatePrincipalVariation(move, currentPly);
                }
            }

            return(alpha);
        }