I use "Always Replace" strategy.
Here is the source code:
Code: Select all
var HASHENTRIES = (28 << 20) / 14; // Hashtabla merete 28 MB / 1 Hash merete (14 Byte)
var HASHMASK = HASHENTRIES - 1; // Hashtabla maszk, csak ketto hatvanya lehet & MASK
Code: Select all
function StoreHashMove(move, score, flags, depth) {
if (score > ISMATE) { // Pontszam fixalasa
score += boardPly;
} else if (score < -ISMATE) { // Pontszam fixalasa
score -= boardPly;
}
brd_HashTable[brd_hashKeyLow & HASHMASK] = new HashEntry(move, score, flags, depth, brd_hashKeyLow, brd_hashKeyHigh); // 108 bit /14 Byte/
}
function HashEntry(move, score, flags, depth, hashLow, hashHigh) {
this.move = move; // 20 bit
this.flags = flags; // 2 bit
this.depth = depth; // 7 bit
this.score = score; // 15 bit
this.hashKeyLow = hashLow; // 32 bit
this.hashKeyHigh = hashHigh; // 32 bit
}
I use 1 array -> it's called: brd_HashTable
The entries is Objects, not arrays, and not strings.
It could have been like this:
Code: Select all
brd_HashTable[brd_hashKeyLow & HASHMASK] = {
move : move,
flags : flags,
depth : depth,
score : score,
hashKeyLow : brd_hashKeyLow,
hashKeyHigh: brd_hashKeyHigh
};
but in most browsers with "Object prototype" is a bit faster.
function HashEntry is my prototype.
So, this is not string, but also object in array.
(It's difficult because browser-dependent is the speed.)
I saw this method in garboChess.js
So you can refer to it:
Code: Select all
brd_HashTable[brd_hashKeyLow & HASHMASK].score
brd_HashTable[brd_hashKeyLow & HASHMASK].flags
brd_HashTable[brd_hashKeyLow & HASHMASK].depth
In C would look like this(but this is different):
Code: Select all
brd_HashTable[brd_hashKeyLow & HASHMASK]->score
brd_HashTable[brd_hashKeyLow & HASHMASK]->flags
brd_HashTable[brd_hashKeyLow & HASHMASK]->depth
Very important:
so the maximal hash size is 28mb (currently).
If this is bigger, than some mobile browser crashes.
In a UCI i would like with bigger hash...
And again: JavaScript chess engine is difficult because browser-dependent is the speed.