示例#1
0
        void OutputUCIInfo(MCTSManager manager, MCTSNode searchRootNode, bool isFinalInfo = false)
        {
            BestMoveInfo best = searchRootNode.BestMoveInfo(false);

            if (numPV == 1)
            {
                UCIWriteLine(UCIInfo.UCIInfoString(manager, searchRootNode, best?.BestMoveNode,
                                                   showWDL: showWDL, scoreAsQ: scoreAsQ));
            }
            else
            {
                // Send top move
                UCIWriteLine(UCIInfo.UCIInfoString(manager, searchRootNode, best.BestMoveNode, 1,
                                                   showWDL: showWDL, useParentN: !perPVCounters, scoreAsQ: scoreAsQ));

                // Send other moves visited
                MCTSNode[] sortedN      = searchRootNode.ChildrenSorted(s => - (float)s.N);
                int        multiPVIndex = 2;
                for (int i = 0; i < sortedN.Length && i < numPV; i++)
                {
                    if (!object.ReferenceEquals(sortedN[i], best.BestMoveNode))
                    {
                        UCIWriteLine(UCIInfo.UCIInfoString(manager, searchRootNode, sortedN[i], multiPVIndex,
                                                           showWDL: showWDL, useParentN: !perPVCounters, scoreAsQ: scoreAsQ));
                        multiPVIndex++;
                    }
                }

                // Finally show moves that had no visits
                float  elapsedTimeSeconds = (float)(DateTime.Now - manager.StartTimeThisSearch).TotalSeconds;
                string timeStr            = $"{ elapsedTimeSeconds * 1000.0f:F0}";
                for (int i = multiPVIndex - 1; i < searchRootNode.NumPolicyMoves; i++)
                {
                    (MCTSNode node, EncodedMove move, FP16 p)info = searchRootNode.ChildAtIndexInfo(i);
                    if (info.node == null)
                    {
                        bool        isWhite = searchRootNode.Annotation.Pos.MiscInfo.SideToMove == SideType.White;
                        EncodedMove moveCorrectPerspective = isWhite ? info.move : info.move.Flipped;
                        string      str = $"info depth 0 seldepth 0 time { timeStr } nodes 1 score cp 0 tbhits 0 "
                                          + $"multipv {multiPVIndex} pv {moveCorrectPerspective.AlgebraicStr} ";
                        UCIWriteLine(str);
                        multiPVIndex++;
                    }
                }
            }
            if (verboseMoveStats && (logLiveStats || isFinalInfo))
            {
                OutputVerboseMoveStats(CeresEngine.Search.SearchRootNode);
            }
        }
示例#2
0
        public static MGMove ToMGMove(MGPosition mgPos, EncodedMove encodedMove)
        {
            MGMoveList movesLegal = new MGMoveList();

            MGMoveGen.GenerateMoves(in mgPos, movesLegal);

            int indexLegalMove = MoveInMGMovesArrayLocator.FindMoveInMGMoves(in mgPos, movesLegal.MovesArray, encodedMove, 0, movesLegal.NumMovesUsed, mgPos.BlackToMove);

            if (indexLegalMove == -1)
            {
                throw new Exception($"Move not found {encodedMove}");
            }
            return(movesLegal.MovesArray[indexLegalMove]);
            //  Move move = MGMoveConverter.ToMove(theMove);
        }
示例#3
0
        // Version
        // V4_STRUCT_STRING = '4s7432s832sBBBBBBBbffff'
        // V3_STRUCT_STRING = '4s7432s832sBBBBBBBb'


        /// <summary>
        /// Dumps information about the training position to the Console.
        /// </summary>
        public unsafe void Dump()
        {
            Console.WriteLine("\r\nEncodedTrainingPosition");
            Console.WriteLine("We are " + (Position.MiscInfo.InfoPosition.SideToMove == 0 ? "White" : "Black") + " result our perspective: " + Position.MiscInfo.InfoTraining.ResultFromOurPerspective);
            Console.WriteLine("Relative points us " + Position.GetPlanesForHistoryBoard(0).RelativePointsUs);
            for (int i = 0; i < 8; i++)
            {
                Console.WriteLine("History " + i + " " + Position.FENForHistoryBoard(i));
            }
            for (int i = 0; i < EncodedPolicyVector.POLICY_VECTOR_LENGTH; i++)
            {
                if (Policies.Probabilities[i] != 0 && !float.IsNaN(Policies.Probabilities[i]))
                {
                    bool        isPawnMove = false; // TO DO: fill in
                    bool        isKingMove = false; // TO DO: fill in
                    EncodedMove lm         = EncodedMove.FromNeuralNetIndex(i, isPawnMove, isKingMove);
                }
            }
        }
示例#4
0
        internal void ApplySearchMoves()
        {
            // This is intended to be called only once, immediately after the root is evaluated.
            Debug.Assert(Context.Root.N == 1 && !haveAppliedSearchMoves);

            if (SearchMoves != null)
            {
                if (Context.RootMovesPruningStatus == null)
                {
                    Context.RootMovesPruningStatus = new MCTSFutilityPruningStatus[Root.NumPolicyMoves];
                }

                // Start by assuming all are pruned.
                Array.Fill(Context.RootMovesPruningStatus, MCTSFutilityPruningStatus.PrunedDueToSearchMoves);

                // Specifically un-prune any which are specified as valid search moves.
                foreach (Move move in SearchMoves)
                {
                    bool found = false;
                    for (int i = 0; i < Root.NumPolicyMoves; i++)
                    {
                        EncodedMove moveEncoded = Root.ChildAtIndexInfo(i).move;
                        if (move.ToString().ToLower() == moveEncoded.AlgebraicStr)
                        {
                            Context.RootMovesPruningStatus[i] = MCTSFutilityPruningStatus.NotPruned;
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        throw new Exception($"Specified search move not found {move}");
                    }
                }
            }
            haveAppliedSearchMoves = true;
        }
示例#5
0
 public static MGMove ToMGMove(Position position, EncodedMove encodedMove) => ToMGMove(MGPosition.FromPosition(position), encodedMove);