当前位置: 首页>>代码示例>>C#>>正文


C# Position.nodes_searched方法代码示例

本文整理汇总了C#中Position.nodes_searched方法的典型用法代码示例。如果您正苦于以下问题:C# Position.nodes_searched方法的具体用法?C# Position.nodes_searched怎么用?C# Position.nodes_searched使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Position的用法示例。


在下文中一共展示了Position.nodes_searched方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: pv

    /// UCI::pv() formats PV information according to the UCI protocol. UCI requires
    /// that all (if any) unsearched PV lines are sent using a previous search score.
    internal static string pv(Position pos, Depth depth, ValueT alpha, ValueT beta)
    {
        var ss = new StringBuilder();
        var elapsed = TimeManagement.elapsed() + 1;
        var multiPV = Math.Min(int.Parse(OptionMap.Instance["MultiPV"].v), Search.RootMoves.Count);
        var selDepth = ThreadPool.threads.Select(th => th.maxPly).Concat(new[] {0}).Max();

        for (var i = 0; i < multiPV; ++i)
        {
            var updated = (i <= Search.PVIdx);

            if (depth == Depth.ONE_PLY && !updated)
            {
                continue;
            }

            var d = updated ? depth : depth - Depth.ONE_PLY;
            var v = updated ? Search.RootMoves[i].score : Search.RootMoves[i].previousScore;

            var tb = Tablebases.RootInTB && Math.Abs(v) < Value.VALUE_MATE - _.MAX_PLY;
            v = tb? Tablebases.Score : v;

            ss.Append($"info depth {d/Depth.ONE_PLY} seldepth {selDepth} multipv {i + 1} score {value(v)}");

            if (!tb && i == Search.PVIdx)
            {
                ss.Append(v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
            }

            ss.Append($" nodes {pos.nodes_searched()} nps {pos.nodes_searched()*1000/elapsed}");

            if (elapsed > 1000) // Earlier makes little sense
                ss.Append($" hashfull {TranspositionTable.hashfull()}");

            ss.Append($" tbhits {Tablebases.Hits} time {elapsed} pv");
            
            foreach (var m in Search.RootMoves[i].pv)
            {
                ss.Append($" {move(m, pos.is_chess960())}");
            }
        }

        return ss.ToString();
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:46,代码来源:UCI.cs

示例2: split


//.........这里部分代码省略.........
    // informed that they have been assigned work. This will cause them to instantly
    // leave their idle loops and call search(). When all threads have returned from
    // search() then split() returns.

    internal void split(
        Position pos,
        StackArrayWrapper ss,
        ValueT alpha,
        ValueT beta,
        ref ValueT bestValue,
        ref MoveT bestMove,
        Depth depth,
        int moveCount,
        MovePicker movePicker,
        NodeType nodeType,
        bool cutNode)
    {
        Debug.Assert(searching);
        Debug.Assert(
            -Value.VALUE_INFINITE < bestValue && bestValue <= alpha && alpha < beta && beta <= Value.VALUE_INFINITE);
        Debug.Assert(depth >= ThreadPool.minimumSplitDepth);
        Debug.Assert(splitPointsSize < _.MAX_SPLITPOINTS_PER_THREAD);

        // Pick and init the next available split point
        var sp = splitPoints[splitPointsSize];

        ThreadHelper.lock_grab(sp.spinLock); // No contention here until we don't increment splitPointsSize

        sp.master = this;
        sp.parentSplitPoint = activeSplitPoint;
        sp.slavesMask = 0;
        sp.slavesMask = (1u << idx);
        sp.depth = depth;
        sp.bestValue = bestValue;
        sp.bestMove = bestMove;
        sp.alpha = alpha;
        sp.beta = beta;
        sp.nodeType = nodeType;
        sp.cutNode = cutNode;
        sp.movePicker = movePicker;
        sp.moveCount = moveCount;
        sp.pos = pos;
        sp.nodes = 0;
        sp.cutoff = false;
        sp.ss = ss;
        sp.allSlavesSearching = true; // Must be set under lock protection

        ++splitPointsSize;
        activeSplitPoint = sp;
        activePosition = null;

        // Try to allocate available threads
        Thread slave;

        while (Bitcount.popcount_Full(sp.slavesMask) < _.MAX_SLAVES_PER_SPLITPOINT
               && (slave = ThreadPool.available_slave(sp)) != null)
        {
            ThreadHelper.lock_grab(slave.spinlock);

            if (slave.can_join(activeSplitPoint))
            {
                activeSplitPoint.slavesMask |= 1u << (slave.idx);
                slave.activeSplitPoint = activeSplitPoint;
                slave.searching = true;
            }

            ThreadHelper.lock_release(slave.spinlock);
        }

        // Everything is set up. The master thread enters the idle loop, from which
        // it will instantly launch a search, because its 'searching' flag is set.
        // The thread will return from the idle loop when all slaves have finished
        // their work at this split point.
        ThreadHelper.lock_release(sp.spinLock);

        base_idle_loop(null); // Force a call to base class idle_loop()

        // In the helpful master concept, a master can help only a sub-tree of its
        // split point and because everything is finished here, it's not possible
        // for the master to be booked.
        Debug.Assert(!searching);
        Debug.Assert(activePosition == null);

        // We have returned from the idle loop, which means that all threads are
        // finished. Note that decreasing splitPointsSize must be done under lock
        // protection to avoid a race with Thread::can_join().
        ThreadHelper.lock_grab(spinlock);

        searching = true;
        --splitPointsSize;
        activeSplitPoint = sp.parentSplitPoint;
        activePosition = pos;

        ThreadHelper.lock_release(spinlock);

        // Split point data cannot be changed now, so no need to lock protect
        pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
        bestMove = Move.Create(sp.bestMove);
        bestValue = Value.Create(sp.bestValue);
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Thread.cs

示例3: base_idle_loop

    internal void base_idle_loop(ManualResetEvent initEvent)
    {
        // Pointer 'this_sp' is not null only if we are called from split(), and not
        // at the thread creation. This means we are the split point's master.
        var this_sp = splitPointsSize > 0 ? activeSplitPoint : null;
        Debug.Assert(this_sp == null || (this_sp.master == this && searching));

        while (!exit && this_sp == null && (this_sp.slavesMask == 0))
        {
            // If this thread has been assigned work, launch a search
            while (searching)
            {
                ThreadHelper.lock_grab(spinlock);

                Debug.Assert(activeSplitPoint != null);
                var sp = activeSplitPoint;

                ThreadHelper.lock_release(spinlock);

                var stack = new StackArrayWrapper(new Stack[_.MAX_PLY + 4]);
                var ss = new StackArrayWrapper(stack.table, 2);
                var pos = new Position(sp.pos, this);

                Array.Copy(sp.ss.table, ss.table, 5);
                ss[ss.current].splitPoint = sp;

                ThreadHelper.lock_grab(sp.spinLock);

                Debug.Assert(activePosition == null);

                activePosition = pos;

                if (sp.nodeType == NodeType.NonPV)
                {
                    //enable call to search
                    //search < NonPV, true > (pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode)
                }

                else if (sp.nodeType == NodeType.PV)
                {
                    //enable call to search
                    //search < PV, true > (pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode)
                }

                else if (sp.nodeType == NodeType.Root)
                {
                    //enable call to search
                    //search < Root, true > (pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
                }

                else
                {
                    Debug.Assert(false);
                }

                Debug.Assert(searching);

                ThreadHelper.lock_grab(spinlock);

                searching = false;
                activePosition = null;

                ThreadHelper.lock_release(spinlock);

                sp.slavesMask &= ~(1UL << idx); //sp.slavesMask.reset(idx);
                sp.allSlavesSearching = false;
                sp.nodes += pos.nodes_searched();

                // After releasing the lock we can't access any SplitPoint related data
                // in a safe way because it could have been released under our feet by
                // the sp master.
                ThreadHelper.lock_release(sp.spinLock);

                // Try to late join to another split point if none of its slaves has
                // already finished.
                SplitPoint bestSp = null;
                var minLevel = int.MaxValue;

                foreach (var th in ThreadPool.threads)
                {
                    var size = th.splitPointsSize; // Local copy
                    sp = size > 0 ? th.splitPoints[size - 1] : null;

                    if (sp != null && sp.allSlavesSearching
                        && Bitcount.popcount_Full(sp.slavesMask) < _.MAX_SLAVES_PER_SPLITPOINT && can_join(sp))
                    {
                        Debug.Assert(this != th);
                        Debug.Assert(!(this_sp != null && Bitcount.popcount_Full(sp.slavesMask) == 0));
                        Debug.Assert(ThreadPool.threads.Count > 2);

                        // Prefer to join to SP with few parents to reduce the probability
                        // that a cut-off occurs above us, and hence we waste our work.
                        var level = 0;
                        for (var p = th.activeSplitPoint; p != null; p = p.parentSplitPoint)
                        {
                            level++;
                        }

                        if (level < minLevel)
                        {
//.........这里部分代码省略.........
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Thread.cs


注:本文中的Position.nodes_searched方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。