#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"
/// 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) {
/// Position::print() prints an ASCII representation of the position to
-/// the standard output. If a move is given then also the san is print.
+/// the standard output. If a move is given then also the san is printed.
void Position::print(Move move) const {
assert(move_is_ok(m));
assert(square_is_ok(s));
+ Bitboard occ, xray;
Square f = move_from(m), t = move_to(m);
assert(square_is_occupied(f));
return true;
// Move the piece and scan for X-ray attacks behind it
- Bitboard occ = occupied_squares();
- Color us = color_of_piece_on(f);
- clear_bit(&occ, f);
- set_bit(&occ, t);
- Bitboard xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN))
- |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN))) & pieces_of_color(us);
+ occ = occupied_squares();
+ do_move_bb(&occ, make_move_bb(f, t));
+ xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN))
+ |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN)))
+ & pieces_of_color(color_of_piece_on(f));
// If we have attacks we need to verify that are caused by our move
// and are not already existent ones.
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
Value npMaterial[2];
};
- memcpy(&newSt, st, sizeof(ReducedStateInfo));
+ if (&newSt != st)
+ memcpy(&newSt, st, sizeof(ReducedStateInfo));
+
newSt.previous = st;
st = &newSt;
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);
Key Position::compute_key() const {
- Key result = Key(0ULL);
+ Key result = 0;
for (Square s = SQ_A1; s <= SQ_H8; s++)
if (square_is_occupied(s))
Key Position::compute_pawn_key() const {
- Key result = Key(0ULL);
+ Key result = 0;
Bitboard b;
Square s;
Key Position::compute_material_key() const {
- Key result = Key(0ULL);
+ Key result = 0;
for (Color c = WHITE; c <= BLACK; c++)
for (PieceType pt = PAWN; pt <= QUEEN; pt++)
{
bool Position::is_mate() const {
- MoveStack moves[256];
+ MoveStack moves[MOVES_MAX];
return is_check() && (generate_moves(*this, moves) == moves);
}
bool Position::has_mate_threat() {
- MoveStack mlist[256], *last, *cur;
+ MoveStack mlist[MOVES_MAX], *last, *cur;
StateInfo st1, st2;
bool mateFound = false;
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>();
}