hash改名为hashCheckCode以免和后面添加的真正的hash值名称冲突

This commit is contained in:
CalciteM Team 2019-07-13 14:59:22 +08:00
parent 0d5306514a
commit 88fec0b8bf
2 changed files with 33 additions and 33 deletions

View File

@ -178,7 +178,7 @@ NineChess::~NineChess()
void NineChess::constructHash()
{
context.hash = 0;
context.hashCheckCode = 0;
#if 0
gameMovingHash = rand64();
@ -324,7 +324,7 @@ void NineChess::createMillTable()
// 设置棋局状态和棋盘数据,用于初始化
bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int maxTimeLedToLose,
int initialStep, int flags, const char *board,
int nPiecesInHand_1, int nPiecesInHand_2, int nPiecesNeedRemove, uint64_t hash)
int nPiecesInHand_1, int nPiecesInHand_2, int nPiecesNeedRemove, uint64_t hashCheckCode)
{
// 有效性判断
if (maxStepsLedToDraw < 0 || maxTimeLedToLose < 0 || initialStep < 0 ||
@ -390,10 +390,10 @@ bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int m
// 当前棋局3×8
if (board == nullptr) {
memset(context.board, 0, sizeof(context.board));
context.hash = 0;
context.hashCheckCode = 0;
} else {
memcpy(context.board, board, sizeof(context.board));
context.hash = hash;
context.hashCheckCode = hashCheckCode;
}
// 计算盘面子数
@ -491,7 +491,7 @@ bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int m
void NineChess::getContext(struct Rule &rule, int &step, int &flags,
int *&board, int &nPiecesInHand_1, int &nPiecesInHand_2, int &num_NeedRemove,
uint64_t &hash)
uint64_t &hashCheckCode)
{
rule = this->currentRule;
step = this->currentStep;
@ -500,7 +500,7 @@ void NineChess::getContext(struct Rule &rule, int &step, int &flags,
nPiecesInHand_1 = context.nPiecesInHand_1;
nPiecesInHand_2 = context.nPiecesInHand_2;
num_NeedRemove = context.nPiecesNeedRemove;
hash = context.hash;
hashCheckCode = context.hashCheckCode;
}
bool NineChess::reset()
@ -544,8 +544,8 @@ bool NineChess::reset()
// 用时置零
elapsedMS_1 = elapsedMS_2 = 0;
// 哈希归零
context.hash = 0;
// 哈希校验码归零
context.hashCheckCode = 0;
// 提示
setTips();
@ -699,7 +699,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
}
board_[pos] = piece;
updateHash(pos);
updateHashCheckCode(pos);
move_ = pos;
player_ms = update(time_p);
sprintf(cmdline, "(%1u,%1u) %02u:%02u.%03u",
@ -788,9 +788,9 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
cmdlist.push_back(string(cmdline));
board_[pos] = board_[currentPos];
updateHash(pos);
updateHashCheckCode(pos);
board_[currentPos] = '\x00';
updateHash(currentPos);
updateHashCheckCode(currentPos);
currentPos = pos;
currentStep++;
n = addMills(currentPos);
@ -876,7 +876,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
currentPos = 0;
context.nPiecesNeedRemove--;
currentStep++;
updateHash(pos);
updateHashCheckCode(pos);
// 去子完成
// 如果决出胜负
@ -1026,7 +1026,7 @@ bool NineChess::place(int pos)
}
board_[pos] = piece;
updateHash(pos);
updateHashCheckCode(pos);
move_ = pos;
currentPos = pos;
//step++;
@ -1102,9 +1102,9 @@ bool NineChess::place(int pos)
// 移子
move_ = (currentPos << 8) + pos;
board_[pos] = board_[currentPos];
updateHash(pos);
updateHashCheckCode(pos);
board_[currentPos] = '\x00';
updateHash(currentPos);
updateHashCheckCode(currentPos);
currentPos = pos;
//step++;
n = addMills(currentPos);
@ -1181,7 +1181,7 @@ bool NineChess::capture(int pos)
move_ = -pos;
currentPos = 0;
context.nPiecesNeedRemove--;
updateHash(pos);
updateHashCheckCode(pos);
//step++;
// 去子完成
@ -1286,16 +1286,16 @@ bool NineChess::choose(int pos)
return false;
}
uint64_t NineChess::getHash()
uint64_t NineChess::getHashCheckCode()
{
return context.hash;
return context.hashCheckCode;
}
// hash函数对应可重复去子的规则
uint64_t NineChess::updateHash(int pos)
uint64_t NineChess::updateHashCheckCode(int pos)
{
/*
* hash各数据位详解hash
* hash校验码各数据位详解
* 56-630
* 5501
* 5401
@ -1315,18 +1315,18 @@ uint64_t NineChess::updateHash(int pos)
#endif
uint64_t temp = board_[pos] & 0x30 >> 4;
context.hash |= (temp) << ((pos - 8) * 2 + 6);
context.hashCheckCode |= (temp) << ((pos - 8) * 2 + 6);
if (context.turn == PLAYER2)
context.hash |= 1ull << 55;
context.hashCheckCode |= 1ull << 55;
if (context.action == ACTION_CAPTURE)
context.hash |= 1ull << 54;
context.hashCheckCode |= 1ull << 54;
context.hash |= (uint64_t)context.nPiecesNeedRemove << 4;
context.hash |= context.nPiecesInHand_1;
context.hashCheckCode |= (uint64_t)context.nPiecesNeedRemove << 4;
context.hashCheckCode |= context.nPiecesInHand_1;
return context.hash;
return context.hashCheckCode;
}
bool NineChess::giveup(Player loser)
@ -1762,7 +1762,7 @@ void NineChess::cleanForbiddenPoints()
pos = i * N_SEATS + j;
if (board_[pos] == '\x0f') {
board_[pos] = '\x00';
updateHash(pos);
updateHashCheckCode(pos);
}
}
}

View File

@ -179,8 +179,8 @@ public:
*/
int board[N_POINTS];
// 局面哈希
uint64_t hash;
// 局面哈希的校验码,校验码相同 才能认为是同一局面
uint64_t hashCheckCode;
// Zobrist 数组
//uint64_t zobrist[N_POINTS][POINT_TYPE_COUNT];
@ -269,7 +269,7 @@ public:
int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数
int nPiecesInHand_2 = 12, // 玩家2剩余未放置子数
int nPiecesNeedRemove = 0, // 尚待去除的子数
uint64_t hash = 0ull // Hash 为0
uint64_t hashCheckCode = 0ull // Hash 为0
);
// 获取棋局状态和棋盘上下文
@ -479,9 +479,9 @@ protected:
bool place(int pos);
bool capture(int pos);
// hash函数
uint64_t getHash();
uint64_t updateHash(int pos);
// hash校验值相关
uint64_t getHashCheckCode();
uint64_t updateHashCheckCode(int pos);
private:
// 当前使用的规则