コード例 #1
0
ファイル: egbb.cpp プロジェクト: raimarHD/lcec
bool CBitbases::probe(eval_t& eval, const CBoard& board)
{
    if (loaded())
    {
        int32 player = (board.getSide() == eBlack ? _BLACK : _WHITE);
        int32 piece[MAX_PIECES]  = { _EMPTY, _EMPTY, _EMPTY, _EMPTY, _EMPTY, _EMPTY, _EMPTY, _EMPTY, _EMPTY };
        int32 square[MAX_PIECES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        int32 count = 0;

        bb_t pieces = board.getOccupBits();
        while (pieces)
        {
            EField from = popFirstBit(pieces);
            EPiece type = board.getPiece(from);

            square[count] = from;
            switch (type)
            {
                case eW_P: piece[count] = _WPAWN; break;
                case eW_N: piece[count] = _WKNIGHT; break;
                case eW_B: piece[count] = _WBISHOP; break;
                case eW_R: piece[count] = _WROOK; break;
                case eW_Q: piece[count] = _WQUEEN; break;
                case eW_K: piece[count] = _WKING; break;
                case eB_P: piece[count] = _BPAWN; break;
                case eB_N: piece[count] = _BKNIGHT; break;
                case eB_B: piece[count] = _BBISHOP; break;
                case eB_R: piece[count] = _BROOK; break;
                case eB_Q: piece[count] = _BQUEEN; break;
                case eB_K: piece[count] = _BKING; break;
                case eNP: break;
            }
            ++count;
        }

        eval_t eval_eg = m_lib.probe_egbb(player, piece, square);
        if (eval_eg != NOTFOUND)
        {
            eval = eval_eg;
            ++m_hits;

            return(true);
        }
    }
    return(false);
}
コード例 #2
0
ファイル: egtb.cpp プロジェクト: raimarHD/lcec
bool CTablebases::probe(eval_t& eval, const CBoard& board)
{
    if (loaded())
    {
        int rgiCounters[10];
        for (int32 i = 0; i < 10; ++i)
            rgiCounters[i] = 0;

        const int rgsq_cnt = C_PIECES * 5 + 1;
        square rgsqWhite[rgsq_cnt];
        square rgsqBlack[rgsq_cnt];
        for (int32 i = 0; i < rgsq_cnt; ++i)
            rgsqWhite[i] = rgsqBlack[i] = XX;

        VInitSqCtr(rgiCounters, rgsqWhite, 0, board.getPieceBits(eW_P));
        VInitSqCtr(rgiCounters, rgsqWhite, 1, board.getPieceBits(eW_N));
        VInitSqCtr(rgiCounters, rgsqWhite, 2, board.getPieceBits(eW_B));
        VInitSqCtr(rgiCounters, rgsqWhite, 3, board.getPieceBits(eW_R));
        VInitSqCtr(rgiCounters, rgsqWhite, 4, board.getPieceBits(eW_Q));
        VInitSqCtr(rgiCounters + 5, rgsqBlack, 0, board.getPieceBits(eB_P));
        VInitSqCtr(rgiCounters + 5, rgsqBlack, 1, board.getPieceBits(eB_N));
        VInitSqCtr(rgiCounters + 5, rgsqBlack, 2, board.getPieceBits(eB_B));
        VInitSqCtr(rgiCounters + 5, rgsqBlack, 3, board.getPieceBits(eB_R));
        VInitSqCtr(rgiCounters + 5, rgsqBlack, 4, board.getPieceBits(eB_Q));

        int iTb = IDescFindFromCounters(rgiCounters);
        if (iTb)
        {
            bb_t wk = board.getPieceBits(eW_K);
            while (wk)
                rgsqWhite[C_PIECES * 5] = popFirstBit(wk);

            bb_t bk = board.getPieceBits(eB_K);
            while (bk)
                rgsqBlack[C_PIECES * 5] = popFirstBit(bk);

            color side;
            int fInvert;
            square* psqW;
            square* psqB;
            if (iTb > 0)
            {
                side = eWhite == board.getSide() ? x_colorWhite : x_colorBlack;
                fInvert = 0;
                psqW = rgsqWhite;
                psqB = rgsqBlack;
            }
            else
            {
                side = eWhite == board.getSide() ? x_colorBlack : x_colorWhite;
                fInvert = 1;
                psqW = rgsqBlack;
                psqB = rgsqWhite;
                iTb = -iTb;
            }

            if (FRegisteredFun(iTb, side))
            {
                square sqEnP = eNF != board.getEp() ? board.getEp() : XX;
                INDEX ind = PfnIndCalcFun(iTb, side) (psqW, psqB, sqEnP, fInvert);
                int tbValue = L_TbtProbeTable(iTb, side, ind);
                if (tb_broken != tbValue)
                {
                    if (tbValue > 0)
                        eval = MATE_VALUE + 2 * (-tb_mate_in_1 + tbValue - 1);
                    else
                        if (tbValue < 0)
                            eval = -MATE_VALUE + 2 * (tb_mate_in_1 + tbValue);
                        else
                            eval = DRAW_VALUE;

                    ++m_hits;
                    return (true);
                }
            }
        }
    }
    return(false);
}