mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-24 19:16:49 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ee0842c81 | ||
|
|
e59ff49a55 | ||
|
|
225dcfeeb7 | ||
|
|
8dd01fda12 | ||
|
|
18cd83a380 | ||
|
|
fd2b3df770 | ||
|
|
da948cc94e | ||
|
|
e49b21eacb | ||
|
|
60bc30275d | ||
|
|
32dfaa56b0 | ||
|
|
3701a8e57d |
@@ -50,7 +50,7 @@ using namespace std;
|
||||
/// Version number. If this is left empty, the current date (in the format
|
||||
/// YYMMDD) is used as a version number.
|
||||
|
||||
static const string EngineVersion = "1.5";
|
||||
static const string EngineVersion = "1.5.1";
|
||||
static const string AppName = "Stockfish";
|
||||
static const string AppTag = "";
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class PawnInfo {
|
||||
friend class PawnInfoTable;
|
||||
|
||||
public:
|
||||
PawnInfo() : key(0) { clear(); }
|
||||
PawnInfo() { clear(); }
|
||||
|
||||
Value mg_value() const;
|
||||
Value eg_value() const;
|
||||
|
||||
@@ -985,17 +985,22 @@ void Position::do_castle_move(Move m) {
|
||||
rto = relative_square(us, SQ_D1);
|
||||
}
|
||||
|
||||
// Move the pieces
|
||||
Bitboard kmove_bb = make_move_bb(kfrom, kto);
|
||||
do_move_bb(&(byColorBB[us]), kmove_bb);
|
||||
do_move_bb(&(byTypeBB[KING]), kmove_bb);
|
||||
do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
Bitboard rmove_bb = make_move_bb(rfrom, rto);
|
||||
do_move_bb(&(byColorBB[us]), rmove_bb);
|
||||
do_move_bb(&(byTypeBB[ROOK]), rmove_bb);
|
||||
do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
// Remove pieces from source squares:
|
||||
clear_bit(&(byColorBB[us]), kfrom);
|
||||
clear_bit(&(byTypeBB[KING]), kfrom);
|
||||
clear_bit(&(byTypeBB[0]), kfrom); // HACK: byTypeBB[0] == occupied squares
|
||||
clear_bit(&(byColorBB[us]), rfrom);
|
||||
clear_bit(&(byTypeBB[ROOK]), rfrom);
|
||||
clear_bit(&(byTypeBB[0]), rfrom); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// Put pieces on destination squares:
|
||||
set_bit(&(byColorBB[us]), kto);
|
||||
set_bit(&(byTypeBB[KING]), kto);
|
||||
set_bit(&(byTypeBB[0]), kto); // HACK: byTypeBB[0] == occupied squares
|
||||
set_bit(&(byColorBB[us]), rto);
|
||||
set_bit(&(byTypeBB[ROOK]), rto);
|
||||
set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// Update board array
|
||||
Piece king = piece_of_color_and_type(us, KING);
|
||||
Piece rook = piece_of_color_and_type(us, ROOK);
|
||||
@@ -1106,6 +1111,7 @@ void Position::undo_move(Move m) {
|
||||
pieceList[us][PAWN][index[to]] = to;
|
||||
}
|
||||
|
||||
|
||||
// Put the piece back at the source square
|
||||
Bitboard move_bb = make_move_bb(to, from);
|
||||
do_move_bb(&(byColorBB[us]), move_bb);
|
||||
@@ -1183,17 +1189,22 @@ void Position::undo_castle_move(Move m) {
|
||||
|
||||
assert(piece_on(kto) == piece_of_color_and_type(us, KING));
|
||||
assert(piece_on(rto) == piece_of_color_and_type(us, ROOK));
|
||||
|
||||
// Put the pieces back at the source square
|
||||
Bitboard kmove_bb = make_move_bb(kto, kfrom);
|
||||
do_move_bb(&(byColorBB[us]), kmove_bb);
|
||||
do_move_bb(&(byTypeBB[KING]), kmove_bb);
|
||||
do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
Bitboard rmove_bb = make_move_bb(rto, rfrom);
|
||||
do_move_bb(&(byColorBB[us]), rmove_bb);
|
||||
do_move_bb(&(byTypeBB[ROOK]), rmove_bb);
|
||||
do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// Remove pieces from destination squares:
|
||||
clear_bit(&(byColorBB[us]), kto);
|
||||
clear_bit(&(byTypeBB[KING]), kto);
|
||||
clear_bit(&(byTypeBB[0]), kto); // HACK: byTypeBB[0] == occupied squares
|
||||
clear_bit(&(byColorBB[us]), rto);
|
||||
clear_bit(&(byTypeBB[ROOK]), rto);
|
||||
clear_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// Put pieces on source squares:
|
||||
set_bit(&(byColorBB[us]), kfrom);
|
||||
set_bit(&(byTypeBB[KING]), kfrom);
|
||||
set_bit(&(byTypeBB[0]), kfrom); // HACK: byTypeBB[0] == occupied squares
|
||||
set_bit(&(byColorBB[us]), rfrom);
|
||||
set_bit(&(byTypeBB[ROOK]), rfrom);
|
||||
set_bit(&(byTypeBB[0]), rfrom); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// Update board
|
||||
board[rto] = board[kto] = EMPTY;
|
||||
|
||||
@@ -325,14 +325,15 @@ const string line_to_san(const Position& pos, Move line[], int startColumn, bool
|
||||
/// when the UCI parameter "Use Search Log" is "true").
|
||||
|
||||
const string pretty_pv(const Position& pos, int time, int depth,
|
||||
uint64_t nodes, Value score, Move pv[]) {
|
||||
uint64_t nodes, Value score, ValueType type, Move pv[]) {
|
||||
std::stringstream s;
|
||||
|
||||
// Depth
|
||||
s << std::setw(2) << depth << " ";
|
||||
|
||||
// Score
|
||||
s << std::setw(8) << score_string(score);
|
||||
s << ((type == VALUE_TYPE_LOWER)? ">" : ((type == VALUE_TYPE_UPPER)? "<" : " "));
|
||||
s << std::setw(7) << score_string(score);
|
||||
|
||||
// Time
|
||||
s << std::setw(8) << time_string(time) << " ";
|
||||
|
||||
@@ -39,6 +39,6 @@
|
||||
extern const std::string move_to_san(const Position& pos, Move m);
|
||||
extern Move move_from_san(const Position& pos, const std::string& str);
|
||||
extern const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines);
|
||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, Move pv[]);
|
||||
extern const std::string pretty_pv(const Position& pos, int time, int depth, uint64_t nodes, Value score, ValueType type, Move pv[]);
|
||||
|
||||
#endif // !defined(SAN_H_INCLUDED)
|
||||
|
||||
@@ -299,6 +299,7 @@ namespace {
|
||||
void ponderhit();
|
||||
void print_current_line(SearchStack ss[], int ply, int threadID);
|
||||
void wait_for_stop_or_ponderhit();
|
||||
void init_ss_array(SearchStack ss[]);
|
||||
|
||||
void idle_loop(int threadID, SplitPoint* waitSp);
|
||||
void init_split_point_stack();
|
||||
@@ -445,7 +446,8 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
if (movesToGo == 1)
|
||||
{
|
||||
MaxSearchTime = myTime / 2;
|
||||
AbsoluteMaxSearchTime = Min(myTime / 2, myTime - 500);
|
||||
AbsoluteMaxSearchTime =
|
||||
(myTime > 3000)? (myTime - 500) : ((myTime * 3) / 4);
|
||||
} else {
|
||||
MaxSearchTime = myTime / Min(movesToGo, 20);
|
||||
AbsoluteMaxSearchTime = Min((4 * myTime) / movesToGo, myTime / 3);
|
||||
@@ -469,6 +471,10 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||
NodesBetweenPolls = Min(MaxNodes, 30000);
|
||||
InfiniteSearch = true; // HACK
|
||||
}
|
||||
else if (myTime && myTime < 1000)
|
||||
NodesBetweenPolls = 1000;
|
||||
else if (myTime && myTime < 5000)
|
||||
NodesBetweenPolls = 5000;
|
||||
else
|
||||
NodesBetweenPolls = 30000;
|
||||
|
||||
@@ -636,11 +642,7 @@ namespace {
|
||||
// Initialize
|
||||
TT.new_search();
|
||||
H.clear();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ss[i].init(i);
|
||||
ss[i].initKillers();
|
||||
}
|
||||
init_ss_array(ss);
|
||||
IterationInfo[1] = IterationInfoType(rml.get_move_score(0), rml.get_move_score(0));
|
||||
Iteration = 1;
|
||||
|
||||
@@ -947,7 +949,7 @@ namespace {
|
||||
// Update PV
|
||||
rml.set_move_score(i, value);
|
||||
update_pv(ss, 0);
|
||||
TT.extract_pv(pos, ss[0].pv);
|
||||
TT.extract_pv(pos, ss[0].pv, PLY_MAX);
|
||||
rml.set_move_pv(i, ss[0].pv);
|
||||
|
||||
if (MultiPV == 1)
|
||||
@@ -974,7 +976,10 @@ namespace {
|
||||
std::cout << std::endl;
|
||||
|
||||
if (UseLogFile)
|
||||
LogFile << pretty_pv(pos, current_search_time(), Iteration, nodes_searched(), value, ss[0].pv)
|
||||
LogFile << pretty_pv(pos, current_search_time(), Iteration, nodes_searched(), value,
|
||||
((value >= beta)? VALUE_TYPE_LOWER
|
||||
: ((value <= alpha)? VALUE_TYPE_UPPER : VALUE_TYPE_EXACT)),
|
||||
ss[0].pv)
|
||||
<< std::endl;
|
||||
|
||||
if (value > alpha)
|
||||
@@ -1961,6 +1966,7 @@ namespace {
|
||||
// Find a quick score for the move
|
||||
StateInfo st;
|
||||
SearchStack ss[PLY_MAX_PLUS_2];
|
||||
init_ss_array(ss);
|
||||
|
||||
moves[count].move = cur->move;
|
||||
pos.do_move(moves[count].move, st);
|
||||
@@ -2560,6 +2566,18 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
// init_ss_array() does a fast reset of the first entries of a SearchStack array
|
||||
|
||||
void init_ss_array(SearchStack ss[]) {
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ss[i].init(i);
|
||||
ss[i].initKillers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// wait_for_stop_or_ponderhit() is called when the maximum depth is reached
|
||||
// while the program is pondering. The point is to work around a wrinkle in
|
||||
// the UCI protocol: When pondering, the engine is not allowed to give a
|
||||
|
||||
33
src/tt.cpp
33
src/tt.cpp
@@ -220,27 +220,26 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||
/// will often get single-move PVs when the search stops while failing high,
|
||||
/// and a single-move PV means that we don't have a ponder move.
|
||||
|
||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[], int pvSize) {
|
||||
|
||||
int ply;
|
||||
Position p(pos);
|
||||
StateInfo st[100];
|
||||
|
||||
for (ply = 0; pv[ply] != MOVE_NONE; ply++)
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
|
||||
bool stop;
|
||||
const TTEntry* tte;
|
||||
for (stop = false, tte = retrieve(p.get_key());
|
||||
tte && tte->move() != MOVE_NONE && !stop;
|
||||
tte = retrieve(p.get_key()), ply++)
|
||||
StateInfo st;
|
||||
Position p(pos);
|
||||
int ply = 0;
|
||||
|
||||
// Update position to the end of current PV
|
||||
while (pv[ply] != MOVE_NONE)
|
||||
p.do_move(pv[ply++], st);
|
||||
|
||||
// Try to add moves from TT while possible
|
||||
while ( (tte = retrieve(p.get_key())) != NULL
|
||||
&& tte->move() != MOVE_NONE
|
||||
&& move_is_legal(p, tte->move())
|
||||
&& (!p.is_draw() || ply < 2)
|
||||
&& ply < pvSize)
|
||||
{
|
||||
if (!move_is_legal(p, tte->move()))
|
||||
break;
|
||||
pv[ply] = tte->move();
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
for (int j = 0; j < ply; j++)
|
||||
if (st[j].key == p.get_key()) stop = true;
|
||||
p.do_move(pv[ply++], st);
|
||||
}
|
||||
pv[ply] = MOVE_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user