Exemplo n.º 1
0
        /// <summary>
        /// Add the current packed board to the history
        /// </summary>
        /// <param name="l64ZobristKey">            Zobrist key of the board</param>
        /// <param name="bPawnMoveOrPieceEaten">    true if a pawn has moved or a piece has been eaten</param>
        /// <returns>
        /// Result: NoRepeat, ThreeFoldRepeat or FiftyRuleRepeat
        /// </returns>
        public ChessBoard.RepeatResultE AddCurrentPackedBoard(long l64ZobristKey, bool bPawnMoveOrPieceEaten)
        {
            ChessBoard.RepeatResultE eRetVal = ChessBoard.RepeatResultE.NoRepeat;
            int  iHashIndex;
            int  iNewArraySize;
            byte count;

            PackedBoard[] arrNew;

            l64ZobristKey ^= (int)m_packedBoardCurrent.m_eInfo;
            if (m_iMoveCount >= m_iPackedBoardArraySize)
            {
                iNewArraySize = m_iPackedBoardArraySize * 2;
                arrNew        = new PackedBoard[iNewArraySize];
                Array.Copy(m_arrPackedBoard, arrNew, m_iPackedBoardArraySize);
                m_iPackedBoardArraySize = iNewArraySize;
            }
            iHashIndex = (int)(l64ZobristKey & 16383);
            count      = ++m_arrHashCount[iHashIndex];
            m_arrHashCount[iHashIndex] = count;
            if (bPawnMoveOrPieceEaten)
            {
                m_iCountMoveDepth++;
                m_arrCountMove[m_iCountMoveDepth] = 0;
            }
            else
            {
                if (++m_arrCountMove[m_iCountMoveDepth] >= 50)
                {
                    eRetVal = ChessBoard.RepeatResultE.FiftyRuleRepeat;
                }
                else
                {
                    // A count > 2 is only an indication that 3 or more identical board may exist
                    // because 2 non-identical board can share the same slot
                    if (count > 2 && GetBoardCount(m_packedBoardCurrent) >= 2)
                    {
                        eRetVal = ChessBoard.RepeatResultE.ThreeFoldRepeat;
                    }
                }
            }
            m_arrPackedBoard[m_iMoveCount++] = m_packedBoardCurrent;
            return(eRetVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the current packed board to the history
        /// </summary>
        /// <param name="l64ZobristKey">    Zobrist key of the board</param>
        /// <returns>
        /// Result: NoRepeat, ThreeFoldRepeat or FiftyRuleRepeat
        /// </returns>
        public ChessBoard.RepeatResultE CurrentRepeatResult(long l64ZobristKey)
        {
            ChessBoard.RepeatResultE eRetVal = ChessBoard.RepeatResultE.NoRepeat;
            int  iHashIndex;
            byte count;

            iHashIndex = (int)(l64ZobristKey & 16383);
            count      = m_arrHashCount[iHashIndex];
            if (m_arrCountMove[m_iCountMoveDepth] >= 50)
            {
                eRetVal = ChessBoard.RepeatResultE.FiftyRuleRepeat;
            }
            else
            {
                // A count > 2 is only an indication that 3 or more identical board may exist
                // because 2 non-identical board can share the same slot
                if (count > 2 && GetBoardCount(m_packedBoardCurrent) >= 2)
                {
                    eRetVal = ChessBoard.RepeatResultE.ThreeFoldRepeat;
                }
            }
            return(eRetVal);
        }