Computer Chess Club Archives


Search

Terms

Messages

Subject: Alpha Beta and Min-Max:

Author: Nicolas Carrasco

Date: 14:53:33 09/23/99


Hey guys,

Here I am posting one AlphaBeta function called "Search" that makes the move of
"AlphaBeta". These two first functions seems to be simialar.

Later I had posted a pair of MIN-MAX functions. I think MIN-MAX functions are
correct, but AlphaBeta. I am sure because it does different move and socore.

The real problem is that teoricaly they must have the same result but I am not
having that case. :(

I tried to do my source code clear as possible.

Thanks!

I use AlphaBeta like this:

///////////////////////////////////////////////////////////////////
int AlphaBeta (int depth, int alpha, int beta);
int Search (int depth, int alpha, int beta);

void main(void)
{
Search(5,-50000,50000);
}

int AlphaBeta (int depth, int alpha, int beta)
{
	int i;
	int value;

	if (depth == 0)
		return eval();
	++ply;

    gen();

    for (i=0; i<move[ply].number;i++) {
        if (make_move(move[ply].b[i])) {
			++nodes;
			value = -AlphaBeta(depth - 1, -beta, -alpha);
			unmake_move();
			if (value >= beta) {
				--ply;
				return value;
			}
			if (value > alpha)
				alpha = value;
		}
    }
	--ply;
    return alpha;
}

int Search (int depth, int alpha, int beta)
{
	int i;
	int value;
	int move_to_make;

	if (depth == 0)
		return eval();
	++ply;

    gen();

    for (i=0; i<move[ply].number;i++) {
        if (make_move(move[ply].b[i])) {
			++nodes;
			value = -AlphaBeta(depth - 1, -beta, -alpha);
			unmake_move();
			if (value >= beta) {
				--ply;
				make_move(move[ply].b[i]);
				return value;
			}
			if (value > alpha) {
				move_to_make = i;
				alpha = value;
			}
		}
    }
	--ply;
    make_move(move[ply].b[move_to_make]);
	return alpha;
}


////////////////////OLD SEARCH FUNCTIONS/////////////////////////
/*
// MIN-MAX

int Search (int depth);
int Examine(int depth);

void main(void)
{
Search(5);
}

int Search(int depth)
{
	int mejor = -120000;
	int actual;
	int i;
	int best_move;

	ply = 0;

	gen();
	for (i=0; i<move[ply].number;i++) {
		if (make_move(move[ply].b[i])) {
			actual = -examine(depth-1);
			unmake_move();
			++nodes;
			if (actual>mejor) {
				mejor = actual;
				best_move = i;
			}
		}
	}
	make_move(move[ply].b[best_move]);
	return mejor;
}

int Examine(int depth)
{
	int actual;
	int mejor = -120000;
	int i;

	if (depth==0) {
		return eval();
		}
	++ply;
	gen();
	for(i=0;i<move[ply].number;i++) {
		if (make_move(move[ply].b[i])) {
			actual = -examine(depth-1);
			unmake_move();
			++nodes;
			if (actual>mejor)
				mejor = actual;
			}
	}
	--ply;
	return mejor;
}
*/




This page took 0 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.