Пример #1
0
        internal static bool probe(Key posKey, ref UInt32 ttePos, out TTEntry entry)
        {
            UInt32 posKey32 = (UInt32)(posKey >> 32);
            UInt32 offset   = (((UInt32)posKey) & sizeMask) << 2;

            for (UInt32 i = offset; i < (Constants.ClusterSize + offset); i++)
            {
                if (entries[i].key == posKey32)
                {
                    ttePos = i;
                    entry  = entries[i];
                    return(true);
                }
            }

            entry = StaticEntry;
            return(false);
        }
Пример #2
0
        // refine_eval() returns the transposition table score if possible, otherwise
        // falls back on static position evaluation.
        static Value refine_eval(TTEntry tte, Value v, Value defaultEval)
        {
            if ((((tte.type() & Bound.BOUND_LOWER) != 0) && v >= defaultEval)
                || (((tte.type() & Bound.BOUND_UPPER) != 0) && v < defaultEval))
                return v;

            return defaultEval;
        }
Пример #3
0
        static bool can_return_tt(TTEntry tte, Depth depth, Value v, Value beta)
        {
            return (tte.depth() >= depth
                      || v >= Math.Max(ValueC.VALUE_MATE_IN_MAX_PLY, beta)
                      || v < Math.Min(ValueC.VALUE_MATED_IN_MAX_PLY, beta))

                  && ((((tte.type() & Bound.BOUND_LOWER) != 0) && v >= beta)
                      || (((tte.type() & Bound.BOUND_UPPER) != 0) && v < beta));
        }
Пример #4
0
        internal static bool probe(ulong key, ref uint ttePos, out TTEntry entry)
        {
            var key32 = (uint)(key >> 32);
            var offset = (((uint)key) & sizeMask) << 2;

            for (var i = offset; i < (Constants.ClusterSize + offset); i++)
            {
                if (table[i].key == key32)
                {
                    ttePos = i;
                    entry = table[i];
                    return true;
                }
            }

            entry = StaticEntry;
            return false;
        }
Пример #5
0
        internal static bool probe(Key posKey, ref UInt32 ttePos, out TTEntry entry)
        {
            UInt32 posKey32 = (UInt32)(posKey >> 32);
            UInt32 offset = (((UInt32)posKey) & sizeMask) << 2;

            for (UInt32 i = offset; i < (Constants.ClusterSize + offset); i++)
            {
                if (entries[i].key == posKey32)
                {
                    ttePos = i;
                    entry = entries[i];
                    return true;
                }
            }

            entry = StaticEntry;
            return false;
        }
Пример #6
0
        /// TranspositionTable::store() writes a new entry containing position key and
        /// valuable information of current position. The lowest order bits of position
        /// key are used to decide on which cluster the position will be placed.
        /// When a new entry is written and there are no empty entries available in cluster,
        /// it replaces the least valuable of entries. A TTEntry t1 is considered to be
        /// more valuable than a TTEntry t2 if t1 is from the current search and t2 is from
        /// a previous search, or if the depth of t1 is bigger than the depth of t2.
        internal static void store(Key posKey, Value v, Bound t, Depth d, Move m, Value statV, Value kingD)
        {
            UInt32 posKey32   = (UInt32)(posKey >> 32); // Use the high 32 bits as key inside the cluster
            UInt32 ttePos     = 0;
            UInt32 replacePos = 0;

            ttePos = replacePos = (((UInt32)posKey) & sizeMask) << 2;

            for (UInt32 i = 0; i < Constants.ClusterSize; i++)
            {
                TTEntry tte = entries[ttePos];

                if ((tte.key == 0) || tte.key == posKey32) // Empty or overwrite old
                {
                    // Preserve any existing ttMove
                    if (m == MoveC.MOVE_NONE)
                    {
                        m = (Move)tte.move16;
                    }

                    entries[ttePos].save(posKey32, v, t, d, m, generation, statV, kingD);
                    return;
                }

                // Implement replace strategy
                //if ((entries[replacePos].generation8 == generation ? 2 : 0) + (tte.generation8 == generation || tte.bound == 3/*Bound.BOUND_EXACT*/ ? -2 : 0) + (tte.depth16 < entries[replacePos].depth16 ? 1 : 0) > 0)
                //{
                //    replacePos = ttePos;
                //}

                if (entries[replacePos].generation8 == generation)
                {
                    // +2
                    if (tte.generation8 == generation || tte.bound == 3 /*Bound.BOUND_EXACT*/)
                    {
                        // 0
                        if (tte.depth16 < entries[replacePos].depth16)
                        {
                            // +1
                            replacePos = ttePos;
                        }
                    }
                    else
                    {
                        // +2
                        replacePos = ttePos;
                    }
                }
                else
                {
                    // 0
                    if ((!(tte.generation8 == generation || tte.bound == 3 /*Bound.BOUND_EXACT*/)) && (tte.depth16 < entries[replacePos].depth16))
                    {
                        // +1
                        replacePos = ttePos;
                    }
                }

                ttePos++;
            }
            entries[replacePos].save(posKey32, v, t, d, m, generation, statV, kingD);
        }