mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Replace Position::copy()
With assignment operator. And fix Position::flip(). No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
c2fc80e5d1
commit
676b2c8435
4 changed files with 16 additions and 30 deletions
|
@ -107,7 +107,7 @@ void benchmark(istringstream& is) {
|
||||||
|
|
||||||
for (size_t i = 0; i < fens.size(); i++)
|
for (size_t i = 0; i < fens.size(); i++)
|
||||||
{
|
{
|
||||||
Position pos(fens[i], false, NULL);
|
Position pos(fens[i], false, Threads.main_thread());
|
||||||
|
|
||||||
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
||||||
|
|
||||||
|
|
|
@ -92,16 +92,15 @@ CheckInfo::CheckInfo(const Position& pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::copy() creates a copy of 'pos'. We want the new born Position
|
/// Position::operator=() creates a copy of 'pos'. We want the new born Position
|
||||||
/// object do not depend on any external data so we detach state pointer from
|
/// object do not depend on any external data so we detach state pointer from
|
||||||
/// the source one.
|
/// the source one.
|
||||||
|
|
||||||
void Position::copy(const Position& pos, Thread* th) {
|
void Position::operator=(const Position& pos) {
|
||||||
|
|
||||||
memcpy(this, &pos, sizeof(Position));
|
memcpy(this, &pos, sizeof(Position));
|
||||||
startState = *st;
|
startState = *st;
|
||||||
st = &startState;
|
st = &startState;
|
||||||
thisThread = th;
|
|
||||||
nodes = 0;
|
nodes = 0;
|
||||||
|
|
||||||
assert(pos_is_ok());
|
assert(pos_is_ok());
|
||||||
|
@ -331,7 +330,7 @@ void Position::print(Move move) const {
|
||||||
|
|
||||||
if (move)
|
if (move)
|
||||||
{
|
{
|
||||||
Position p(*this, thisThread);
|
Position p(*this);
|
||||||
cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
|
cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1540,21 +1539,20 @@ void Position::init() {
|
||||||
|
|
||||||
void Position::flip() {
|
void Position::flip() {
|
||||||
|
|
||||||
// Make a copy of current position before to start changing
|
const Position pos(*this);
|
||||||
const Position pos(*this, thisThread);
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
thisThread = pos.this_thread();
|
|
||||||
|
|
||||||
// Board
|
sideToMove = ~pos.side_to_move();
|
||||||
|
thisThread = pos.this_thread();
|
||||||
|
nodes = pos.nodes_searched();
|
||||||
|
chess960 = pos.is_chess960();
|
||||||
|
startPosPly = pos.startpos_ply_counter();
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
if (!pos.square_empty(s))
|
if (!pos.square_empty(s))
|
||||||
put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
|
put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
|
||||||
|
|
||||||
// Side to move
|
|
||||||
sideToMove = ~pos.side_to_move();
|
|
||||||
|
|
||||||
// Castling rights
|
|
||||||
if (pos.can_castle(WHITE_OO))
|
if (pos.can_castle(WHITE_OO))
|
||||||
set_castle_right(BLACK, ~pos.castle_rook_square(WHITE_OO));
|
set_castle_right(BLACK, ~pos.castle_rook_square(WHITE_OO));
|
||||||
if (pos.can_castle(WHITE_OOO))
|
if (pos.can_castle(WHITE_OOO))
|
||||||
|
@ -1564,22 +1562,14 @@ void Position::flip() {
|
||||||
if (pos.can_castle(BLACK_OOO))
|
if (pos.can_castle(BLACK_OOO))
|
||||||
set_castle_right(WHITE, ~pos.castle_rook_square(BLACK_OOO));
|
set_castle_right(WHITE, ~pos.castle_rook_square(BLACK_OOO));
|
||||||
|
|
||||||
// En passant square
|
|
||||||
if (pos.st->epSquare != SQ_NONE)
|
if (pos.st->epSquare != SQ_NONE)
|
||||||
st->epSquare = ~pos.st->epSquare;
|
st->epSquare = ~pos.st->epSquare;
|
||||||
|
|
||||||
// Checkers
|
|
||||||
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
|
|
||||||
|
|
||||||
// Hash keys
|
|
||||||
st->key = compute_key();
|
st->key = compute_key();
|
||||||
st->pawnKey = compute_pawn_key();
|
st->pawnKey = compute_pawn_key();
|
||||||
st->materialKey = compute_material_key();
|
st->materialKey = compute_material_key();
|
||||||
|
|
||||||
// Incremental scores
|
|
||||||
st->psqScore = compute_psq_score();
|
st->psqScore = compute_psq_score();
|
||||||
|
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
|
||||||
// Material
|
|
||||||
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
|
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
|
||||||
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
|
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
|
||||||
|
|
||||||
|
|
|
@ -84,18 +84,14 @@ struct StateInfo {
|
||||||
/// * A counter for detecting 50 move rule draws.
|
/// * A counter for detecting 50 move rule draws.
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
|
|
||||||
// No copy c'tor or assignment operator allowed
|
|
||||||
Position(const Position&);
|
|
||||||
Position& operator=(const Position&);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Position() {}
|
Position() {}
|
||||||
Position(const Position& p, Thread* t) { copy(p, t); }
|
Position(const Position& p) { *this = p; }
|
||||||
|
Position(const Position& p, Thread* t) { *this = p; thisThread = t; }
|
||||||
Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); }
|
Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); }
|
||||||
|
void operator=(const Position&);
|
||||||
|
|
||||||
// Text input/output
|
// Text input/output
|
||||||
void copy(const Position& pos, Thread* th);
|
|
||||||
void from_fen(const std::string& fen, bool isChess960, Thread* th);
|
void from_fen(const std::string& fen, bool isChess960, Thread* th);
|
||||||
const std::string to_fen() const;
|
const std::string to_fen() const;
|
||||||
void print(Move m = MOVE_NONE) const;
|
void print(Move m = MOVE_NONE) const;
|
||||||
|
|
|
@ -434,7 +434,7 @@ void ThreadsManager::start_searching(const Position& pos, const LimitsType& limi
|
||||||
Signals.stopOnPonderhit = Signals.firstRootMove = false;
|
Signals.stopOnPonderhit = Signals.firstRootMove = false;
|
||||||
Signals.stop = Signals.failedLowAtRoot = false;
|
Signals.stop = Signals.failedLowAtRoot = false;
|
||||||
|
|
||||||
RootPosition.copy(pos, main_thread());
|
RootPosition = pos;
|
||||||
Limits = limits;
|
Limits = limits;
|
||||||
RootMoves.clear();
|
RootMoves.clear();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue