X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=063233111dea59066bffb702c3597ec31ca7b87f;hp=b8f7807b68aa5eb225a5b3aabcee248e6c5f06fb;hb=72c7595f8ac72c7831ee319b8b0bc46404c5fc27;hpb=b870f5a091793ea423de78e74f5652b9307cfcbd diff --git a/src/position.cpp b/src/position.cpp index b8f7807b..06323311 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -190,7 +190,7 @@ void Position::from_fen(const std::string& fen) { i++; // En passant square - if ( i < fen.length() - 2 + if ( i <= fen.length() - 2 && (fen[i] >= 'a' && fen[i] <= 'h') && (fen[i+1] == '3' || fen[i+1] == '6')) st->epSquare = square_from_string(fen.substr(i, 2)); @@ -755,7 +755,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { st->capture = type_of_piece_on(to); if (st->capture) - do_capture_move(m, st->capture, them, to); + do_capture_move(st->capture, them, to); // Move the piece clear_bit(&(byColorBB[us]), from); @@ -848,7 +848,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { /// Position::do_capture_move() is a private method used to update captured /// piece info. It is called from the main Position::do_move function. -void Position::do_capture_move(Move m, PieceType capture, Color them, Square to) { +void Position::do_capture_move(PieceType capture, Color them, Square to) { assert(capture != KING); @@ -867,8 +867,6 @@ void Position::do_capture_move(Move m, PieceType capture, Color them, Square to) st->mgValue -= pst(them, capture, to); st->egValue -= pst(them, capture, to); - assert(!move_promotion(m) || capture != PAWN); - // Update material if (capture != PAWN) npMaterial[them] -= piece_value_midgame(capture); @@ -1010,7 +1008,7 @@ void Position::do_promotion_move(Move m) { st->capture = type_of_piece_on(to); if (st->capture) - do_capture_move(m, st->capture, them, to); + do_capture_move(st->capture, them, to); // Remove pawn clear_bit(&(byColorBB[us]), from); @@ -1618,7 +1616,7 @@ int Position::see(Square from, Square to) const { // Remove the attacker we just found from the 'attackers' bitboard, // and scan for new X-ray attacks behind the attacker. b = attackers & pieces_of_color_and_type(c, pt); - occ ^= (b & -b); + occ ^= (b & (~b + 1)); attackers |= (rook_attacks_bb(to, occ) & rooks_and_queens()) | (bishop_attacks_bb(to, occ) & bishops_and_queens()); @@ -1960,26 +1958,26 @@ bool Position::has_mate_threat(Color c) { void Position::init_zobrist() { - for (int i = 0; i < 2; i++) - for (int j = 0; j < 8; j++) - for (int k = 0; k < 64; k++) - zobrist[i][j][k] = Key(genrand_int64()); + for(Piece p = WP; p <= BK; p++) + for(Square s = SQ_A1; s <= SQ_H8; s++) + zobrist[color_of_piece(p)][type_of_piece(p)][s] = genrand_int64(); - for (int i = 0; i < 64; i++) - zobEp[i] = Key(genrand_int64()); + zobEp[0] = 0ULL; + for(int i = 1; i < 64; i++) + zobEp[i] = genrand_int64(); - for (int i = 0; i < 16; i++) - zobCastle[i] = genrand_int64(); + for(int i = 15; i >= 0; i--) + zobCastle[(i&8) | (i&1) | ((i&2) << 1) | ((i&4) >> 1)] = genrand_int64(); zobSideToMove = genrand_int64(); for (int i = 0; i < 2; i++) for (int j = 0; j < 8; j++) for (int k = 0; k < 16; k++) - zobMaterial[i][j][k] = (k > 0)? Key(genrand_int64()) : Key(0LL); + zobMaterial[i][j][k] = (k > 0)? genrand_int64() : 0LL; for (int i = 0; i < 16; i++) - zobMaterial[0][KING][i] = zobMaterial[1][KING][i] = Key(0ULL); + zobMaterial[0][KING][i] = zobMaterial[1][KING][i] = 0ULL; }