mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Don't copy Position in pretty_pv()
Also let do_setup_move() don't reuse same StateInfo so that we can remove the check about different StateInfo objects before memcpy() in do_move. Functional change due to harmless additionals do_move() / undo_move() steps. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
c89762288b
commit
15153a1de7
6 changed files with 30 additions and 36 deletions
17
src/move.cpp
17
src/move.cpp
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
#include "search.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
/// It is used to write search information to the log file (which is created
|
/// It is used to write search information to the log file (which is created
|
||||||
/// when the UCI parameter "Use Search Log" is "true").
|
/// when the UCI parameter "Use Search Log" is "true").
|
||||||
|
|
||||||
const string pretty_pv(const Position& pos, int time, int depth,
|
const string pretty_pv(Position& pos, int time, int depth,
|
||||||
Value score, ValueType type, Move pv[]) {
|
Value score, ValueType type, Move pv[]) {
|
||||||
|
|
||||||
const int64_t K = 1000;
|
const int64_t K = 1000;
|
||||||
|
@ -187,13 +188,12 @@ const string pretty_pv(const Position& pos, int time, int depth,
|
||||||
const size_t maxLength = 80 - startColumn;
|
const size_t maxLength = 80 - startColumn;
|
||||||
const string lf = string("\n") + string(startColumn, ' ');
|
const string lf = string("\n") + string(startColumn, ' ');
|
||||||
|
|
||||||
StateInfo st;
|
StateInfo state[PLY_MAX_PLUS_2], *st = state;
|
||||||
|
Move* m = pv;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
string san;
|
string san;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
Position p(pos, pos.thread());
|
|
||||||
|
|
||||||
// First print depth, score, time and searched nodes...
|
// First print depth, score, time and searched nodes...
|
||||||
s << std::setw(2) << depth
|
s << std::setw(2) << depth
|
||||||
<< (type == VALUE_TYPE_LOWER ? " >" : type == VALUE_TYPE_UPPER ? " <" : " ")
|
<< (type == VALUE_TYPE_LOWER ? " >" : type == VALUE_TYPE_UPPER ? " <" : " ")
|
||||||
|
@ -208,9 +208,9 @@ const string pretty_pv(const Position& pos, int time, int depth,
|
||||||
s << std::setw(7) << pos.nodes_searched() / M << " M ";
|
s << std::setw(7) << pos.nodes_searched() / M << " M ";
|
||||||
|
|
||||||
// ...then print the full PV line in short algebraic notation
|
// ...then print the full PV line in short algebraic notation
|
||||||
for (Move* m = pv; *m != MOVE_NONE; m++)
|
while (*m != MOVE_NONE)
|
||||||
{
|
{
|
||||||
san = move_to_san(p, *m);
|
san = move_to_san(pos, *m);
|
||||||
length += san.length() + 1;
|
length += san.length() + 1;
|
||||||
|
|
||||||
if (length > maxLength)
|
if (length > maxLength)
|
||||||
|
@ -220,9 +220,12 @@ const string pretty_pv(const Position& pos, int time, int depth,
|
||||||
}
|
}
|
||||||
s << san << ' ';
|
s << san << ' ';
|
||||||
|
|
||||||
p.do_move(*m, st);
|
pos.do_move(*m++, *st++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore original position before to leave
|
||||||
|
while (m != pv) pos.undo_move(*--m);
|
||||||
|
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,6 @@ class Position;
|
||||||
extern const std::string move_to_uci(Move m, bool chess960);
|
extern const std::string move_to_uci(Move m, bool chess960);
|
||||||
extern Move move_from_uci(const Position& pos, const std::string& str);
|
extern Move move_from_uci(const Position& pos, const std::string& str);
|
||||||
extern const std::string move_to_san(Position& pos, Move m);
|
extern const std::string move_to_san(Position& pos, Move m);
|
||||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, Value score, ValueType type, Move pv[]);
|
extern const std::string pretty_pv(Position& pos, int time, int depth, Value score, ValueType type, Move pv[]);
|
||||||
|
|
||||||
#endif // !defined(MOVE_H_INCLUDED)
|
#endif // !defined(MOVE_H_INCLUDED)
|
||||||
|
|
|
@ -776,7 +776,9 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
|
||||||
/// It should be used when setting up a position on board.
|
/// It should be used when setting up a position on board.
|
||||||
/// You can't undo the move.
|
/// You can't undo the move.
|
||||||
|
|
||||||
void Position::do_setup_move(Move m, StateInfo& newSt) {
|
void Position::do_setup_move(Move m) {
|
||||||
|
|
||||||
|
StateInfo newSt;
|
||||||
|
|
||||||
do_move(m, newSt);
|
do_move(m, newSt);
|
||||||
|
|
||||||
|
@ -787,6 +789,10 @@ void Position::do_setup_move(Move m, StateInfo& newSt) {
|
||||||
|
|
||||||
// Update the number of plies played from the starting position
|
// Update the number of plies played from the starting position
|
||||||
startPosPlyCounter++;
|
startPosPlyCounter++;
|
||||||
|
|
||||||
|
// Our StateInfo newSt is about going out of scope so copy
|
||||||
|
// its content inside pos before it disappears.
|
||||||
|
detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Position::do_move() makes a move, and saves all information necessary
|
/// Position::do_move() makes a move, and saves all information necessary
|
||||||
|
@ -803,6 +809,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
assert(&newSt != st);
|
||||||
|
|
||||||
nodes++;
|
nodes++;
|
||||||
Key key = st->key;
|
Key key = st->key;
|
||||||
|
@ -818,7 +825,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
Value npMaterial[2];
|
Value npMaterial[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
if (&newSt != st)
|
|
||||||
memcpy(&newSt, st, sizeof(ReducedStateInfo));
|
memcpy(&newSt, st, sizeof(ReducedStateInfo));
|
||||||
|
|
||||||
newSt.previous = st;
|
newSt.previous = st;
|
||||||
|
|
|
@ -222,8 +222,7 @@ public:
|
||||||
bool square_is_weak(Square s, Color c) const;
|
bool square_is_weak(Square s, Color c) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void detach();
|
void do_setup_move(Move m);
|
||||||
void do_setup_move(Move m, StateInfo& St);
|
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
|
@ -278,6 +277,7 @@ private:
|
||||||
|
|
||||||
// Initialization helper functions (used while setting up a position)
|
// Initialization helper functions (used while setting up a position)
|
||||||
void clear();
|
void clear();
|
||||||
|
void detach();
|
||||||
void put_piece(Piece p, Square s);
|
void put_piece(Piece p, Square s);
|
||||||
void do_allow_oo(Color c);
|
void do_allow_oo(Color c);
|
||||||
void do_allow_ooo(Color c);
|
void do_allow_ooo(Color c);
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace {
|
||||||
|
|
||||||
void extract_pv_from_tt(Position& pos);
|
void extract_pv_from_tt(Position& pos);
|
||||||
void insert_pv_in_tt(Position& pos);
|
void insert_pv_in_tt(Position& pos);
|
||||||
std::string pv_info_to_uci(const Position& pos, Value alpha, Value beta, int pvLine = 0);
|
std::string pv_info_to_uci(Position& pos, Value alpha, Value beta, int pvLine = 0);
|
||||||
|
|
||||||
int64_t nodes;
|
int64_t nodes;
|
||||||
Value pv_score;
|
Value pv_score;
|
||||||
|
@ -2633,7 +2633,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
// formatted according to UCI specification and eventually writes the info
|
// formatted according to UCI specification and eventually writes the info
|
||||||
// to a log file. It is called at each iteration or after a new pv is found.
|
// to a log file. It is called at each iteration or after a new pv is found.
|
||||||
|
|
||||||
std::string RootMove::pv_info_to_uci(const Position& pos, Value alpha, Value beta, int pvLine) {
|
std::string RootMove::pv_info_to_uci(Position& pos, Value alpha, Value beta, int pvLine) {
|
||||||
|
|
||||||
std::stringstream s, l;
|
std::stringstream s, l;
|
||||||
Move* m = pv;
|
Move* m = pv;
|
||||||
|
|
27
src/uci.cpp
27
src/uci.cpp
|
@ -140,7 +140,7 @@ namespace {
|
||||||
|
|
||||||
void set_position(Position& pos, UCIParser& up) {
|
void set_position(Position& pos, UCIParser& up) {
|
||||||
|
|
||||||
string token;
|
string fen, token;
|
||||||
|
|
||||||
if (!(up >> token) || (token != "startpos" && token != "fen"))
|
if (!(up >> token) || (token != "startpos" && token != "fen"))
|
||||||
return;
|
return;
|
||||||
|
@ -148,34 +148,19 @@ namespace {
|
||||||
if (token == "startpos")
|
if (token == "startpos")
|
||||||
{
|
{
|
||||||
pos.from_fen(StartPositionFEN, false);
|
pos.from_fen(StartPositionFEN, false);
|
||||||
if (!(up >> token))
|
up >> token; // Consume "moves" token
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else // fen
|
else // fen
|
||||||
{
|
{
|
||||||
string fen;
|
|
||||||
while (up >> token && token != "moves")
|
while (up >> token && token != "moves")
|
||||||
{
|
fen += token + string(" ");
|
||||||
fen += token;
|
|
||||||
fen += ' ';
|
|
||||||
}
|
|
||||||
pos.from_fen(fen, Options["UCI_Chess960"].value<bool>());
|
pos.from_fen(fen, Options["UCI_Chess960"].value<bool>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token != "moves")
|
// Parse move list (if any)
|
||||||
return;
|
|
||||||
|
|
||||||
// Parse optional move list
|
|
||||||
Move move;
|
|
||||||
StateInfo st;
|
|
||||||
while (up >> token)
|
while (up >> token)
|
||||||
{
|
pos.do_setup_move(move_from_uci(pos, token));
|
||||||
move = move_from_uci(pos, token);
|
|
||||||
pos.do_setup_move(move, st);
|
|
||||||
}
|
|
||||||
// Our StateInfo st is about going out of scope so copy
|
|
||||||
// its content inside pos before it disappears.
|
|
||||||
pos.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue