每下一着之前才重新随机生成着法候选列表以提升效率

This commit is contained in:
CalciteM 2019-07-10 02:05:33 +08:00
parent 556bb7b94f
commit eb2121046d
2 changed files with 34 additions and 9 deletions

View File

@ -102,13 +102,10 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
mutex NineChessAi_ab::hashMapMutex;
unordered_map<uint64_t, NineChessAi_ab::HashValue> NineChessAi_ab::hashmap;
void NineChessAi_ab::generateLegalMoves(Node *node)
{
const int MOVE_PRIORITY_TABLE_SIZE = NineChess::N_RINGS * NineChess::N_SEATS;
int pos = 0;
#ifdef MOVE_PRIORITY_TABLE_SUPPORT
#ifdef RANDOM_MOVE
void NineChessAi_ab::shuffleMovePriorityTable()
{
array<int, 4> movePriorityTable0 = { 17, 19, 21, 23 }; // 星位
array<int, 8> movePriorityTable1 = { 25, 27, 29, 31, 9, 11, 13, 15 }; // 外圈和内圈四个顶点
array<int, 4> movePriorityTable2 = { 16, 18, 20, 22 }; // 中圈十字架
@ -121,8 +118,6 @@ void NineChessAi_ab::generateLegalMoves(Node *node)
std::shuffle(movePriorityTable2.begin(), movePriorityTable2.end(), std::default_random_engine(seed));
std::shuffle(movePriorityTable3.begin(), movePriorityTable3.end(), std::default_random_engine(seed));
array<int, 24> movePriorityTable;
for (int i = 0; i < 4; i++) {
movePriorityTable[i + 0] = movePriorityTable0[i];
}
@ -138,6 +133,18 @@ void NineChessAi_ab::generateLegalMoves(Node *node)
for (int i = 0; i < 8; i++) {
movePriorityTable[i + 16] = movePriorityTable3[i];
}
}
#endif // #ifdef RANDOM_MOVE
#endif // MOVE_PRIORITY_TABLE_SUPPORT
void NineChessAi_ab::generateLegalMoves(Node *node)
{
const int MOVE_PRIORITY_TABLE_SIZE = NineChess::N_RINGS * NineChess::N_SEATS;
int pos = 0;
#ifdef MOVE_PRIORITY_TABLE_SUPPORT
#ifdef RANDOM_MOVE
#else // RANDOM_MOVE
int movePriorityTable[MOVE_PRIORITY_TABLE_SIZE] = {
17, 19, 21, 23, // 星位
@ -580,6 +587,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth)
time1.start();
#ifdef MOVE_PRIORITY_TABLE_SUPPORT
#ifdef RANDOM_MOVE
shuffleMovePriorityTable();
#endif
#endif
#ifdef IDS_SUPPORT
// 深化迭代
for (int i = 2; i < d; i++) {

View File

@ -13,6 +13,7 @@
#include <mutex>
#include <string>
#include <Qdebug>
#include <array>
#include "ninechess.h"
@ -127,6 +128,13 @@ protected:
// 篡改深度
int changeDepth(int originalDepth);
// 随机打乱着法搜索顺序
#ifdef MOVE_PRIORITY_TABLE_SUPPORT
#ifdef RANDOM_MOVE
void shuffleMovePriorityTable();
#endif
#endif
// 判断是否在哈希表中
unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator findHash(uint64_t hash);
@ -166,6 +174,10 @@ private:
// 局面数据哈希表
static unordered_map<uint64_t, HashValue> hashmap;
#ifdef MOVE_PRIORITY_TABLE_SUPPORT
array<int, NineChess::N_RINGS *NineChess::N_SEATS> movePriorityTable;
#endif // MOVE_PRIORITY_TABLE_SUPPORT
// 哈希表的默认大小
static const size_t maxHashCount = 1024 * 1024;