http://www.math.sci.hiroshima-u.ac.jp/~ ... T/emt.htmlDaniel Anulliero wrote:Mersenne twister is a good generator and they had 1000 64 bits numbers on the page (I can't find now)
No Zobrist key
Moderators: hgm, Rebel, chrisw
-
- Posts: 2204
- Joined: Sat Jan 18, 2014 10:24 am
- Location: Andorra
Re: No Zobrist key
Daniel José - http://www.andscacs.com
Re: No Zobrist key
Can you explain why this is a good hash?Henk wrote:Maybe this is better. At least I understand it. Collecting 8 times four bits because hash code must be 32 bits. Largest prime for four bits is 13.Code: Select all
public override int GetHashCode() { int hash = 0; for (int i = 0; i < SIZE-1; i++) { hash += (int)(rep[i] % 13); hash = (hash << 4); } hash += (int)(rep[SIZE-1] % 13); return hash; }
Did you test how often it has collisions?
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: No Zobrist key
I don't know if it is a good hash but I understand the code. Might be it is a bad hash with many collisions but I don't think it makes my engine play worse.flok wrote:Can you explain why this is a good hash?Henk wrote:Maybe this is better. At least I understand it. Collecting 8 times four bits because hash code must be 32 bits. Largest prime for four bits is 13.Code: Select all
public override int GetHashCode() { int hash = 0; for (int i = 0; i < SIZE-1; i++) { hash += (int)(rep[i] % 13); hash = (hash << 4); } hash += (int)(rep[SIZE-1] % 13); return hash; }
Did you test how often it has collisions?
Best is to switch too Zobrist key but maybe that is a waste of time.
-
- Posts: 759
- Joined: Fri Jan 04, 2013 4:55 pm
- Location: Nice
Re: No Zobrist key
Yes I know the site Daniel but it's the 1000 numbers I can't find in itcdani wrote:http://www.math.sci.hiroshima-u.ac.jp/~ ... T/emt.htmlDaniel Anulliero wrote:Mersenne twister is a good generator and they had 1000 64 bits numbers on the page (I can't find now)
-
- Posts: 1756
- Joined: Tue Apr 19, 2016 6:08 am
- Location: U.S.A
- Full name: Andrew Grant
Re: No Zobrist key
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
-
- Posts: 759
- Joined: Fri Jan 04, 2013 4:55 pm
- Location: Nice
Re: No Zobrist key
Cool Andrew lolAndrewGrant wrote:http://www.math.sci.hiroshima-u.ac.jp/~ ... 64.out.txt
Took me 15 seconds. Come on
You know I am an old man now , with less vision !!
-
- Posts: 859
- Joined: Mon Aug 10, 2009 10:05 pm
- Location: Italy
- Full name: Stefano Gemma
Re: No Zobrist key
This is my last version of my "mystic" code to generate hash, already discussed in another thread:Henk wrote:Properties side to move, castling rights, ep target square are stored inIf you know a much simpler and still effective formula to compute a hash key then that would be better. For I don't like mystic code. Might be I found it somewhere on internet. Can't remember.Code: Select all
rep[7] = board.Other;
Code: Select all
uint64_t _URandS(uint64_t &seed0, uint64_t &seed1)
{
uint64_t x = seed0;
const uint64_t y = seed1;
seed0 = y;
x ^= x << 23; // a
x ^= x >> 17; // b
x ^= y ^ (y >> 26); // c
seed1 = x;
return x + y;
}
uint64_t clsBoard::GetBookHash() const
{
// NB: non cambiare mai questa definizione, per non perdere i libri già compilati!!!
#define HH(a) seeds[0] ^= (a); boBookHash ^= _URandS(seeds[0], seeds[1]);
uint64_t seeds[] = { 0xA10E014701010401ULL, 0x02C070202CDE2ULL };
uint64_t boBookHash = boBits[boAllPieces];
HH(boBits[boKings])
HH(boBits[boQueens])
HH(boBits[boRooks])
HH(boBits[boBishops])
HH(boBits[boKnights])
HH(boBits[boPawns])
HH(color)
HH(boBits[boFriends])
HH(boBits[boEnpPawn] - boBits[boCastlings])
return boBookHash;
}
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
http://www.linformatica.com
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: No Zobrist key
Found it. It was copied from this site.Henk wrote:I use this key for hash table.
And I wonder if it does make my engine slow and if Zobrist key would be much better. But hash table is not used in qSearch.Code: Select all
public Key(IChessBoardBits board) { rep = new ulong[SIZE]; rep[0] = board.Pawns; rep[1] = board.Kings; rep[2] = board.Knights; rep[3] = board.Bishops; rep[4] = board.Rooks; rep[5] = board.Queens; rep[6] = board.WhitePieces; rep[7] = board.Other; } public bool Equals(Key key) { for (int i = 0; i < SIZE; i++) { if (rep[i] != key[i]) return false; } return true; } public override int GetHashCode() { int hash, i; for (hash = i = 0; i < SIZE; ++i) { for (int j = 0; j < 4; j++) { hash += (int)(rep[i] >> (j * 8)); hash += (hash << 10); hash ^= (hash >> 6); } } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; }
[Don't ask how GetHashCode works for it's abracadabra to me now]
https://en.wikipedia.org/wiki/Jenkins_hash_function
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: No Zobrist key
If you calculate the hash for the entire board from scratch in every node it doesn't really matter much what method you use. It will always be orders of magnitude too slow.
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: No Zobrist key
Yes. Zobrist key is better but still don't know if it is worth while to change my code.
By the way I forget a % 256 when extracting a byte.
Might be this is faster:
http://www.isthe.com/chongo/tech/comp/f ... #FNV-param
By the way I forget a % 256 when extracting a byte.
Code: Select all
//Jenkins hash function
public override int GetHashCode()
{
int hash, i;
for (hash = i = 0; i < SIZE; ++i)
{
for (int j = 0; j < 4; j++)
{
var octet = (int)((rep[i] >> (j * 8)) % 256);
hash += octet;
hash += (hash << 10);
hash ^= (hash >> 6);
}
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
http://www.isthe.com/chongo/tech/comp/f ... #FNV-param
Code: Select all
// FNV hash function
public override int GetHashCode()
{
unchecked
{
int hash = (int)2166136261;
for (int i = 0; i < SIZE; ++i)
{
for (int j = 0; j < 4; j++)
{
hash *= 16777619;
var octet = (int)((rep[i] >> (j * 8)) % 256);
hash ^= octet;
}
}
return hash;
}
}