コード例 #1
0
ファイル: UciClient.cs プロジェクト: NicolaiSorensen/Cosette
        private void OnSearchUpdate(object sender, SearchStatistics stats)
        {
            var score = FormatScore(stats.Score);
            var principalVariation = FormatPrincipalVariation(stats.PrincipalVariation, stats.PrincipalVariationMovesCount);

            Send($"info depth {stats.Depth} seldepth {stats.SelectiveDepth} time {stats.SearchTime} " +
                 $"score {score} nodes {stats.TotalNodes} nps {stats.TotalNodesPerSecond} pv {principalVariation}");

            if (_debugMode)
            {
                var evaluationStatistics = new EvaluationStatistics();
                var openingPhase         = stats.Board.GetPhaseRatio();
                var endingPhase          = BoardConstants.PhaseResolution - openingPhase;

                var fieldsAttackedByWhite = 0ul;
                var fieldsAttackedByBlack = 0ul;

                var materialEvaluation      = MaterialEvaluator.Evaluate(stats.Board);
                var castlingEvaluation      = CastlingEvaluator.Evaluate(stats.Board, openingPhase, endingPhase);
                var positionEvaluation      = PositionEvaluator.Evaluate(stats.Board, openingPhase, endingPhase);
                var pawnStructureEvaluation = PawnStructureEvaluator.Evaluate(stats.Board, evaluationStatistics, openingPhase, endingPhase);
                var mobility   = MobilityEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack);
                var kingSafety = KingSafetyEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack);
                var pieces     = PiecesEvaluator.Evaluate(stats.Board, openingPhase, endingPhase);
                var fianchetto = FianchettoEvaluator.Evaluate(stats.Board, openingPhase, endingPhase);

                var total = materialEvaluation + castlingEvaluation + positionEvaluation + pawnStructureEvaluation +
                            mobility + kingSafety + pieces;

                Send($"info string evaluation {total} phase {openingPhase} material {materialEvaluation} castling {castlingEvaluation} " +
                     $"position {positionEvaluation} pawns {pawnStructureEvaluation} mobility {mobility} ksafety {kingSafety} " +
                     $"pieces {pieces} fianchetto {fianchetto} irrmoves {stats.Board.IrreversibleMovesCount}");
            }
        }
コード例 #2
0
        public void Run(params string[] parameters)
        {
            var fen                  = string.Join(' ', parameters);
            var boardState           = FenToBoard.Parse(fen);
            var evaluationStatistics = new EvaluationStatistics();

            var openingPhase = boardState.GetPhaseRatio();
            var endingPhase  = BoardConstants.PhaseResolution - openingPhase;

            var fieldsAttackedByWhite = 0ul;
            var fieldsAttackedByBlack = 0ul;

            var materialEvaluation      = MaterialEvaluator.Evaluate(boardState);
            var castlingEvaluation      = CastlingEvaluator.Evaluate(boardState, openingPhase, endingPhase);
            var positionEvaluation      = PositionEvaluator.Evaluate(boardState, openingPhase, endingPhase);
            var pawnStructureEvaluation = PawnStructureEvaluator.Evaluate(boardState, evaluationStatistics, openingPhase, endingPhase);
            var mobility   = MobilityEvaluator.Evaluate(boardState, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack);
            var kingSafety = KingSafetyEvaluator.Evaluate(boardState, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack);
            var pieces     = PiecesEvaluator.Evaluate(boardState, openingPhase, endingPhase);
            var fianchetto = FianchettoEvaluator.Evaluate(boardState, openingPhase, endingPhase);

            var total = materialEvaluation + castlingEvaluation + positionEvaluation + pawnStructureEvaluation +
                        mobility + kingSafety + pieces + fianchetto;

            _interactiveConsole.WriteLine($"Evaluation for board with hash {boardState.Hash} (phase {openingPhase}, " +
                                          $"{boardState.IrreversibleMovesCount} irreversible moves)");

            _interactiveConsole.WriteLine($" = Material: {materialEvaluation}");
            _interactiveConsole.WriteLine($" = Castling: {castlingEvaluation}");
            _interactiveConsole.WriteLine($" = Position: {positionEvaluation}");
            _interactiveConsole.WriteLine($" = Pawns: {pawnStructureEvaluation}");
            _interactiveConsole.WriteLine($" = Mobility: {mobility}");
            _interactiveConsole.WriteLine($" = King safety: {kingSafety}");
            _interactiveConsole.WriteLine($" = Pieces evaluation: {pieces}");
            _interactiveConsole.WriteLine($" = Fianchetto evaluation: {fianchetto}");
            _interactiveConsole.WriteLine();
            _interactiveConsole.WriteLine($" = Total: {total}");
        }
コード例 #3
0
ファイル: Evaluation.cs プロジェクト: NicolaiSorensen/Cosette
        public static int Evaluate(BoardState board, EvaluationStatistics statistics)
        {
            var openingPhase = board.GetPhaseRatio();
            var endingPhase  = BoardConstants.PhaseResolution - openingPhase;

            var result = MaterialEvaluator.Evaluate(board);

            result += PositionEvaluator.Evaluate(board, openingPhase, endingPhase);
            result += PawnStructureEvaluator.Evaluate(board, statistics, openingPhase, endingPhase);

            if (endingPhase != BoardConstants.PhaseResolution)
            {
                var fieldsAttackedByWhite = 0ul;
                var fieldsAttackedByBlack = 0ul;

                result += MobilityEvaluator.Evaluate(board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack);
                result += KingSafetyEvaluator.Evaluate(board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack);
                result += CastlingEvaluator.Evaluate(board, openingPhase, endingPhase);
                result += FianchettoEvaluator.Evaluate(board, openingPhase, endingPhase);
                result += PiecesEvaluator.Evaluate(board, openingPhase, endingPhase);
            }

            return(board.ColorToMove == Color.White ? result : -result);
        }