No globals #50

Merged
rektdie merged 23 commits from no_globals into main 2025-04-12 13:52:41 +02:00
3 changed files with 7 additions and 8 deletions
Showing only changes of commit 3aad0d90ee - Show all commits

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
#include "tt.h" #include "tt.h"
SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) {
TTEntry *current = &table[hashKey % hashSize]; TTEntry *current = &table[hashKey % table.size()];
if (current->hashKey == hashKey) { if (current->hashKey == hashKey) {
if (current->depth >= depth) { if (current->depth >= depth) {
@@ -20,7 +20,7 @@ SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int
} }
void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) { void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) {
TTEntry *current = &table[hashKey % hashSize]; TTEntry *current = &table[hashKey % table.size()];
current->hashKey = hashKey; current->hashKey = hashKey;
current->nodeType = nodeType; current->nodeType = nodeType;
+4 -5
View File
@@ -21,27 +21,26 @@ constexpr U64 maxHash = (64* 1000000) / sizeof(TTEntry);
// 5 MB // 5 MB
constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry); constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry);
inline U64 hashSize = defaultHash;
constexpr int invalidEntry = 111111; constexpr int invalidEntry = 111111;
class TTable { class TTable {
private: private:
std::vector<TTEntry> table; std::vector<TTEntry> table;
public: public:
TTable() : table(hashSize) {}; TTable() : table(defaultHash) {};
void Resize(U64 size) { void Resize(U64 size) {
table.resize(size); table.resize(size);
} }
void Clear() { void Clear() {
U64 size = table.size();
table.clear(); table.clear();
table.resize(hashSize); table.resize(size);
} }
TTEntry* GetRawEntry(U64 &hashKey) { TTEntry* GetRawEntry(U64 &hashKey) {
TTEntry *current = &table[hashKey % hashSize]; TTEntry *current = &table[hashKey % table.size()];
return current; return current;
} }
+1 -1
View File
@@ -94,7 +94,7 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext& c
static void SetOption(std::string &command, SEARCH::SearchContext& ctx) { static void SetOption(std::string &command, SEARCH::SearchContext& ctx) {
if (command.find("Hash") != std::string::npos) { if (command.find("Hash") != std::string::npos) {
hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry); U64 hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry);
ctx.TT->Resize(hashSize); ctx.TT->Resize(hashSize);
} }
} }