AI: 关闭 IDS 并调整 rating 计算以提升性能

* 关闭IDS, 因为通过判断是否成三来排定走子顺序已经很有效;
* 仅在吃子时才统计各个点周围子类型分布;
* 仅在需要检测落子点是否能阻止对方成三时才统计点位于对手几个三连中;
* 去掉摆子阶段尽量往禁点旁边落子的策略;
* 不再判断吃子点处于我方的三连中, 因为可能正好也处于对方的三连中.

自对弈时长 2s, 但走棋阶段没多久就闷杀.
若开 IDS 则是 20s.
This commit is contained in:
Calcitem 2019-10-21 00:06:17 +08:00
parent 8611d4db8b
commit 091a208fbe
2 changed files with 18 additions and 14 deletions

View File

@ -62,9 +62,9 @@
//#define DEAL_WITH_HORIZON_EFFECT
#define IDS_SUPPORT
//#define IDS_SUPPORT
//#define IDS_WINDOW
#define IDS_DEBUG
//#define IDS_DEBUG
//#define IDS_ADD_VALUE
//#define CLEAR_PRUNED_FLAG_BEFORE_SEARCH

View File

@ -244,10 +244,6 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
// 若没有启用置换表,或启用了但为叶子节点,则 bestMove 为0
if (bestMove == 0 || move != bestMove) {
int nPlayerPiece = 0;
int nOpponentPiece = 0;
int nForbidden = 0;
int nEmpty = 0;
square_t sq = SQ_0;
if (move > 0) {
@ -258,12 +254,10 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
sq = (square_t)((-move) & 0x00ff);
}
// TODO: 处理移动子的统计
tempGame.position.board.getSurroundedPieceCount(sq, tempGame.position.sideId,
nPlayerPiece, nOpponentPiece, nForbidden, nEmpty);
int nMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.sideToMove);
int nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent);
int nopponentMills = 0;
#ifdef MILL_FIRST
// TODO: rule.allowRemoveMultiPieces 以及 适配打三棋之外的其他规则
@ -272,20 +266,29 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
if (nMills > 0) {
newNode->rating += static_cast<rating_t>(RATING_ONE_MILL * nMills);
} else {
// 检测落子点是否能阻止对方成三
// 检测落子点是否能阻止对方成三
nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent);
newNode->rating += static_cast<rating_t>(RATING_BLOCK_ONE_MILL * nopponentMills);
}
newNode->rating += static_cast<rating_t>(nForbidden); // 摆子阶段尽量往禁点旁边落子
//newNode->rating += static_cast<rating_t>(nForbidden); // 摆子阶段尽量往禁点旁边落子
if (tempGame.getPiecesOnBoardCount(2) < 2 && // patch: 仅当白方第2着时
Board::isStar(static_cast<square_t>(move))) {
newNode->rating += RATING_STAR_SQUARE;
}
} else if (move < 0) {
} else if (move < 0) {
int nPlayerPiece = 0;
int nOpponentPiece = 0;
int nForbidden = 0;
int nEmpty = 0;
tempGame.position.board.getSurroundedPieceCount(sq, tempGame.position.sideId,
nPlayerPiece, nOpponentPiece, nForbidden, nEmpty);
if (nMills > 0) {
// 吃子点处于我方的三连中
newNode->rating += static_cast<rating_t>(RATING_CAPTURE_ONE_MILL * nMills);
//newNode->rating += static_cast<rating_t>(RATING_CAPTURE_ONE_MILL * nMills);
if (nOpponentPiece == 0) {
// 吃子点旁边没有对方棋子则优先考虑
@ -298,6 +301,7 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
}
// 吃子点处于对方的三连中
nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent);
if (nopponentMills) {
if (nOpponentPiece >= 2) {
// 旁边对方的子较多, 则倾向不吃