node 增加 stage/action/depth 属性以便于调试
This commit is contained in:
parent
b21474a475
commit
1feeb914ed
|
@ -103,6 +103,7 @@ public:
|
|||
// 局面阶段标识
|
||||
enum GameStage : uint16_t
|
||||
{
|
||||
GAME_NONE = 0x0000,
|
||||
GAME_NOTSTARTED = 0x0001, // 未开局
|
||||
GAME_PLACING = 0x0002, // 开局(摆棋)
|
||||
GAME_MOVING = 0x0004, // 中局(走棋)
|
||||
|
@ -123,6 +124,7 @@ public:
|
|||
// 动作状态标识
|
||||
enum Action : uint16_t
|
||||
{
|
||||
ACTION_NONE = 0x0000,
|
||||
ACTION_CHOOSE = 0x0100, // 选子
|
||||
ACTION_PLACE = 0x0200, // 落子
|
||||
ACTION_CAPTURE = 0x0400 // 提子
|
||||
|
|
|
@ -37,6 +37,9 @@ void NineChessAi_ab::addNode(Node *parent, int value, int move)
|
|||
newNode->parent = parent;
|
||||
newNode->value = value;
|
||||
newNode->move = move;
|
||||
newNode->root = rootNode;
|
||||
newNode->stage = chessTemp.context.stage;
|
||||
newNode->action = chessTemp.context.action;
|
||||
parent->children.push_back(newNode);
|
||||
}
|
||||
|
||||
|
@ -175,6 +178,10 @@ void NineChessAi_ab::setChess(const NineChess &chess)
|
|||
rootNode->value = 0;
|
||||
rootNode->move = 0;
|
||||
rootNode->parent = nullptr;
|
||||
rootNode->action = NineChess::ACTION_NONE;
|
||||
rootNode->stage = NineChess::GAME_NONE;
|
||||
rootNode->root = rootNode;
|
||||
|
||||
}
|
||||
|
||||
int NineChessAi_ab::evaluate(Node *node)
|
||||
|
@ -210,6 +217,9 @@ int NineChessAi_ab::evaluate(Node *node)
|
|||
break;
|
||||
}
|
||||
|
||||
node->stage = chessContext->stage;
|
||||
node->action = chessContext->action;
|
||||
|
||||
switch (chessContext->stage) {
|
||||
case NineChess::GAME_NOTSTARTED:
|
||||
break;
|
||||
|
@ -322,6 +332,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
|||
// 统计遍历次数
|
||||
nodeCount++;
|
||||
|
||||
// 记录深度
|
||||
node->depth = depth;
|
||||
|
||||
// 记录根节点
|
||||
node->root = rootNode;
|
||||
|
||||
// 搜索到叶子节点(决胜局面)
|
||||
if (chessContext->stage == NineChess::GAME_OVER) {
|
||||
node->value = evaluate(node);
|
||||
|
|
|
@ -38,6 +38,10 @@ public:
|
|||
int move; // 招法的命令行指令,图上标示为节点前的连线
|
||||
struct Node *parent; // 父节点
|
||||
list<struct Node *> children; // 子节点列表
|
||||
struct Node *root;
|
||||
NineChess::GameStage stage;
|
||||
NineChess::Action action;
|
||||
int depth;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue