replace key_t to hash_t to fix GCC build error
This commit is contained in:
parent
92c65f3c2d
commit
333641845a
|
@ -163,4 +163,4 @@
|
|||
#define likely(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
|
||||
|
||||
#endif // CONFIG_H
|
||||
#endif // CONFIG_H
|
||||
|
|
|
@ -38,7 +38,7 @@ player_t gSideToMove;
|
|||
using namespace CTSL;
|
||||
|
||||
// 用于检测重复局面 (Position)
|
||||
vector<key_t> moveHistory;
|
||||
vector<hash_t> moveHistory;
|
||||
|
||||
AIAlgorithm::AIAlgorithm()
|
||||
{
|
||||
|
@ -198,7 +198,7 @@ int AIAlgorithm::search(depth_t depth)
|
|||
static int nRepetition = 0;
|
||||
|
||||
if (state->position->getPhase() == PHASE_MOVING) {
|
||||
key_t key = state->position->getPosKey();
|
||||
hash_t key = state->position->getPosKey();
|
||||
|
||||
if (std::find(moveHistory.begin(), moveHistory.end(), key) != moveHistory.end()) {
|
||||
nRepetition++;
|
||||
|
@ -343,7 +343,7 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta)
|
|||
|
||||
#if defined (TRANSPOSITION_TABLE_ENABLE) || defined(ENDGAME_LEARNING)
|
||||
// 获取哈希值
|
||||
key_t posKey = st->position->getPosKey();
|
||||
hash_t posKey = st->position->getPosKey();
|
||||
#endif
|
||||
|
||||
#ifdef ENDGAME_LEARNING
|
||||
|
|
|
@ -208,7 +208,7 @@ public:
|
|||
#include "tt.h"
|
||||
|
||||
#ifdef THREEFOLD_REPETITION
|
||||
extern vector<key_t> moveHistory;
|
||||
extern vector<hash_t> moveHistory;
|
||||
#endif
|
||||
|
||||
#endif /* SEARCH_H */
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
static constexpr int TRANSPOSITION_TABLE_SIZE = 0x2000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突
|
||||
HashMap<key_t, TTEntry> TT(TRANSPOSITION_TABLE_SIZE);
|
||||
HashMap<hash_t, TTEntry> TT(TRANSPOSITION_TABLE_SIZE);
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
|
||||
uint8_t transpositionTableAge;
|
||||
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
|
||||
|
||||
value_t TranspositionTable::probe(const key_t &key,
|
||||
value_t TranspositionTable::probe(const hash_t &key,
|
||||
const depth_t &depth,
|
||||
const value_t &alpha,
|
||||
const value_t &beta,
|
||||
|
@ -88,7 +88,7 @@ out:
|
|||
return VALUE_UNKNOWN;
|
||||
}
|
||||
|
||||
bool TranspositionTable::search(const key_t &key, TTEntry &tte)
|
||||
bool TranspositionTable::search(const hash_t &key, TTEntry &tte)
|
||||
{
|
||||
return TT.find(key, tte);
|
||||
|
||||
|
@ -117,7 +117,7 @@ bool TranspositionTable::search(const key_t &key, TTEntry &tte)
|
|||
#endif
|
||||
}
|
||||
|
||||
void TranspositionTable::prefetch(const key_t &key)
|
||||
void TranspositionTable::prefetch(const hash_t &key)
|
||||
{
|
||||
TT.prefetchValue(key);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void TranspositionTable::prefetch(const key_t &key)
|
|||
int TranspositionTable::save(const value_t &value,
|
||||
const depth_t &depth,
|
||||
const bound_t &type,
|
||||
const key_t &key
|
||||
const hash_t &key
|
||||
#ifdef TT_MOVE_ENABLE
|
||||
, const move_t &ttMove
|
||||
#endif // TT_MOVE_ENABLE
|
||||
|
|
12
src/ai/tt.h
12
src/ai/tt.h
|
@ -30,7 +30,7 @@ using namespace CTSL;
|
|||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
extern const key_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT];
|
||||
extern const hash_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT];
|
||||
|
||||
enum bound_t : uint8_t
|
||||
{
|
||||
|
@ -57,8 +57,8 @@ class TranspositionTable
|
|||
{
|
||||
public:
|
||||
// 查找哈希表
|
||||
static bool search(const key_t &key, TTEntry &tte);
|
||||
static value_t probe(const key_t &key,
|
||||
static bool search(const hash_t &key, TTEntry &tte);
|
||||
static value_t probe(const hash_t &key,
|
||||
const depth_t &depth,
|
||||
const value_t &alpha,
|
||||
const value_t &beta,
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
static int save(const value_t &value,
|
||||
const depth_t &depth,
|
||||
const bound_t &type,
|
||||
const key_t &key
|
||||
const hash_t &key
|
||||
#ifdef TT_MOVE_ENABLE
|
||||
, const move_t &ttMove
|
||||
#endif // TT_MOVE_ENABLE
|
||||
|
@ -82,13 +82,13 @@ public:
|
|||
static void clear();
|
||||
|
||||
// 预读取
|
||||
static void prefetch(const key_t &key);
|
||||
static void prefetch(const hash_t &key);
|
||||
|
||||
private:
|
||||
friend struct TTEntry;
|
||||
};
|
||||
|
||||
extern HashMap<key_t, TTEntry> TT;
|
||||
extern HashMap<hash_t, TTEntry> TT;
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
|
||||
extern uint8_t transpositionTableAge;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace CTSL //Concurrent Thread Safe Library
|
|||
//during the creation of the bucket. All the key buckets are created during the construction of the map.
|
||||
//Locks are taken per bucket, hence multiple threads can write simultaneously in different buckets in the key map
|
||||
#ifdef HASH_KEY_DISABLE
|
||||
#define hashFn key_t
|
||||
#define hashFn hash_t
|
||||
template <typename K, typename V>
|
||||
#else
|
||||
template <typename K, typename V, typename F = std::key<K> >
|
||||
|
@ -34,7 +34,7 @@ namespace CTSL //Concurrent Thread Safe Library
|
|||
class HashMap
|
||||
{
|
||||
public:
|
||||
HashMap(key_t hashSize_ = HASH_SIZE_DEFAULT) : hashSize(hashSize_)
|
||||
HashMap(hash_t hashSize_ = HASH_SIZE_DEFAULT) : hashSize(hashSize_)
|
||||
{
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
hashTable = new HashNode<K, V>[hashSize]; //create the key table as an array of key nodes
|
||||
|
@ -230,7 +230,7 @@ namespace CTSL //Concurrent Thread Safe Library
|
|||
#else
|
||||
F hashFn;
|
||||
#endif
|
||||
const key_t hashSize;
|
||||
const hash_t hashSize;
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
#ifndef HASHMAP_NOLOCK
|
||||
mutable std::shared_timed_mutex mutex_;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "zobrist.h"
|
||||
|
||||
const key_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT] = {
|
||||
const hash_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT] = {
|
||||
#ifdef TRANSPOSITION_TABLE_CUTDOWN
|
||||
{0x4E421A, 0x3962FF, 0x6DB6EE, 0x219AE1},
|
||||
{0x1F3DE2, 0xD9AACB, 0xD51733, 0xD3F9EA},
|
||||
|
|
|
@ -22,4 +22,4 @@
|
|||
#include "config.h"
|
||||
#include "position.h"
|
||||
|
||||
extern const key_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT];
|
||||
extern const hash_t zobrist[SQ_EXPANDED_COUNT][PIECETYPE_COUNT];
|
||||
|
|
|
@ -352,7 +352,7 @@ bool Position::start()
|
|||
// 如果游戏处于未开始状态
|
||||
case PHASE_READY:
|
||||
// 启动计时器
|
||||
startTime = time(NULL);
|
||||
startTime = time(nullptr);
|
||||
// 进入开局状态
|
||||
phase = PHASE_PLACING;
|
||||
return true;
|
||||
|
@ -363,6 +363,20 @@ bool Position::start()
|
|||
|
||||
bool Position::placePiece(square_t square, bool updateCmdlist)
|
||||
{
|
||||
ring_t r;
|
||||
seat_t s;
|
||||
int i;
|
||||
// 时间的临时变量
|
||||
int seconds = -1;
|
||||
|
||||
// 对于开局落子
|
||||
int piece = '\x00';
|
||||
int n = 0;
|
||||
|
||||
int playerId = Player::toId(sideToMove);
|
||||
|
||||
bitboard_t fromTo;
|
||||
|
||||
// 如果局面为“结局”,返回false
|
||||
if (phase == PHASE_GAMEOVER)
|
||||
return false;
|
||||
|
@ -380,19 +394,8 @@ bool Position::placePiece(square_t square, bool updateCmdlist)
|
|||
return false;
|
||||
|
||||
// 格式转换
|
||||
ring_t r;
|
||||
seat_t s;
|
||||
Board::squareToPolar(square, r, s);
|
||||
|
||||
// 时间的临时变量
|
||||
int seconds = -1;
|
||||
|
||||
// 对于开局落子
|
||||
int piece = '\x00';
|
||||
int n = 0;
|
||||
|
||||
int playerId = Player::toId(sideToMove);
|
||||
|
||||
if (phase == PHASE_PLACING) {
|
||||
piece = (0x01 | sideToMove) + rule.nTotalPiecesEachSide - nPiecesInHand[playerId];
|
||||
nPiecesInHand[playerId]--;
|
||||
|
@ -479,7 +482,6 @@ bool Position::placePiece(square_t square, bool updateCmdlist)
|
|||
// 如果落子不合法
|
||||
if (nPiecesOnBoard[sideId] > rule.nPiecesAtLeast ||
|
||||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (square == MoveList::moveTable[currentSquare][i])
|
||||
break;
|
||||
|
@ -503,7 +505,7 @@ bool Position::placePiece(square_t square, bool updateCmdlist)
|
|||
moveStep++;
|
||||
}
|
||||
|
||||
bitboard_t fromTo = square_bb(currentSquare) | square_bb(square);
|
||||
fromTo = square_bb(currentSquare) | square_bb(square);
|
||||
board.byTypeBB[ALL_PIECES] ^= fromTo;
|
||||
board.byTypeBB[playerId] ^= fromTo;
|
||||
|
||||
|
@ -852,6 +854,7 @@ bool Position::doMove(move_t m)
|
|||
if (selectPiece(from_sq(m))) {
|
||||
return placePiece(to_sq(m));
|
||||
}
|
||||
break;
|
||||
case MOVETYPE_PLACE:
|
||||
return placePiece(to_sq(m));
|
||||
default:
|
||||
|
@ -1174,13 +1177,13 @@ void Position::constructKey()
|
|||
key = 0;
|
||||
}
|
||||
|
||||
key_t Position::getPosKey()
|
||||
hash_t Position::getPosKey()
|
||||
{
|
||||
// TODO: 每次获取哈希值时更新 key 值剩余8位,放在此处调用不优雅
|
||||
return updateKeyMisc();
|
||||
}
|
||||
|
||||
key_t Position::updateKey(square_t square)
|
||||
hash_t Position::updateKey(square_t square)
|
||||
{
|
||||
// PieceType is board.locations[square]
|
||||
|
||||
|
@ -1196,18 +1199,18 @@ key_t Position::updateKey(square_t square)
|
|||
return key;
|
||||
}
|
||||
|
||||
key_t Position::revertKey(square_t square)
|
||||
hash_t Position::revertKey(square_t square)
|
||||
{
|
||||
return updateKey(square);
|
||||
}
|
||||
|
||||
key_t Position::updateKeyMisc()
|
||||
hash_t Position::updateKeyMisc()
|
||||
{
|
||||
const int KEY_MISC_BIT = 8;
|
||||
|
||||
// 清除标记位
|
||||
key = key << KEY_MISC_BIT >> KEY_MISC_BIT;
|
||||
key_t hi = 0;
|
||||
hash_t hi = 0;
|
||||
|
||||
// 置位
|
||||
|
||||
|
@ -1219,17 +1222,17 @@ key_t Position::updateKeyMisc()
|
|||
hi |= 1U << 1;
|
||||
}
|
||||
|
||||
hi |= static_cast<key_t>(nPiecesNeedRemove) << 2;
|
||||
hi |= static_cast<key_t>(nPiecesInHand[BLACK]) << 4; // TODO: 或许换 phase 也可以?
|
||||
hi |= static_cast<hash_t>(nPiecesNeedRemove) << 2;
|
||||
hi |= static_cast<hash_t>(nPiecesInHand[BLACK]) << 4; // TODO: 或许换 phase 也可以?
|
||||
|
||||
key = key | (hi << (CHAR_BIT * sizeof(key_t) - KEY_MISC_BIT));
|
||||
key = key | (hi << (CHAR_BIT * sizeof(hash_t) - KEY_MISC_BIT));
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
key_t Position::getNextPrimaryKey(move_t m)
|
||||
hash_t Position::getNextPrimaryKey(move_t m)
|
||||
{
|
||||
key_t npKey = key /* << 8 >> 8 */;
|
||||
hash_t npKey = key /* << 8 >> 8 */;
|
||||
square_t sq = static_cast<square_t>(to_sq(m));;
|
||||
movetype_t mt = type_of(m);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
Board board;
|
||||
|
||||
// 局面的哈希值
|
||||
key_t key {0};
|
||||
hash_t key {0};
|
||||
|
||||
// 局面阶段标识
|
||||
enum phase_t phase {PHASE_NONE};
|
||||
|
@ -238,11 +238,11 @@ public:
|
|||
bool removePiece(square_t square, bool updateCmdlist = false);
|
||||
|
||||
// key 相关
|
||||
key_t getPosKey();
|
||||
key_t revertKey(square_t square);
|
||||
key_t updateKey(square_t square);
|
||||
key_t updateKeyMisc();
|
||||
key_t getNextPrimaryKey(move_t m);
|
||||
hash_t getPosKey();
|
||||
hash_t revertKey(square_t square);
|
||||
hash_t updateKey(square_t square);
|
||||
hash_t updateKeyMisc();
|
||||
hash_t getNextPrimaryKey(move_t m);
|
||||
|
||||
// 赢盘数
|
||||
int score[COLOR_COUNT] = { 0 };
|
||||
|
|
|
@ -30,9 +30,9 @@ using score_t = uint32_t;
|
|||
typedef uint32_t bitboard_t;
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_CUTDOWN
|
||||
using key_t = uint32_t;
|
||||
using hash_t = uint32_t;
|
||||
#else
|
||||
using key_t = uint64_t;
|
||||
using hash_t = uint64_t;
|
||||
#endif /* TRANSPOSITION_TABLE_CUTDOWN */
|
||||
|
||||
enum move_t : int32_t
|
||||
|
|
Loading…
Reference in New Issue