diff --git a/src/ai/movegen.cpp b/src/ai/movegen.cpp index c31c8c18..b9dcbd91 100644 --- a/src/ai/movegen.cpp +++ b/src/ai/movegen.cpp @@ -51,10 +51,12 @@ void MoveList::generate(AIAlgorithm &ai, Game &tempGame, for (move_t i : movePriorityTable) { square = static_cast(i); + // 如果已经有子占据, 继续检索 if (tempGame.boardLocations[square]) { continue; } + // 否则如果是空位 if (tempGame.position.phase != PHASE_READY || node != root) { ai.addNode(node, VALUE_ZERO, (move_t)square, bestMove, tempGame.position.sideToMove); } else { diff --git a/src/ai/search.cpp b/src/ai/search.cpp index 8740e5da..2baeaad7 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -220,11 +220,18 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode( // 若没有启用置换表,或启用了但为叶子节点,则 bestMove 为0 if (bestMove == 0 || move != bestMove) { #ifdef MILL_FIRST - // 优先成三 // TODO: Adapt MEMORY_POOL - if (tempGame.getPhase() == GAME_PLACING && move > 0 && tempGame.position.board.isInMills(move, true)) { - parent->children.insert(parent->children.begin(), newNode); + // 优先成三 + if (tempGame.getPhase() == PHASE_PLACING && move > 0 && + tempGame.position.board.inHowManyMills2((square_t)move)) { + int pcs = parent->childrenSize; + for (int i = pcs; i >= 1; i--) { + parent->children[i] = parent->children[i - 1]; + } + parent->children[0] = newNode; + parent->childrenSize++; } else { - parent->children.push_back(newNode); + parent->children[parent->childrenSize] = newNode; + parent->childrenSize++; } #else // MILL_FIRST parent->children[parent->childrenSize] = newNode; diff --git a/src/game/board.cpp b/src/game/board.cpp index 3a560284..a7ab609f 100644 --- a/src/game/board.cpp +++ b/src/game/board.cpp @@ -225,6 +225,22 @@ int Board::inHowManyMills(square_t square) return n; } +int Board::inHowManyMills2(square_t square) +{ + int n = 0; + int square_1, square_2; + + for (int l = 0; l < LINE_TYPES_COUNT; l++) { + square_1 = millTable[square][l][0]; + square_2 = millTable[square][l][1]; + if (locations[square_1] & locations[square_2]) { + n++; + } + } + + return n; +} + int Board::addMills(square_t square) { // 成三用一个64位整数了,规则如下 diff --git a/src/game/board.h b/src/game/board.h index 0a0f4420..98ac3040 100644 --- a/src/game/board.h +++ b/src/game/board.h @@ -70,6 +70,7 @@ public: // 判断棋盘 square 处的棋子处于几个“三连”中 int inHowManyMills(square_t square); + int inHowManyMills2(square_t square); // 判断玩家的所有棋子是否都处于“三连”状态 bool isAllInMills(player_t);