去除AB剪枝时对子节点的随机排序
This commit is contained in:
parent
6a3aac64aa
commit
3fd746012c
|
@ -120,11 +120,15 @@ void NineChessAi_ab::buildChildren(Node *node)
|
||||||
void NineChessAi_ab::sortChildren(Node *node)
|
void NineChessAi_ab::sortChildren(Node *node)
|
||||||
{
|
{
|
||||||
// 这个函数对效率的影响很大,排序好的话,剪枝较早,节省时间,但不能在此函数耗费太多时间
|
// 这个函数对效率的影响很大,排序好的话,剪枝较早,节省时间,但不能在此函数耗费太多时间
|
||||||
|
|
||||||
|
#ifdef AB_RANDOM_SORT_CHILDREN
|
||||||
// 这里我用一个随机排序,使AI不至于每次走招相同
|
// 这里我用一个随机排序,使AI不至于每次走招相同
|
||||||
srand((unsigned)time(0));
|
srand((unsigned)time(0));
|
||||||
for (auto i : node->children) {
|
for (auto i : node->children) {
|
||||||
i->value = rand();
|
i->value = rand();
|
||||||
}
|
}
|
||||||
|
#endif /* AB_RANDOM_SORT_CHILDREN */
|
||||||
|
|
||||||
// 排序
|
// 排序
|
||||||
if (chessTemp.whosTurn() == NineChess::PLAYER1)
|
if (chessTemp.whosTurn() == NineChess::PLAYER1)
|
||||||
node->children.sort([](Node *n1, Node *n2) { return n1->value > n2->value; });
|
node->children.sort([](Node *n1, Node *n2) { return n1->value > n2->value; });
|
||||||
|
@ -176,8 +180,10 @@ int NineChessAi_ab::evaluate(Node *node)
|
||||||
case NineChess::GAME_PLACING:
|
case NineChess::GAME_PLACING:
|
||||||
// 按手中的棋子计分,不要break;
|
// 按手中的棋子计分,不要break;
|
||||||
value += chessData->nPiecesInHand_1 * 50 - chessData->nPiecesInHand_2 * 50;
|
value += chessData->nPiecesInHand_1 * 50 - chessData->nPiecesInHand_2 * 50;
|
||||||
|
|
||||||
// 按场上棋子计分
|
// 按场上棋子计分
|
||||||
value += chessData->nPiecesOnBoard_1 * 100 - chessData->nPiecesOnBoard_2 * 100;
|
value += chessData->nPiecesOnBoard_1 * 100 - chessData->nPiecesOnBoard_2 * 100;
|
||||||
|
|
||||||
switch (chessData->action) {
|
switch (chessData->action) {
|
||||||
// 选子和落子使用相同的评价方法
|
// 选子和落子使用相同的评价方法
|
||||||
case NineChess::ACTION_CHOOSE:
|
case NineChess::ACTION_CHOOSE:
|
||||||
|
@ -190,11 +196,13 @@ int NineChessAi_ab::evaluate(Node *node)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NineChess::GAME_MOVING:
|
case NineChess::GAME_MOVING:
|
||||||
// 按场上棋子计分
|
// 按场上棋子计分
|
||||||
value += chessData->nPiecesOnBoard_1 * 100 - chessData->nPiecesOnBoard_2 * 100;
|
value += chessData->nPiecesOnBoard_1 * 100 - chessData->nPiecesOnBoard_2 * 100;
|
||||||
|
|
||||||
switch (chessData->action) {
|
switch (chessData->action) {
|
||||||
// 选子和落子使用相同的评价方法
|
// 选子和落子使用相同的评价方法
|
||||||
case NineChess::ACTION_CHOOSE:
|
case NineChess::ACTION_CHOOSE:
|
||||||
|
@ -207,6 +215,7 @@ int NineChessAi_ab::evaluate(Node *node)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 终局评价最简单
|
// 终局评价最简单
|
||||||
|
|
Loading…
Reference in New Issue