alpha-beta剪枝搜索
2007-11-21 19:37
423 查看
// basic Alpha-Beta search;
move bestmove;
int alphabeta(int depth, int alpha, int beta, bool isMyTurn) ...{
if (gameOver || depth == 0) ...{
return evaluation();
}
generateLegalMoves();
// you may change the search order to make the search faster
for (each move m) ...{
do move m;
score = -alphabeta(depth - 1, -beta, -alpha, ! isMyTurn );
if (score > alpha) ...{
alpha = score;
if(at the Level 1)
bestmove = m;
}
undo move-m;
if (alpha >= beta) ...{
break;
}
}
return alpha;
}
Initial call : alphabeta(depth, - infinite, infinite, isMyTurn);
不理解上面的代码的话,看看下面的极小极大搜索
极小极大搜索
//极大搜索
int Max(int depth)
...{
int best = -INFINITY;
if (depth == 0)
...{
return evaluation();
}
generateLegalMoves();
for (each move m) ...{
...{
do move m;
val = Min(depth - 1); // call the Min search
undo move m;
if (val > best)
...{
best = val;
}
}
return best;
}
int Min(int depth) // Min search
...{
int best = INFINITY;
if (depth <= 0)
...{
return evaluation();
}
GenerateLegalMoves();
for (each move m) ...{
do move m;
val = Max(depth - 1); // call the Max search
undo move m;
if (val < best)
...{
best = val;
}
}
return best;
}
负极大搜索
极小极大搜索可以统一用负极大搜索代替
int NegaMax(int depth)
...{
int best = -INFINITY;
if (depth == 0)
...{
return evaluation();
}
GenerateLegalMoves();
for (each move m) ...{
do move m;
val = - NegaMax(depth - 1);
undo move m;
if (val > best)
...{
best = val;
}
}
return best;
}
move bestmove;
int alphabeta(int depth, int alpha, int beta, bool isMyTurn) ...{
if (gameOver || depth == 0) ...{
return evaluation();
}
generateLegalMoves();
// you may change the search order to make the search faster
for (each move m) ...{
do move m;
score = -alphabeta(depth - 1, -beta, -alpha, ! isMyTurn );
if (score > alpha) ...{
alpha = score;
if(at the Level 1)
bestmove = m;
}
undo move-m;
if (alpha >= beta) ...{
break;
}
}
return alpha;
}
Initial call : alphabeta(depth, - infinite, infinite, isMyTurn);
不理解上面的代码的话,看看下面的极小极大搜索
极小极大搜索
//极大搜索
int Max(int depth)
...{
int best = -INFINITY;
if (depth == 0)
...{
return evaluation();
}
generateLegalMoves();
for (each move m) ...{
...{
do move m;
val = Min(depth - 1); // call the Min search
undo move m;
if (val > best)
...{
best = val;
}
}
return best;
}
int Min(int depth) // Min search
...{
int best = INFINITY;
if (depth <= 0)
...{
return evaluation();
}
GenerateLegalMoves();
for (each move m) ...{
do move m;
val = Max(depth - 1); // call the Max search
undo move m;
if (val < best)
...{
best = val;
}
}
return best;
}
负极大搜索
极小极大搜索可以统一用负极大搜索代替
int NegaMax(int depth)
...{
int best = -INFINITY;
if (depth == 0)
...{
return evaluation();
}
GenerateLegalMoves();
for (each move m) ...{
do move m;
val = - NegaMax(depth - 1);
undo move m;
if (val > best)
...{
best = val;
}
}
return best;
}
相关文章推荐
- 完全极大极小搜索与alpha-beta剪枝
- POJ 1568 Find the Winning Move 极大极小搜索+alpha-beta剪枝 -
- 最小-最大搜索和Alpha-beta剪枝搜索
- POJ - 1568 Find the Winning Move 极小极大搜索+alpha-beta剪枝
- POJ 1085 Triangle War 博弈 (对抗搜索 alpha-beta 剪枝)
- 浅谈"对抗搜索"的alpha-beta 剪枝
- 博弈树搜索之alpha-beta剪枝——一步一步教你写一字棋智能程序
- 最大最小搜索,alpha beta 剪枝
- poj1568 Find the Winning Move[极大极小搜索+alpha-beta剪枝]
- bzoj Triangle War 状态压缩+极大极小搜索+Alpha-Beta剪枝
- 【POJ1568】【极大极小搜索+alpha-beta剪枝】Find the Winning Move
- POJ - 1085 Triangle War 极小极大搜索+alpha-beta剪枝
- POJ 1568 极大极小搜索 + alpha-beta剪枝
- [POJ1568]Find the Winning Move(极大极小搜索,alpha-beta剪枝,特判)
- alpha-beta剪枝搜索
- POJ - 3317 Stake Your Claim 极大极小搜索+alpha-beta剪枝+记忆化搜索
- 博弈搜索练习-极大极小值搜索+AlphaBeta剪枝--POJ 1085-Triangle War/三角点格棋
- 极小极大值方法以及alpha-Beta剪枝
- 转:极小极大搜索方法、负值最大算法和Alpha-Beta搜索方法
- Alpha-Beta搜索