1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Reformat check_is_dangerous()

And shuffle some code at search.cpp tail.

No functional change.
This commit is contained in:
Marco Costalba 2012-10-27 14:25:31 +02:00
parent cd80762c13
commit b3d030294b

View file

@ -100,7 +100,7 @@ namespace {
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth); Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
void id_loop(Position& pos); void id_loop(Position& pos);
bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta); bool check_is_dangerous(Position& pos, Move move, Value futilityBase, Value beta);
bool connected_moves(const Position& pos, Move m1, Move m2); bool connected_moves(const Position& pos, Move m1, Move m2);
Value value_to_tt(Value v, int ply); Value value_to_tt(Value v, int ply);
Value value_from_tt(Value v, int ply); Value value_from_tt(Value v, int ply);
@ -1292,40 +1292,56 @@ split_point_start: // At split points actual search starts from here
} }
// check_is_dangerous() tests if a checking move can be pruned in qsearch(). // value_to_tt() adjusts a mate score from "plies to mate from the root" to
// bestValue is updated only when returning false because in that case move // "plies to mate from the current position". Non-mate scores are unchanged.
// will be pruned. // The function is called before storing a value to the transposition table.
bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta) Value value_to_tt(Value v, int ply) {
assert(v != VALUE_NONE);
return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
: v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
}
// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
// from the transposition table (where refers to the plies to mate/be mated
// from current position) to "plies to mate/be mated from the root".
Value value_from_tt(Value v, int ply) {
return v == VALUE_NONE ? VALUE_NONE
: v >= VALUE_MATE_IN_MAX_PLY ? v - ply
: v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
}
// check_is_dangerous() tests if a checking move can be pruned in qsearch()
bool check_is_dangerous(Position& pos, Move move, Value futilityBase, Value beta)
{ {
Bitboard b, occ, oldAtt, newAtt, kingAtt; Piece pc = pos.piece_moved(move);
Square from, to, ksq; Square from = from_sq(move);
Piece pc; Square to = to_sq(move);
Color them; Color them = ~pos.side_to_move();
Square ksq = pos.king_square(them);
Bitboard enemies = pos.pieces(them);
Bitboard kingAtt = pos.attacks_from<KING>(ksq);
Bitboard occ = pos.pieces() ^ from ^ ksq;
Bitboard oldAtt = pos.attacks_from(pc, from, occ);
Bitboard newAtt = pos.attacks_from(pc, to, occ);
from = from_sq(move); // Checks which give opponent's king at most one escape square are dangerous
to = to_sq(move); if (!more_than_one(kingAtt & ~(enemies | newAtt | to)))
them = ~pos.side_to_move();
ksq = pos.king_square(them);
kingAtt = pos.attacks_from<KING>(ksq);
pc = pos.piece_moved(move);
occ = pos.pieces() ^ from ^ ksq;
oldAtt = pos.attacks_from(pc, from, occ);
newAtt = pos.attacks_from(pc, to, occ);
// Rule 1. Checks which give opponent's king at most one escape square are dangerous
b = kingAtt & ~pos.pieces(them) & ~newAtt & ~(1ULL << to);
if (!more_than_one(b))
return true; return true;
// Rule 2. Queen contact check is very dangerous // Queen contact check is very dangerous
if (type_of(pc) == QUEEN && (kingAtt & to)) if (type_of(pc) == QUEEN && (kingAtt & to))
return true; return true;
// Rule 3. Creating new double threats with checks // Creating new double threats with checks is dangerous
b = pos.pieces(them) & newAtt & ~oldAtt & ~(1ULL << ksq); Bitboard b = (enemies ^ ksq) & newAtt & ~oldAtt;
while (b) while (b)
{ {
// Note that here we generate illegal "double move"! // Note that here we generate illegal "double move"!
@ -1385,31 +1401,6 @@ split_point_start: // At split points actual search starts from here
} }
// value_to_tt() adjusts a mate score from "plies to mate from the root" to
// "plies to mate from the current position". Non-mate scores are unchanged.
// The function is called before storing a value to the transposition table.
Value value_to_tt(Value v, int ply) {
assert(v != VALUE_NONE);
return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
: v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
}
// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
// from the transposition table (where refers to the plies to mate/be mated
// from current position) to "plies to mate/be mated from the root".
Value value_from_tt(Value v, int ply) {
return v == VALUE_NONE ? VALUE_NONE
: v >= VALUE_MATE_IN_MAX_PLY ? v - ply
: v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
}
// connected_threat() tests whether it is safe to forward prune a move or if // connected_threat() tests whether it is safe to forward prune a move or if
// is somehow connected to the threat move returned by null search. // is somehow connected to the threat move returned by null search.
@ -1500,23 +1491,24 @@ split_point_start: // At split points actual search starts from here
std::stringstream s; std::stringstream s;
Time::point elaspsed = Time::now() - SearchTime + 1; Time::point elaspsed = Time::now() - SearchTime + 1;
size_t uciPVSize = std::min((size_t)Options["MultiPV"], RootMoves.size());
int selDepth = 0; int selDepth = 0;
for (size_t i = 0; i < Threads.size(); i++) for (size_t i = 0; i < Threads.size(); i++)
if (Threads[i].maxPly > selDepth) if (Threads[i].maxPly > selDepth)
selDepth = Threads[i].maxPly; selDepth = Threads[i].maxPly;
for (size_t i = 0; i < std::min((size_t)Options["MultiPV"], RootMoves.size()); i++) for (size_t i = 0; i < uciPVSize; i++)
{ {
bool updated = (i <= PVIdx); bool updated = (i <= PVIdx);
if (depth == 1 && !updated) if (depth == 1 && !updated)
continue; continue;
int d = (updated ? depth : depth - 1); int d = updated ? depth : depth - 1;
Value v = (updated ? RootMoves[i].score : RootMoves[i].prevScore); Value v = updated ? RootMoves[i].score : RootMoves[i].prevScore;
if (s.rdbuf()->in_avail()) if (s.rdbuf()->in_avail()) // Not at first line
s << "\n"; s << "\n";
s << "info depth " << d s << "info depth " << d