]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Let rkiss.h to follow SF coding style
[stockfish] / src / position.cpp
index 23ffbaa46593c8dad832a7ee6ebd0973a1820228..ae63f26343f5026d14dbe989cf65f3e53415546a 100644 (file)
 #include <sstream>
 
 #include "bitcount.h"
-#include "mersenne.h"
 #include "movegen.h"
 #include "movepick.h"
 #include "position.h"
 #include "psqtab.h"
+#include "rkiss.h"
 #include "san.h"
 #include "tt.h"
 #include "ucioption.h"
@@ -121,13 +121,12 @@ CheckInfo::CheckInfo(const Position& pos) {
 /// or the FEN string, we want the new born Position object do not depend
 /// on any external data so we detach state pointer from the source one.
 
-Position::Position(int th) : threadID(th) {}
-
 Position::Position(const Position& pos, int th) {
 
   memcpy(this, &pos, sizeof(Position));
   detach(); // Always detach() in copy c'tor to avoid surprises
   threadID = th;
+  nodes = 0;
 }
 
 Position::Position(const string& fen, int th) {
@@ -752,6 +751,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   assert(is_ok());
   assert(move_is_ok(m));
 
+  nodes++;
   Key key = st->key;
 
   // Copy some fields of old state to our new StateInfo object except the
@@ -765,7 +765,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
     Value npMaterial[2];
   };
 
-  memcpy(&newSt, st, sizeof(ReducedStateInfo));
+  if (&newSt != st)
+      memcpy(&newSt, st, sizeof(ReducedStateInfo));
+
   newSt.previous = st;
   st = &newSt;
 
@@ -1477,6 +1479,7 @@ void Position::clear() {
   memset(st, 0, sizeof(StateInfo));
   st->epSquare = SQ_NONE;
   startPosPlyCounter = 0;
+  nodes = 0;
 
   memset(byColorBB,  0, sizeof(Bitboard) * 2);
   memset(byTypeBB,   0, sizeof(Bitboard) * 8);
@@ -1756,19 +1759,20 @@ bool Position::has_mate_threat() {
 
 void Position::init_zobrist() {
 
+  RKISS RKiss;
   int i,j, k;
 
   for (i = 0; i < 2; i++) for (j = 0; j < 8; j++) for (k = 0; k < 64; k++)
-      zobrist[i][j][k] = Key(genrand_int64());
+      zobrist[i][j][k] = RKiss.rand<Key>();
 
   for (i = 0; i < 64; i++)
-      zobEp[i] = Key(genrand_int64());
+      zobEp[i] = RKiss.rand<Key>();
 
   for (i = 0; i < 16; i++)
-      zobCastle[i] = Key(genrand_int64());
+      zobCastle[i] = RKiss.rand<Key>();
 
-  zobSideToMove = Key(genrand_int64());
-  zobExclusion  = Key(genrand_int64());
+  zobSideToMove = RKiss.rand<Key>();
+  zobExclusion  = RKiss.rand<Key>();
 }