Example #1
0
// the quiescence search
int Quiece(board_t *brd, int alpha, int beta, searchinfo_t *sinfo)
{
	if(!(sinfo->nodes & 0xfff)) CheckUp(sinfo);

	sinfo->nodes++;

	ASSERT(CheckBrd(brd));

	//if((IsRep(brd) || brd->fifty >= 100) && brd->ply) return 0;
	if(brd->ply >= MAXDEPTH-1) return Eval(brd);

	int score = Eval(brd);

	// we are probably not going to make our position worse by moving so we can say:
	if(score >= beta){	// if we are doing already too good
		return beta;	// we have a beta cutoff and we return
	}
	if(score > alpha){	// if we are better than alpha
		alpha = score;	// then we can set our minimum alpha to the score
	}

	mlist_t list;
	int i;
	score = -INFINITE;

	GenCaps(brd, &list);	// Generate all capture moves

	for(i = 0; i < list.len; i++)	// Loop through the moves
	{
		if(sinfo->stop) return 0;

		SelectNextMove(&list, i);

		if(!MakeMove(brd, list.move[i].move)) continue;

		score = -Quiece(brd, -beta, -alpha, sinfo);

		TakeBack(brd);

		if(score > alpha){
			if(score >= beta){
				return beta;
			}
			alpha = score;
		}
	}

	return alpha;
}
Example #2
0
int Quiescent (int alpha, int beta)
{
    int i = 0;
    int movescnt = 0;
    int score = 0;
    int best = 0;
    MOVE qMovesBuf[200];

    countquiesCalls++;
    nodes++;

    /* Do some housekeeping every 1024 nodes */
    if ((nodes & 1023) == 0)
        checkup(stop_time);
    if (must_stop)
        return 0;

    if (reps() >= 2)
        return 0;

    best = Eval(alpha, beta);
    // --- stand pat cutoff?
    if (best > alpha)
        {
            if (best >= beta)
                return best;
            alpha = best;
        }

    /* As we are in qasearch we generate the captures */
    movescnt = GenCaps (side, qMovesBuf);
    countCapCalls++;

#ifdef SEARCH_DEBUG
            if (movescnt > 200) printf("Too much moves!: %d", movescnt);
#endif

    /* Now the alpha-beta search in quiescent */
    for (i = 0; i < movescnt; ++i)
        {
        MoveOrder(i, movescnt, qMovesBuf);

            if (!MakeMove (qMovesBuf[i]))
            {
                /* If the current move isn't legal, we take it back
                 * and take the next move in the list */
                TakeBack ();
                continue;
            }

            score = -Quiescent (-beta, -alpha);
            TakeBack ();

            if ((nodes & 1023) == 0)
                checkup(stop_time);
            if (must_stop)
                return 0;

            if (score >= beta)
                return beta;
            if (score > alpha)
                alpha = score;
        }
#ifdef SEARCH_DEBUG
    if (alpha > MATE) printf("alpha too high: %d", alpha);
    if (alpha < -MATE) printf("alpha too low: %d", alpha);
#endif

    return alpha;
}