Ejemplo n.º 1
0
    // This routine treats a position with en passant captures as one without.
    internal static int probe_dtz_no_ep(Position pos, ref int success)
    {
        int wdl;
        int dtz;

        wdl = GlobalMembersTbprobe.probe_ab(pos, -2, 2, ref success);
        if (success == 0)
        {
            return(0);
        }

        if (wdl == 0)
        {
            return(0);
        }

        if (success == 2)
        {
            return(wdl == 2 ? 1 : 101);
        }

        ExtMove[] stack = Arrays.InitializeWithDefaultInstances <ExtMove>(192);
//C++ TO C# CONVERTER TODO TASK: Pointer arithmetic is detected on this variable, so pointers on this variable are left unchanged:
        ExtMove * moves = new ExtMove();
        ExtMove   end   = null;
        StateInfo st    = new StateInfo();
        CheckInfo ci    = new CheckInfo(pos);

        if (wdl > 0)
        {
            // Generate at least all legal non-capturing pawn moves
            // including non-capturing promotions.
            if (pos.checkers() == 0)
            {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<NON_EVASIONS>(pos, stack);
                end = GlobalMembersMovegen.generate <GenType.NON_EVASIONS>(pos, new ExtMove(stack));
            }
            else
            {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<EVASIONS>(pos, stack);
                end = GlobalMembersMovegen.generate <GenType.EVASIONS>(pos, new ExtMove(stack));
            }

            for (moves = stack; moves < end; moves++)
            {
                Move move = moves.move;
                if (GlobalMembersTypes.type_of(pos.moved_piece(move)) != PieceType.PAWN || pos.capture(move) || !pos.legal(move, ci.pinned))
                {
                    continue;
                }
                pos.do_move(move, st, ci, pos.gives_check(move, ci));
                int v = -GlobalMembersTbprobe.probe_ab(pos, -2, -wdl + 1, ref success);
                pos.undo_move(move);
                if (success == 0)
                {
                    return(0);
                }
                if (v == wdl)
                {
                    return(v == 2 ? 1 : 101);
                }
            }
        }

        dtz = 1 + GlobalMembersTbprobe.probe_dtz_table(pos, wdl, ref success);
        if (success >= 0)
        {
            if ((wdl & 1) != 0)
            {
                dtz += 100;
            }
            return(wdl >= 0 ? dtz : -dtz);
        }

        if (wdl > 0)
        {
            int best = 0xffff;
            for (moves = stack; moves < end; moves++)
            {
                Move move = moves.move;
                if (pos.capture(move) || GlobalMembersTypes.type_of(pos.moved_piece(move)) == PieceType.PAWN || !pos.legal(move, ci.pinned))
                {
                    continue;
                }
                pos.do_move(move, st, ci, pos.gives_check(move, ci));
                int v = -GlobalMembersTbprobe.probe_dtz(pos, ref success);
                pos.undo_move(move);
                if (success == 0)
                {
                    return(0);
                }
                if (v > 0 && v + 1 < best)
                {
                    best = v + 1;
                }
            }
            return(best);
        }
        else
        {
            int best = -1;
            if (pos.checkers() == 0)
            {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<NON_EVASIONS>(pos, stack);
                end = GlobalMembersMovegen.generate <GenType.NON_EVASIONS>(pos, new ExtMove(stack));
            }
            else
            {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<EVASIONS>(pos, stack);
                end = GlobalMembersMovegen.generate <GenType.EVASIONS>(pos, new ExtMove(stack));
            }
            for (moves = stack; moves < end; moves++)
            {
                int  v;
                Move move = moves.move;
                if (!pos.legal(move, ci.pinned))
                {
                    continue;
                }
                pos.do_move(move, st, ci, pos.gives_check(move, ci));
                if (st.rule50 == 0)
                {
                    if (wdl == -2)
                    {
                        v = -1;
                    }
                    else
                    {
                        v = GlobalMembersTbprobe.probe_ab(pos, 1, 2, ref success);
                        v = (v == 2) ? 0 : -101;
                    }
                }
                else
                {
                    v = -GlobalMembersTbprobe.probe_dtz(pos, ref success) - 1;
                }
                pos.undo_move(move);
                if (success == 0)
                {
                    return(0);
                }
                if (v < best)
                {
                    best = v;
                }
            }
            return(best);
        }
    }
Ejemplo n.º 2
0
    internal static int probe_ab(Position pos, int alpha, int beta, ref int success)
    {
        int v;

        ExtMove[] stack = Arrays.InitializeWithDefaultInstances <ExtMove>(64);
        ExtMove   moves;
        ExtMove   end;
        StateInfo st = new StateInfo();

        // Generate (at least) all legal non-ep captures including (under)promotions.
        // It is OK to generate more, as long as they are filtered out below.
        if (pos.checkers() == 0)
        {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<CAPTURES>(pos, stack);
            end = GlobalMembersMovegen.generate <GenType.CAPTURES>(pos, new ExtMove(stack));
            // Since underpromotion captures are not included, we need to add them.
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = add_underprom_caps(pos, stack, end);
            end = GlobalMembersTbprobe.add_underprom_caps(pos, new ExtMove(stack), end);
        }
        else
        {
//C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: end = generate<EVASIONS>(pos, stack);
            end = GlobalMembersMovegen.generate <GenType.EVASIONS>(pos, new ExtMove(stack));
        }

        CheckInfo ci = new CheckInfo(pos);

        for (moves = stack; moves < end; moves++)
        {
            Move capture = moves.move;
            if (!pos.capture(capture) || GlobalMembersTypes.type_of(capture) == MoveType.ENPASSANT || !pos.legal(capture, ci.pinned))
            {
                continue;
            }
            pos.do_move(capture, st, ci, pos.gives_check(capture, ci));
            v = -GlobalMembersTbprobe.probe_ab(pos, -beta, -alpha, ref success);
            pos.undo_move(capture);
            if (success == 0)
            {
                return(0);
            }
            if (v > alpha)
            {
                if (v >= beta)
                {
                    success = 2;
                    return(v);
                }
                alpha = v;
            }
        }

        v = GlobalMembersTbprobe.probe_wdl_table(pos, ref success);
        if (success == 0)
        {
            return(0);
        }
        if (alpha >= v)
        {
            success = 1 + (alpha > 0);
            return(alpha);
        }
        else
        {
            success = 1;
            return(v);
        }
    }