打印是选择的最佳着法缩减到没有被剪枝的选择
This commit is contained in:
parent
c55b10b129
commit
b0d2884dbf
|
@ -1,13 +1,13 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
//#define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
//#define DEAL_WITH_HORIZON_EFFECT
|
||||
|
||||
//#define RANDOM_BEST_MOVE
|
||||
|
||||
#define HASH_MAP_ENABLE
|
||||
//#define HASH_MAP_ENABLE
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DONOT_PLAY_SOUND
|
||||
|
@ -21,7 +21,7 @@
|
|||
//#define DONOT_PLAY_SOUND
|
||||
|
||||
#ifdef DEBUG
|
||||
#define GAME_PLACING_FIXED_DEPTH 4
|
||||
#define GAME_PLACING_FIXED_DEPTH 5
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -42,7 +42,7 @@
|
|||
#define DRAW_SEAT_NUMBER
|
||||
#endif
|
||||
|
||||
#define IDS_SUPPORT
|
||||
//#define IDS_SUPPORT
|
||||
|
||||
#define SAVE_CHESSBOOK_WHEN_ACTION_NEW_TRIGGERED
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
|
|||
newNode->beta = INF_VALUE;
|
||||
newNode->result = 0;
|
||||
newNode->isHash = false;
|
||||
newNode->visited = false;
|
||||
newNode->pruned = false;
|
||||
#endif
|
||||
int c, p;
|
||||
char cmd[32] = { 0 };
|
||||
|
@ -217,6 +219,7 @@ void NineChessAi_ab::sortLegalMoves(Node *node)
|
|||
});
|
||||
}
|
||||
#else
|
||||
|
||||
if (chessTemp.whosTurn() == NineChess::PLAYER1) {
|
||||
node->children.sort([](Node* n1, Node* n2) {return n1->value > n2->value;});
|
||||
} else {
|
||||
|
@ -521,6 +524,7 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
|||
node->isLeaf = false;
|
||||
node->isTimeout = false;
|
||||
node->isHash = false;
|
||||
node->visited = true;
|
||||
node->hash = 0;
|
||||
#endif
|
||||
|
||||
|
@ -675,8 +679,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
|||
|
||||
// 如果某个着法的结果大于 α 但小于β,那么这个着法就是走棋一方可以考虑走的
|
||||
// 否则剪枝返回
|
||||
if (alpha >= beta)
|
||||
if (alpha >= beta) {
|
||||
#ifdef DEBUG_AB_TREE
|
||||
node->pruned = true;
|
||||
break;
|
||||
#endif // DEBUG_AB_TREE
|
||||
}
|
||||
}
|
||||
|
||||
node->value = minMax;
|
||||
|
@ -762,11 +770,12 @@ const char* NineChessAi_ab::bestMove()
|
|||
|
||||
int i = 0;
|
||||
string moves = "";
|
||||
|
||||
for (auto child : rootNode->children) {
|
||||
if (child->value == rootNode->value)
|
||||
qDebug("[%.2d] %d\t%s\t%d H%d *", i, child->move, move2string(child->move), child->value, child->isHash);
|
||||
if (child->value == rootNode->value && !child->pruned)
|
||||
qDebug("[%.2d] %d\t%s\t%d *", i, child->move, move2string(child->move), child->value);
|
||||
else
|
||||
qDebug("[%.2d] %d\t%s\t%d H%d", i, child->move, move2string(child->move), child->value, child->isHash);
|
||||
qDebug("[%.2d] %d\t%s\t%d", i, child->move, move2string(child->move), child->value);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ public:
|
|||
int beta; // 表示对手目前的劣势,这是对手所能承受的最坏结果,Beta 值越大,表示对手劣势越明显,如果当前结点返回 Beta 或比 Beta 更好的值,作为父结点的对方就绝对不会选择这种策略
|
||||
bool isTimeout; // 是否遍历到此结点时因为超时而被迫退出
|
||||
bool isLeaf; // 是否为叶子结点, 叶子结点是决胜局面
|
||||
|
||||
bool visited; // 是否在遍历时访问过
|
||||
bool pruned; // 是否在此处剪枝
|
||||
NineChess::GameStage stage; // 摆棋阶段还是走棋阶段
|
||||
NineChess::Action action; // 动作状态
|
||||
int nPiecesOnBoardDiff; // 场上棋子个数和对手的差值
|
||||
|
|
Loading…
Reference in New Issue