what's wrong with this alpha-beta tree??
From: alessandro (halex2000_at_virgilio.it)
Date: 08/28/04
- Next message: Arthur J. O'Dwyer: "Re: [Q] Text vs Binary Files"
- Previous message: Richard Harter: "Re: Dominance Tree Sorts"
- Next in thread: Thad Smith: "Re: what's wrong with this alpha-beta tree??"
- Reply: Thad Smith: "Re: what's wrong with this alpha-beta tree??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Aug 2004 15:15:16 GMT
Hi, these are the two functions of my alpha-beta tree:
protected int Max(Board b, Board oldb, int alpha, int beta, int depth)
{
int tmp = b.CheckForVictory(); //Check for the end of the game
if(tmp == 1) return 1000; //Max wins
else if(tmp == 2) return -1000; //Min wins
if(depth == 0) return EvaluateGame(b, oldb); // We reached the max tree
depth
Board child = new Board();
for(int x = 0; x < 6; x++)
for(int y = 0; y < 5; y++)
{
if(!b.Verify(x, y, true)) continue; //The move is not valid
child.CopyFrom(b);
child.AddFast(x, y, true);
tmp = Min(child, b, alpha, beta, depth-1); //Recursive call
if(tmp > alpha)
{
alpha = tmp;
_x = x;
_y = y;
}
if(beta < alpha) return beta;
}
return alpha;
}
protected int Min(Board b, Board oldb, int alpha, int beta, int depth)
{
int tmp = b.CheckForVictory(); //Check for the end of the game
if(tmp == 1) return 1000; //Max wins
else if(tmp == 2) return -1000; //Min wins
if(depth == 0) return -EvaluateGame(b, oldb); // We reached the max tree
depth
Board child = new Board();
for(int x = 0; x < 6; x++)
for(int y = 0; y < 5; y++)
{
if(!b.Verify(x, y, true)) continue; //The move is not valid
child.CopyFrom(b);
child.AddFast(x, y, true);
tmp = Max(child, b, alpha, beta, depth-1); //Recursive call
if(tmp < beta)
{
beta = tmp;
_x = x;
_y = y;
}
if(beta < alpha) return alpha;
}
return beta;
}
I call them with the following instruction:
Max(b, oldb, -100000, 100000, tree_depth);
But my game doesn't notice that with only one move it would win. Is this
code wrong?
NOTE: EvalGame() returns a value that estimates how the game state is good
FOR MAX.
Thank you!
- Next message: Arthur J. O'Dwyer: "Re: [Q] Text vs Binary Files"
- Previous message: Richard Harter: "Re: Dominance Tree Sorts"
- Next in thread: Thad Smith: "Re: what's wrong with this alpha-beta tree??"
- Reply: Thad Smith: "Re: what's wrong with this alpha-beta tree??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|