Computer Chess Club Archives


Search

Terms

Messages

Subject: Found another small bug in TSCP

Author: Michel Langeveld

Date: 12:24:24 01/15/04


Just for sharing

Fixing the bug saves a bit in quiet positions where history heuristic is more
important. I take the original TSCP 1.81 search again to explain the bug. The
bug is caused that the wrong number of plies is added to the history heurstic if
we talk about a check.

I will publish my heavily modified TSCP when it is totally done :-)

/* search() does just that, in negamax fashion */

int search(int alpha, int beta, int depth)
{
	int i, j, x;
	BOOL c, f;

	/* we're as deep as we want to be; call quiesce() to get
	   a reasonable score and return it. */
	if (!depth)
		return quiesce(alpha,beta);
	++nodes;

	/* do some housekeeping every 1024 nodes */
	if ((nodes & 1023) == 0)
		checkup();

	pv_length[ply] = ply;

	/* if this isn't the root of the search tree (where we have
	   to pick a move and can't simply return 0) then check to
	   see if the position is a repeat. if so, we can assume that
	   this line is a draw and return 0. */
	if (ply && reps())
		return 0;

	/* are we too deep? */
	if (ply >= MAX_PLY - 1)
		return eval();
	if (hply >= HIST_STACK - 1)
		return eval();

	/* are we in check? if so, we want to search deeper */
	c = in_check(side);
	if (c)
		++depth;
	gen();
	if (follow_pv)  /* are we following the PV? */
		sort_pv();
	f = FALSE;

	/* loop through the moves */
	for (i = first_move[ply]; i < first_move[ply + 1]; ++i) {
		sort(i);
		if (!makemove(gen_dat[i].m.b))
			continue;
		f = TRUE;
		x = -search(-beta, -alpha, depth - 1);
		takeback();
		if (x > alpha) {

			/* this move caused a cutoff, so increase the history
			   value so it gets ordered high next time we can
			   search it */
			//history[(int)gen_dat[i].m.b.from][(int)gen_dat[i].m.b.to] += depth;

                        ************************************************
                        //we have to subtract depth

history[(int)gen_dat[i].m.b.from][(int)gen_dat[i].m.b.to] += (depth - c);
                        ************************************************

			if (x >= beta)
				return beta;
			alpha = x;

			/* update the PV */
			pv[ply][ply] = gen_dat[i].m;
			for (j = ply + 1; j < pv_length[ply + 1]; ++j)
				pv[ply][j] = pv[ply + 1][j];
			pv_length[ply] = pv_length[ply + 1];
		}
	}

	/* no legal moves? then we're in checkmate or stalemate */
	if (!f) {
		if (c)
			return -10000 + ply;
		else
			return 0;
	}

	/* fifty move draw rule */
	if (fifty >= 100)
		return 0;
	return alpha;
}

starting position:

original:
8   1021   1689903     -9  b1c3 d7d5 i1h3 i8h6 h3f4 d5d4 c3e4 c8f5

fixed:
8   1023   1675730     -9  b1c3 d7d5 i1h3 i8h6 h3f4 d5d4 c3e4 c8f5

tactical position:

original:
7    164    328189  -9990  i3j3 h5h4 d1j7 i8j7 j3i4 c8e8 i4i5 g2i2 i5j5 e8h5
fixed:
7    168    328128  -9990  i3j3 h5h4 d1j7 i8j7 j3i4 c8e8 i4i5 g2i2 i5j5 e8h5



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.