X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.cpp;h=6abef5b47bcb42c764901fdc0cb7a871d7e80039;hb=b36900ef44044e9ab96637c9da7a4d7ea5b055d9;hp=be9ece11630d288dc264b019ec426b6e3e698d05;hpb=5254ca22f3dcfa3bd1993d85e57d68ba1a4f4f34;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index be9ece11..6abef5b4 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -31,11 +31,11 @@ #include #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" @@ -44,9 +44,54 @@ using std::string; using std::cout; using std::endl; -static inline bool isZero(char c) { return c == '0'; } -struct PieceLetters : public std::map { +//// +//// Position's static data definitions +//// + +Key Position::zobrist[2][8][64]; +Key Position::zobEp[64]; +Key Position::zobCastle[16]; +Key Position::zobSideToMove; +Key Position::zobExclusion; + +Score Position::PieceSquareTable[16][64]; + +// Material values arrays, indexed by Piece +const Value Position::PieceValueMidgame[17] = { + VALUE_ZERO, + PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, + RookValueMidgame, QueenValueMidgame, VALUE_ZERO, + VALUE_ZERO, VALUE_ZERO, + PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, + RookValueMidgame, QueenValueMidgame +}; + +const Value Position::PieceValueEndgame[17] = { + VALUE_ZERO, + PawnValueEndgame, KnightValueEndgame, BishopValueEndgame, + RookValueEndgame, QueenValueEndgame, VALUE_ZERO, + VALUE_ZERO, VALUE_ZERO, + PawnValueEndgame, KnightValueEndgame, BishopValueEndgame, + RookValueEndgame, QueenValueEndgame +}; + +// Material values array used by SEE, indexed by PieceType +const Value Position::seeValues[] = { + VALUE_ZERO, + PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, + RookValueMidgame, QueenValueMidgame, QueenValueMidgame*10 +}; + + +namespace { + + // Bonus for having the side to move (modified by Joona Kiiski) + const Score TempoValue = make_score(48, 22); + + bool isZero(char c) { return c == '0'; } + + struct PieceLetters : public std::map { PieceLetters() { @@ -69,36 +114,11 @@ struct PieceLetters : public std::map { assert(false); return 0; } -}; - - -//// -//// Constants and variables -//// - -/// Bonus for having the side to move (modified by Joona Kiiski) - -static const Score TempoValue = make_score(48, 22); - - -Key Position::zobrist[2][8][64]; -Key Position::zobEp[64]; -Key Position::zobCastle[16]; -Key Position::zobSideToMove; -Key Position::zobExclusion; - -Score Position::PieceSquareTable[16][64]; - -static PieceLetters pieceLetters; - -// Material values used by SEE, indexed by PieceType -const Value Position::seeValues[] = { - VALUE_ZERO, PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, - RookValueMidgame, QueenValueMidgame, QueenValueMidgame*10 -}; + } pieceLetters; +} -/// Constructors +/// CheckInfo c'tor CheckInfo::CheckInfo(const Position& pos) { @@ -121,13 +141,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 +771,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 @@ -1479,6 +1499,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); @@ -1758,19 +1779,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(); for (i = 0; i < 64; i++) - zobEp[i] = Key(genrand_int64()); + zobEp[i] = RKiss.rand(); for (i = 0; i < 16; i++) - zobCastle[i] = Key(genrand_int64()); + zobCastle[i] = RKiss.rand(); - zobSideToMove = Key(genrand_int64()); - zobExclusion = Key(genrand_int64()); + zobSideToMove = RKiss.rand(); + zobExclusion = RKiss.rand(); }