From c55b10b129a96f83efc076881d04e713e3772f64 Mon Sep 17 00:00:00 2001
From: CalciteM <calcitem@outlook.com>
Date: Sun, 7 Jul 2019 12:59:07 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=90=9C=E7=B4=A2=E7=BF=BB=E8=BD=AC?=
 =?UTF-8?q?=E5=B1=80=E9=9D=A2=E7=9A=84HASH?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 NineChess/src/config.h           |  4 ++--
 NineChess/src/ninechessai_ab.cpp | 15 +++++++++------
 NineChess/src/ninechessai_ab.h   |  5 ++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/NineChess/src/config.h b/NineChess/src/config.h
index eb881b63..60d4b2d4 100644
--- a/NineChess/src/config.h
+++ b/NineChess/src/config.h
@@ -1,7 +1,7 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-#define DEBUG
+//#define DEBUG
 
 //#define DEAL_WITH_HORIZON_EFFECT
 
@@ -42,7 +42,7 @@
 #define DRAW_SEAT_NUMBER
 #endif
 
-//#define IDS_SUPPORT
+#define IDS_SUPPORT
 
 #define SAVE_CHESSBOOK_WHEN_ACTION_NEW_TRIGGERED
 
diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp
index da4b209c..4347b7cd 100644
--- a/NineChess/src/ninechessai_ab.cpp
+++ b/NineChess/src/ninechessai_ab.cpp
@@ -63,6 +63,7 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
     newNode->alpha = -INF_VALUE;
     newNode->beta = INF_VALUE;
     newNode->result = 0;
+    newNode->isHash = false;
 #endif
     int c, p;
     char cmd[32] = { 0 };
@@ -701,12 +702,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
     }
     // 更新更深层数据
     else {
-        hashMapMutex.lock();
-        if (iter->second.depth < depth) {
+        //hashMapMutex.lock();
+        //if (iter->second.depth < depth) {
             //iter->second.value = node->value;
             //iter->second.depth = depth;
-        }
-        hashMapMutex.unlock();
+        //}
+        //hashMapMutex.unlock();
     }
 #endif
 
@@ -763,9 +764,9 @@ const char* NineChessAi_ab::bestMove()
     string moves = "";
     for (auto child : rootNode->children) {
         if (child->value == rootNode->value)
-            qDebug("[%.2d] %d\t%s\t%d *", i, child->move, move2string(child->move), child->value);
+            qDebug("[%.2d] %d\t%s\t%d H%d *", i, child->move, move2string(child->move), child->value, child->isHash);
         else
-            qDebug("[%.2d] %d\t%s\t%d", i, child->move, move2string(child->move), child->value);
+            qDebug("[%.2d] %d\t%s\t%d H%d", i, child->move, move2string(child->move), child->value, child->isHash);
 
         i++;
     }
@@ -835,6 +836,7 @@ unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator NineChessAi_ab::fin
 {
     auto iter = hashmap.find(hash);
 
+#if 0
     if (iter != hashmap.end())
         return iter;
 
@@ -855,6 +857,7 @@ unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator NineChessAi_ab::fin
             }
         }
     }
+#endif
 
     return iter;
 }
diff --git a/NineChess/src/ninechessai_ab.h b/NineChess/src/ninechessai_ab.h
index 7fa1d6b5..be4aff68 100644
--- a/NineChess/src/ninechessai_ab.h
+++ b/NineChess/src/ninechessai_ab.h
@@ -52,9 +52,8 @@ public:
         struct Node* parent;           // 父节点
         size_t id;                      // 结点编号
         int rand;                       // 随机数,对于 value 一致的结点随机排序用
-#ifdef HASH_MAP_ENABLE
         uint64_t hash;
-#endif
+        bool isHash;                    //  是否从 Hash 读取
 #ifdef DEBUG_AB_TREE
         string cmd;
         enum NineChess::Player player;  // 此招是谁下的
@@ -64,7 +63,7 @@ public:
         int beta;                       // 表示对手目前的劣势,这是对手所能承受的最坏结果,Beta 值越大,表示对手劣势越明显,如果当前结点返回  Beta 或比 Beta 更好的值,作为父结点的对方就绝对不会选择这种策略 
         bool isTimeout;                 // 是否遍历到此结点时因为超时而被迫退出
         bool isLeaf;                    // 是否为叶子结点, 叶子结点是决胜局面
-        bool isHash;                    //  是否从 Hash 读取
+
         NineChess::GameStage stage;     // 摆棋阶段还是走棋阶段
         NineChess::Action action;       // 动作状态
         int nPiecesOnBoardDiff;         // 场上棋子个数和对手的差值