Пример #1
0
 public TranspositionTableEntry(TranspositionTableEntry copy)
 {
     if (null == copy)
     {
         return;
     }
     this.Value = copy.Value;
     this.Lock  = copy.Lock;
 }
Пример #2
0
        public void Store(ulong hashKey, Move m, int depth, int score, TranspositionTableEntry.EntryType type)
        {
            Stores++;
            var index    = HashFunction(hashKey);
            var existing = TTable[index];

            var newEntry = new TranspositionTableEntry {
                Type  = (byte)type,
                Score = (Int16)score,
                Depth = depth,
                Age   = SearchId
            };

            if (m != null)
            {
                newEntry.MoveValue = m.Value;
            }

            newEntry.Lock = newEntry.Value ^ hashKey;

            //we will always store the entry in the second bucket
            TTable[index + 1] = new TranspositionTableEntry(newEntry);

            //check that a result is already present at this index, and decide if we should replace
            //if it matches the current position, go ahead and overwrite.  If the
            //existing entry had been useful, we would not be here.

            //this block decides to keep the existing entry
            if (existing != null && existing.Lock != newEntry.Lock)
            {
                // replacement strategy is as follows:
                //  prefer deeper results
                //  but we can't keep results around forever just because they are deep
                //  so we will remember the search (by age) and replace old data first

                if (existing.Age == newEntry.Age)
                {
                    if (existing.Depth > depth)
                    {
                        return; //the entry that's already here is better and new
                    }
                }
            }

            TTable[index] = newEntry;
        }
Пример #3
0
        int OrderMove(Move m, TranspositionTableEntry entry)
        {
            if (entry != null)
            {
                if (m.Value == entry.MoveValue)
                {
                    return(int.MaxValue);// search this move first
                }
            }

            if ((m.Bits & (byte)MoveBits.Capture) > 0)
            {
                //winning and even captures
                if (Evaluator.PieceValueOnSquare(MyBoard, m.To) >= Evaluator.PieceValues[(int)Move.GetPiece((MoveBits)m.Bits)])
                {
                    return(LvaMvv(m));
                }
                else
                {
                    //verify that it is actually losing with SEE
                    if (StaticExchange.Eval(MyBoard, m, MyBoard.SideToMove) >= 0)
                    {
                        return(LvaMvv(m));
                    }
                    return(int.MinValue + LvaMvv(m));//losing captures at the bottom
                }
            }
            else
            {
                //these happen before losing captures
                if (Killers[Ply, 0] != null && Killers[Ply, 0].Value == m.Value)
                {
                    return(2);
                }
                else if (Killers[Ply, 1] != null && Killers[Ply, 1].Value == m.Value)
                {
                    return(1);
                }
            }

            return(0);
        }
Пример #4
0
        void SearchFailHigh(Move m, int score, int depth, TranspositionTableEntry entry)
        {
            UpdateKillers(m, depth);
            Metrics.FailHigh++;

            if (entry != null && entry.MoveValue == m.Value)
            {
                Metrics.TTFailHigh++;
            }

            else if ((Killers[Ply, 0] != null && m.Value == Killers[Ply, 0].Value) ||
                     (Killers[Ply, 1] != null && m.Value == Killers[Ply, 1].Value))
            {
                Metrics.KillerFailHigh++;
            }

            //update the transposition table
            //the move doesn't matter if it is a CUT node
            TranspositionTable.Instance.Store(
                MyBoard.HashKey, m, depth, score, TranspositionTableEntry.EntryType.CUT);
        }