Skip to content

Commit

Permalink
add dynamic hashtable sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
PGG106 committed Jun 10, 2022
1 parent 9291ccc commit 217bb0b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int start_bench() {
int total_nodes = 0;
int total_time = 0;
info->quit = 0;
InitHashTable(HashTable);
InitHashTable(HashTable,64);
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char** argv)
S_Board pos[1];
S_SearchINFO info[1];
Reset_info(info);
InitHashTable(HashTable);
InitHashTable(HashTable,64);
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);

Expand Down
5 changes: 2 additions & 3 deletions src/ttable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "assert.h"
#include "makemove.h"

const int HashSize = 0x100000 * 80;

S_HASHTABLE HashTable[1];

Expand Down Expand Up @@ -58,8 +57,8 @@ void ClearHashTable(S_HASHTABLE* table) {
table->newWrite = 0;
}

void InitHashTable(S_HASHTABLE* table) {

void InitHashTable(S_HASHTABLE* table, int MB) {
int HashSize = 0x100000 * MB;
table->numEntries = HashSize / sizeof(S_HASHENTRY);
table->numEntries -= 2;
if (table->pTable != NULL) free(table->pTable);
Expand Down
2 changes: 1 addition & 1 deletion src/ttable.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int GetPvLine(const int depth, S_Board* pos);


void ClearHashTable(S_HASHTABLE* table);
void InitHashTable(S_HASHTABLE* table);
void InitHashTable(S_HASHTABLE* table, int MB);

int ProbeHashEntry(S_Board* pos, int* move, int* score, int alpha, int beta, int depth);
void StoreHashEntry(S_Board* pos, const int move, int score, const int flags, const int depth);
Expand Down
10 changes: 9 additions & 1 deletion src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void Uci_Loop(S_Board* pos, S_SearchINFO* info, char** argv)

}


int MB = 64;

// reset STDIN & STDOUT buffers
setvbuf(stdin, NULL, _IONBF, 0);
Expand All @@ -277,6 +277,7 @@ void Uci_Loop(S_Board* pos, S_SearchINFO* info, char** argv)
// print engine info
printf("id name CE2BIT\n");
printf("id author PGG\n");
printf("option name Hash type spin default 64 \n");
printf("uciok\n");

// main loop
Expand Down Expand Up @@ -340,6 +341,13 @@ void Uci_Loop(S_Board* pos, S_SearchINFO* info, char** argv)
printf("id author PGG106\n");
printf("uciok\n");
}


else if (!strncmp(input, "setoption name Hash value ", 26)) {
sscanf(input, "%*s %*s %*s %*s %d", &MB);
printf("Set Hash to %d MB\n", MB);
InitHashTable(HashTable, MB);
}
else if (strncmp(input, "bench", 5) == 0) {


Expand Down

0 comments on commit 217bb0b

Please sign in to comment.