xiphos 64 bit random number

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

xiphos 64 bit random number

Post by pedrox »

I have seen the 64 bit random number of xiphos and I wanted to try it, but I have found that it generates different pv for the same position even with 1 thread (the same for my engine).

xiphos 1 thread.

first run

FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Xiphos-0.4.24-w64-sse:
1 00:00 20 20k +0,82 1.d4
2 00:00 52 26k +0,92 1.e3 h5
3 00:00 88 44k +1,11 1.e3 h6 2.Nf3
4 00:00 139 70k +1,13 1.e3 g6 2.Nf3 h5
5 00:00 794 265k +0,37 1.d4 e6 2.Nf3 d5 3.Nc3
6 00:00 1k 357k +0,14 1.d4 e6 2.Nf3 Nf6 3.Nc3 d5
7 00:00 2k 360k +0,29 1.d4 e6 2.Nf3 Nf6 3.Nc3 d5 4.e3
8 00:00 3k 524k +0,10 1.d4 e6 2.Nf3 Nc6 3.e3 d5 4.Nc3 Nf6
9 00:00 8k 732k +0,06 1.d4 Nf6 2.h3 d5 3.Nf3 Nc6 4.Nc3 e6 5.e3
10 00:00 23k 899k +0,31 1.e4 d5 2.exd5 c6 3.dxc6 Nxc6 4.b3 e5 5.Nc3 Nf6 6.Nf3
11 00:00 28k 943k +0,31 1.e4 d5 2.exd5 c6 3.dxc6 Nxc6 4.b3 e5 5.Nc3 Nf6 6.Nf3
12 00:00 49k 1.012k +0,33 1.e4 d5 2.exd5 c6 3.c4 cxd5 4.d4 e6 5.Nc3 Nc6 6.Nf3 Nf6
13 00:00 201k 1.196k +0,15 1.d4 Nf6 2.c4 e6 3.Nc3 d5 4.Bg5 Bb4 5.e3 0-0 6.Nf3 Bxc3+ 7.bxc3
14 00:00 271k 1.206k +0,12 1.d4 Nf6 2.c4 e6 3.Nc3 d5 4.Bg5 Bb4 5.e3 0-0 6.Nf3 Bxc3+ 7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xf6 8.Bd3 dxc4
17 00:00 1.179k 1.224k +0,16 1.d4 d5 2.Nf3 e6 3.e3 c5 4.c4 Nf6 5.Nc3 Nc6 6.Be2 cxd4 7.exd4 Be7 8.a3 0-0 9.0-0 dxc4
18 00:01 1.716k 1.242k +0,19 1.d4 d5 2.Nf3 e6 3.c4 Nf6 4.e3 Bd6 5.cxd5 exd5 6.Nc3 Bd7 7.Bd3 h6 8.h3 0-0 9.0-0 Nc6 10.a3
19 00:01 2.488k 1.245k +0,19 1.d4 d5 2.Nf3 e6 3.c4 Nf6 4.Nc3 Be7 5.cxd5 exd5 6.Bf4 0-0 7.e3 Ne4 8.Bd3 Bb4 9.Rc1 Bxc3+ 10.bxc3 Bf5
20 00:02 3.696k 1.246k +0,20 1.d4 d5 2.Nf3 e6 3.c4 Nf6 4.Nc3 Be7 5.cxd5 exd5 6.Bf4 Nc6 7.e3 0-0 8.Be2 Ne4 9.0-0 Nxc3 10.bxc3 Bf5
21 00:05 6.722k 1.189k +0,23 1.d4 d5 2.Nf3 Nf6 3.c4 e6 4.Nc3 h6 5.e3 c5 6.cxd5 exd5 7.Be2 Be7 8.dxc5 Bxc5 9.a3 0-0 10.0-0 Bf5 11.Bd2 Nc6
22 00:12 13.809k 1.150k +0,21 1.d4 d5 2.Nf3 Nf6 3.c4 e6 4.Nc3 h6 5.e3 c5 6.cxd5 exd5 7.Be2 Be7 8.dxc5 0-0 9.0-0 Bxc5 10.a3 Re8 11.h3 Nc6
22 00:12 14.790k 1.147k +0,21 1.d4 d5 2.Nf3 Nf6 3.c4 e6 4.Nc3 h6 5.e3 c5 6.cxd5 exd5 7.Be2 Be7 8.dxc5 0-0 9.0-0 Bxc5 10.a3 Re8 11.h3 Nc6
Best move: d4, Value: +0,21, Depth: 22, Time: 00:12,948, 14.790.190 Nodes, 1.147 kN/sec.

pv is different from ply 13

64 bit random number used:

uint64_t rand64()
{
int i;
uint64_t r;

r = 0;
for (i = 0; i < 8; i ++)
r |= (uint64_t)(rand() & 0xff) << (i << 3);
return r;
}

This is a bug?
This is a problem? I do not think it affect the strength
maybe used to have more variety with pv for a lazy smp? (I do not know how xiphos does smp and I really do not know how smp works)
D Sceviour
Posts: 570
Joined: Mon Jul 20, 2015 5:06 pm

Re: xiphos 64 bit random number

Post by D Sceviour »

pedrox wrote: Thu Feb 28, 2019 2:21 pm I have seen the 64 bit random number of xiphos and I wanted to try it, but I have found that it generates different pv for the same position even with 1 thread (the same for my engine).

This is a bug?
No, that gives it some style. Random hash collisions and the random moves it generates might give it some advantage over the NN engines that are trying to predict its moves!
This is a problem? I do not think it affect the strength.
It does not effect overall strength. However, Schooner uses the standard polyglot keys. This saves space, makes debugging a lot easier, and keeps the hash system ready for polyglot book immediately.
(I do not know how xiphos does smp and I really do not know how smp works)
Xiphos uses shared hash table threading with staggered aspiration depths (taken from Ethereal). Hash keys probably have no effect on this.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: xiphos 64 bit random number

Post by xr_a_y »

Just recompile with a fixed seed.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: xiphos 64 bit random number

Post by Sven »

pedrox wrote: Thu Feb 28, 2019 2:21 pm

Code: Select all

uint64_t rand64()
{
  int i;
  uint64_t r;

  r = 0;
  for (i = 0; i < 8; i ++)
    r |= (uint64_t)(rand() & 0xff) << (i << 3);
  return r;
}
This is a bug?
The implementation of rand64() looks correct, the 64-bit return value "r" is composed from 8 pseudo-random numbers of 8 bit each, shifted correctly to the expected bit positions. But the implementation of reset_hash_key() in hash.c uses srand(time(0)) so zobrist keys are not the same for each program run and thus the results are not reproducible. Typically the set of zobrist keys should be fixed, either by using fixed constants or through a fixed random seed.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)