示例#1
0
typeMoveList *MyEvasion(typePos *Position, typeMoveList *List, uint64 c2)
{
    uint64 U, T, att, mask;
    int sq, to, fr, c, king, pi;
    king = MyKingSq;
    att = MyKingCheck;
    sq = BSF(att);
    pi = Position->sq[sq];
    mask = (~OppAttacked) &(((pi == EnumOppP) ? AttK[king] : 0) | Evade(king, sq)) & (~MyOccupied) &c2;
    BitClear(sq, att);
    if (att)
    {
        sq = BSF(att);
        pi = Position->sq[sq];
        mask = mask &(PieceIsOppPawn(pi) | Evade(king, sq));
        sq = king;
        AddTo(mask, CaptureValue[EnumMyK][c]);
        List->move = 0;
        return List;
    }
    c2 &= InterPose(king, sq);
    sq = king;
    AddTo(mask, CaptureValue[EnumMyK][c]);
    if (!c2)
    {
        List->move = 0;
        return List;
    }
    if (CaptureRight &(c2 & OppOccupied))
    {
        to = BSF(c2 & OppOccupied);
        c = Position->sq[to];
        if (EighthRank(to))
        {
            Add(List, FlagPromQ | FromLeft(to) | to, (0x20 << 24) + CaptureValue[EnumMyP][c]);
            Add(List, FlagPromN | FromLeft(to) | to, 0);
            Add(List, FlagPromR | FromLeft(to) | to, 0);
            Add(List, FlagPromB | FromLeft(to) | to, 0);
        }
        else
            Add(List, FromLeft(to) | to, CaptureValue[EnumMyP][c]);
    }
    if (CaptureLeft &(c2 & OppOccupied))
    {
        to = BSF(c2 & OppOccupied);
        c = Position->sq[to];
        if (EighthRank(to))
        {
            Add(List, FlagPromQ | FromRight(to) | to, (0x20 << 24) + CaptureValue[EnumMyP][c]);
            Add(List, FlagPromN | FromRight(to) | to, 0);
            Add(List, FlagPromR | FromRight(to) | to, 0);
            Add(List, FlagPromB | FromRight(to) | to, 0);
        }
        else
            Add(List, FromRight(to) | to, CaptureValue[EnumMyP][c]);
    }
    to = Position->Dyn->ep;
    if (to)
    {
        if (CaptureRight & SqSet[to] && SqSet[Backward(to)] & c2)
            Add(List, FlagEP | FromLeft(to) | to, CaptureValue[EnumMyP][EnumOppP]);
        if (CaptureLeft & SqSet[to] && SqSet[Backward(to)] & c2)
            Add(List, FlagEP | FromRight(to) | to, CaptureValue[EnumMyP][EnumOppP]);
    }
    T = BitboardMyP & BackShift((c2 & OppOccupied) ^ c2);
    while (T)
    {
        fr = BSF(T);
        BitClear(fr, T);
        if (SeventhRank(fr))
        {
            Add(List, FlagPromQ | (fr << 6) | Forward(fr), CaptureValue[EnumMyP][0]);
            Add(List, FlagPromN | (fr << 6) | Forward(fr), 0);
            Add(List, FlagPromR | (fr << 6) | Forward(fr), 0);
            Add(List, FlagPromB | (fr << 6) | Forward(fr), 0);
        }
        else
            Add(List, (fr << 6) | Forward(fr), CaptureValue[EnumMyP][0]);
    }
    T = BitboardMyP & BackShift2((c2 & OppOccupied) ^ c2) & SecondRank & BackShift(~Position->OccupiedBW);
    while (T)
    {
        fr = BSF(T);
        BitClear(fr, T);
        Add(List, (fr << 6) | Forward2(fr), CaptureValue[EnumMyP][0]);
    }
    for (U = BitboardMyN; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttN[sq] & c2;
        AddTo(T, CaptureValue[EnumMyN][c]);
    }
    for (U = BitboardMyB; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttB(sq) & c2;
        AddTo(T, CaptureValue[EnumMyBL][c]);
    }
    for (U = BitboardMyR; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttR(sq) & c2;
        AddTo(T, CaptureValue[EnumMyR][c]);
    }
    for (U = BitboardMyQ; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttQ(sq) & c2;
        AddTo(T, CaptureValue[EnumMyQ][c]);
    }
    List->move = 0;
    return List;
}
示例#2
0
typeMoveList *MyQuietChecks(typePos *Position, typeMoveList *List, uint64 mask)
{
    int opks, king, sq, to, fr, pi;
    uint64 U, T, V;
    typeMoveList *list;
    uint32 move;
    uint64 gcm;
    gcm = ~MyXray;
    mask = (~mask) &~MyOccupied;
    ;
    list = List;
    king = OppKingSq;
    list = List;
    for (U = MyXray & MyOccupied; U; BitClear(fr, U))
    {
        fr = BSF(U);
        pi = Position->sq[fr];
        if (pi == EnumMyP)
        {
            if (File(fr) != File(king) && !SeventhRank(fr) && Position->sq[Forward(fr)] == 0)
            {
                (List++)->move = (fr << 6) | Forward(fr);
                if (OnSecondRank(fr) && Position->sq[Forward2(fr)] == 0)
                    (List++)->move = (fr << 6) | Forward2(fr);
            }
            if (CanCaptureRight && Rank(fr) != NumberRank7)
                (List++)->move = (fr << 6) | ForwardRight(fr);
            if (CanCaptureLeft && Rank(fr) != NumberRank7)
                (List++)->move = (fr << 6) | ForwardLeft(fr);
        }
        else if (pi == EnumMyN)
        {
            V = AttN[fr] & mask;
            while (V)
            {
                to = BSF(V);
                (List++)->move = (fr << 6) | to;
                BitClear(to, V);
            }
        }
        else if (pi == EnumMyBL || pi == EnumMyBD)
        {
            V = AttB(fr) & mask;
            while (V)
            {
                to = BSF(V);
                (List++)->move = (fr << 6) | to;
                BitClear(to, V);
            }
        }
        else if (pi == EnumMyR)
        {
            V = AttR(fr) & mask;
            while (V)
            {
                to = BSF(V);
                (List++)->move = (fr << 6) | to;
                BitClear(to, V);
            }
        }
        else if (pi == EnumMyK)
        {
            if (File(fr) == File(king) || Rank(fr) == Rank(king))
                V = AttK[fr] & NonOrtho[king] & mask &(~OppAttacked);
            else
                V = AttK[fr] & NonDiag[king] & mask &(~OppAttacked);
            while (V)
            {
                to = BSF(V);
                (List++)->move = (fr << 6) | to;
                BitClear(to, V);
            }
        }
    }
    opks = OppKingSq;
    T = CaptureLeft &(~BitBoardEighthRank) & mask & OppOccupied & MyAttackedPawns[opks];
    while (T)
    {
        to = BSF(T);
        (List++)->move = FromRight(to) | to;
        BitClear(to, T);
    }
    T = CaptureRight &(~BitBoardEighthRank) & mask & OppOccupied & MyAttackedPawns[opks];
    while (T)
    {
        to = BSF(T);
        (List++)->move = FromLeft(to) | to;
        BitClear(to, T);
    }
    for (U = BitboardMyQ; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttQ(sq) & AttQ(king) & mask;
        while (T)
        {
            to = BSF(T);
            BitClear(to, T);
            if ((OppAttackedPawns[to] & BitboardOppP & gcm) == 0 && (AttN[to] & BitboardOppN & gcm) == 0)
            {
                move = (sq << 6) | to;
                if (MySEE(Position, move))
                    (List++)->move = (sq << 6) | to;
            }
        }
    }
    for (U = BitboardMyR; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttR(sq) & AttR(king) & mask;
        while (T)
        {
            to = BSF(T);
            BitClear(to, T);
            if ((OppAttackedPawns[to] & BitboardOppP & gcm) == 0 && (AttN[to] & BitboardOppN & gcm) == 0)
            {
                move = (sq << 6) | to;
                if (MySEE(Position, move))
                    (List++)->move = (sq << 6) | to;
            }
        }
    }
    for (U = BitboardMyB; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttB(sq) & AttB(king) & mask;
        while (T)
        {
            to = BSF(T);
            BitClear(to, T);
            if ((OppAttackedPawns[to] & BitboardOppP & gcm) == 0)
            {
                move = (sq << 6) | to;
                if (MySEE(Position, move))
                    (List++)->move = (sq << 6) | to;
            }
        }
    }
    for (U = BitboardMyN; U; BitClear(sq, U))
    {
        sq = BSF(U);
        T = AttN[sq] & AttN[king] & mask;
        while (T)
        {
            to = BSF(T);
            BitClear(to, T);
            if ((OppAttackedPawns[to] & BitboardOppP & gcm) == 0)
            {
                move = (sq << 6) | to;
                if (MySEE(Position, move))
                    (List++)->move = (sq << 6) | to;
            }
        }
    }
    if (BitboardOppK & FourthEighthRankNoH && Position->sq[BackRight(opks)] == 0)
    {
        if (Position->sq[BackRight2(opks)] == EnumMyP)
        {
            fr = BackRight2(opks);
            to = BackRight(opks);
            move = (fr << 6) | to;
            if (PawnGuard(to, fr) && MySEE(Position, move))
                (List++)->move = move;
        }
        if (Rank(opks) == NumberRank5 && Position->sq[BackRight2(opks)] == 0
                && Position->sq[BackRight3(opks)] == EnumMyP)
        {
            to = BackRight(opks);
            fr = BackRight3(opks);
            move = (fr << 6) | to;
            if (PawnGuard(to, fr) && MySEE(Position, move))
                (List++)->move = move;
        }
    }
    if (BitboardOppK & FourthEighthRankNoA && Position->sq[BackLeft(opks)] == 0)
    {
        if (Position->sq[BackLeft2(opks)] == EnumMyP)
        {
            fr = BackLeft2(opks);
            to = BackLeft(opks);
            move = (fr << 6) | to;
            if (PawnGuard(to, fr) && MySEE(Position, move))
                (List++)->move = move;
        }
        if (Rank(opks) == NumberRank5 && Position->sq[BackLeft2(opks)] == 0
                && Position->sq[BackLeft3(opks)] == EnumMyP)
        {
            to = BackLeft(opks);
            fr = BackLeft3(opks);
            move = (fr << 6) | to;
            if (PawnGuard(to, fr) && MySEE(Position, move))
                (List++)->move = move;
        }
    }
    List->move = MoveNone;
    return List;
}
示例#3
0
文件: net.hpp 项目: taehoonlee/caffe
 Dtype ForwardBackwardManifold(const vector<Blob<Dtype>* > & bottom) {
   Dtype loss;
   Forward2(bottom, &loss);
   BackwardManifold();
   return loss;
 }