hash改名为hashCheckCode以免和后面添加的真正的hash值名称冲突
This commit is contained in:
parent
0d5306514a
commit
88fec0b8bf
|
@ -178,7 +178,7 @@ NineChess::~NineChess()
|
||||||
|
|
||||||
void NineChess::constructHash()
|
void NineChess::constructHash()
|
||||||
{
|
{
|
||||||
context.hash = 0;
|
context.hashCheckCode = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
gameMovingHash = rand64();
|
gameMovingHash = rand64();
|
||||||
|
@ -324,7 +324,7 @@ void NineChess::createMillTable()
|
||||||
// 设置棋局状态和棋盘数据,用于初始化
|
// 设置棋局状态和棋盘数据,用于初始化
|
||||||
bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int maxTimeLedToLose,
|
bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int maxTimeLedToLose,
|
||||||
int initialStep, int flags, const char *board,
|
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 ||
|
if (maxStepsLedToDraw < 0 || maxTimeLedToLose < 0 || initialStep < 0 ||
|
||||||
|
@ -390,10 +390,10 @@ bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int m
|
||||||
// 当前棋局(3×8)
|
// 当前棋局(3×8)
|
||||||
if (board == nullptr) {
|
if (board == nullptr) {
|
||||||
memset(context.board, 0, sizeof(context.board));
|
memset(context.board, 0, sizeof(context.board));
|
||||||
context.hash = 0;
|
context.hashCheckCode = 0;
|
||||||
} else {
|
} else {
|
||||||
memcpy(context.board, board, sizeof(context.board));
|
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,
|
void NineChess::getContext(struct Rule &rule, int &step, int &flags,
|
||||||
int *&board, int &nPiecesInHand_1, int &nPiecesInHand_2, int &num_NeedRemove,
|
int *&board, int &nPiecesInHand_1, int &nPiecesInHand_2, int &num_NeedRemove,
|
||||||
uint64_t &hash)
|
uint64_t &hashCheckCode)
|
||||||
{
|
{
|
||||||
rule = this->currentRule;
|
rule = this->currentRule;
|
||||||
step = this->currentStep;
|
step = this->currentStep;
|
||||||
|
@ -500,7 +500,7 @@ void NineChess::getContext(struct Rule &rule, int &step, int &flags,
|
||||||
nPiecesInHand_1 = context.nPiecesInHand_1;
|
nPiecesInHand_1 = context.nPiecesInHand_1;
|
||||||
nPiecesInHand_2 = context.nPiecesInHand_2;
|
nPiecesInHand_2 = context.nPiecesInHand_2;
|
||||||
num_NeedRemove = context.nPiecesNeedRemove;
|
num_NeedRemove = context.nPiecesNeedRemove;
|
||||||
hash = context.hash;
|
hashCheckCode = context.hashCheckCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NineChess::reset()
|
bool NineChess::reset()
|
||||||
|
@ -544,8 +544,8 @@ bool NineChess::reset()
|
||||||
// 用时置零
|
// 用时置零
|
||||||
elapsedMS_1 = elapsedMS_2 = 0;
|
elapsedMS_1 = elapsedMS_2 = 0;
|
||||||
|
|
||||||
// 哈希归零
|
// 哈希校验码归零
|
||||||
context.hash = 0;
|
context.hashCheckCode = 0;
|
||||||
|
|
||||||
// 提示
|
// 提示
|
||||||
setTips();
|
setTips();
|
||||||
|
@ -699,7 +699,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
board_[pos] = piece;
|
board_[pos] = piece;
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
move_ = pos;
|
move_ = pos;
|
||||||
player_ms = update(time_p);
|
player_ms = update(time_p);
|
||||||
sprintf(cmdline, "(%1u,%1u) %02u:%02u.%03u",
|
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);
|
c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
|
||||||
cmdlist.push_back(string(cmdline));
|
cmdlist.push_back(string(cmdline));
|
||||||
board_[pos] = board_[currentPos];
|
board_[pos] = board_[currentPos];
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
board_[currentPos] = '\x00';
|
board_[currentPos] = '\x00';
|
||||||
updateHash(currentPos);
|
updateHashCheckCode(currentPos);
|
||||||
currentPos = pos;
|
currentPos = pos;
|
||||||
currentStep++;
|
currentStep++;
|
||||||
n = addMills(currentPos);
|
n = addMills(currentPos);
|
||||||
|
@ -876,7 +876,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
|
||||||
currentPos = 0;
|
currentPos = 0;
|
||||||
context.nPiecesNeedRemove--;
|
context.nPiecesNeedRemove--;
|
||||||
currentStep++;
|
currentStep++;
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
// 去子完成
|
// 去子完成
|
||||||
|
|
||||||
// 如果决出胜负
|
// 如果决出胜负
|
||||||
|
@ -1026,7 +1026,7 @@ bool NineChess::place(int pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
board_[pos] = piece;
|
board_[pos] = piece;
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
move_ = pos;
|
move_ = pos;
|
||||||
currentPos = pos;
|
currentPos = pos;
|
||||||
//step++;
|
//step++;
|
||||||
|
@ -1102,9 +1102,9 @@ bool NineChess::place(int pos)
|
||||||
// 移子
|
// 移子
|
||||||
move_ = (currentPos << 8) + pos;
|
move_ = (currentPos << 8) + pos;
|
||||||
board_[pos] = board_[currentPos];
|
board_[pos] = board_[currentPos];
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
board_[currentPos] = '\x00';
|
board_[currentPos] = '\x00';
|
||||||
updateHash(currentPos);
|
updateHashCheckCode(currentPos);
|
||||||
currentPos = pos;
|
currentPos = pos;
|
||||||
//step++;
|
//step++;
|
||||||
n = addMills(currentPos);
|
n = addMills(currentPos);
|
||||||
|
@ -1181,7 +1181,7 @@ bool NineChess::capture(int pos)
|
||||||
move_ = -pos;
|
move_ = -pos;
|
||||||
currentPos = 0;
|
currentPos = 0;
|
||||||
context.nPiecesNeedRemove--;
|
context.nPiecesNeedRemove--;
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
//step++;
|
//step++;
|
||||||
// 去子完成
|
// 去子完成
|
||||||
|
|
||||||
|
@ -1286,16 +1286,16 @@ bool NineChess::choose(int pos)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t NineChess::getHash()
|
uint64_t NineChess::getHashCheckCode()
|
||||||
{
|
{
|
||||||
return context.hash;
|
return context.hashCheckCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash函数,对应可重复去子的规则
|
// hash函数,对应可重复去子的规则
|
||||||
uint64_t NineChess::updateHash(int pos)
|
uint64_t NineChess::updateHashCheckCode(int pos)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* hash各数据位详解(名为hash,但实际并无冲突,是算法用到的棋局数据的完全表示)
|
* hash校验码各数据位详解(并无冲突,是算法用到的棋局数据的完全表示)
|
||||||
* 56-63位:空白不用,全为0
|
* 56-63位:空白不用,全为0
|
||||||
* 55位:轮流标识,0为先手,1为后手
|
* 55位:轮流标识,0为先手,1为后手
|
||||||
* 54位:动作标识,落子(选子移动)为0,1为去子
|
* 54位:动作标识,落子(选子移动)为0,1为去子
|
||||||
|
@ -1315,18 +1315,18 @@ uint64_t NineChess::updateHash(int pos)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t temp = board_[pos] & 0x30 >> 4;
|
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)
|
if (context.turn == PLAYER2)
|
||||||
context.hash |= 1ull << 55;
|
context.hashCheckCode |= 1ull << 55;
|
||||||
|
|
||||||
if (context.action == ACTION_CAPTURE)
|
if (context.action == ACTION_CAPTURE)
|
||||||
context.hash |= 1ull << 54;
|
context.hashCheckCode |= 1ull << 54;
|
||||||
|
|
||||||
context.hash |= (uint64_t)context.nPiecesNeedRemove << 4;
|
context.hashCheckCode |= (uint64_t)context.nPiecesNeedRemove << 4;
|
||||||
context.hash |= context.nPiecesInHand_1;
|
context.hashCheckCode |= context.nPiecesInHand_1;
|
||||||
|
|
||||||
return context.hash;
|
return context.hashCheckCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NineChess::giveup(Player loser)
|
bool NineChess::giveup(Player loser)
|
||||||
|
@ -1762,7 +1762,7 @@ void NineChess::cleanForbiddenPoints()
|
||||||
pos = i * N_SEATS + j;
|
pos = i * N_SEATS + j;
|
||||||
if (board_[pos] == '\x0f') {
|
if (board_[pos] == '\x0f') {
|
||||||
board_[pos] = '\x00';
|
board_[pos] = '\x00';
|
||||||
updateHash(pos);
|
updateHashCheckCode(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,8 +179,8 @@ public:
|
||||||
*/
|
*/
|
||||||
int board[N_POINTS];
|
int board[N_POINTS];
|
||||||
|
|
||||||
// 局面哈希值
|
// 局面哈希的校验码,校验码相同 才能认为是同一局面
|
||||||
uint64_t hash;
|
uint64_t hashCheckCode;
|
||||||
|
|
||||||
// Zobrist 数组
|
// Zobrist 数组
|
||||||
//uint64_t zobrist[N_POINTS][POINT_TYPE_COUNT];
|
//uint64_t zobrist[N_POINTS][POINT_TYPE_COUNT];
|
||||||
|
@ -269,7 +269,7 @@ public:
|
||||||
int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数
|
int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数
|
||||||
int nPiecesInHand_2 = 12, // 玩家2剩余未放置子数
|
int nPiecesInHand_2 = 12, // 玩家2剩余未放置子数
|
||||||
int nPiecesNeedRemove = 0, // 尚待去除的子数
|
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 place(int pos);
|
||||||
bool capture(int pos);
|
bool capture(int pos);
|
||||||
|
|
||||||
// hash函数
|
// hash校验值相关
|
||||||
uint64_t getHash();
|
uint64_t getHashCheckCode();
|
||||||
uint64_t updateHash(int pos);
|
uint64_t updateHashCheckCode(int pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 当前使用的规则
|
// 当前使用的规则
|
||||||
|
|
Loading…
Reference in New Issue