Skip to content

Commit

Permalink
Merge pull request official-stockfish#5 from official-stockfish/master
Browse files Browse the repository at this point in the history
Retire Search Log
  • Loading branch information
ddugovic committed Mar 28, 2015
2 parents dfdd9b0 + 877313a commit c06cbcc
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 108 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ ifneq ($(comp),mingw)
endif

### 3.4 Debugging
CXXFLAGS += -DKOTH
CXXFLAGS += -DHORDE
#CXXFLAGS += -DKOTH_DISTANCE_BONUS
ifeq ($(debug),no)
CXXFLAGS += -DNDEBUG
Expand Down
4 changes: 4 additions & 0 deletions src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ void benchmark(const Position& current, istream& is) {

for (size_t i = 0; i < fens.size(); ++i)
{
#ifdef HORDE
Position pos(fens[i], Options["UCI_Chess960"], Options["UCI_Horde"], Threads.main());
#else
#ifdef KOTH
Position pos(fens[i], Options["UCI_Chess960"], Options["UCI_KingOfTheHill"], Threads.main());
#else
Position pos(fens[i], Options["UCI_Chess960"], Threads.main());
#endif
#endif

cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
Expand Down
3 changes: 3 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
make clean
make build ARCH=x86-64
#make build ARCH=x86-64 debug=yes optimize=no
4 changes: 4 additions & 0 deletions src/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ namespace {
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";

#ifdef HORDE
return Position(fen, NULL).material_key();
#else
#ifdef KOTH
return Position(fen, NULL).material_key();
#else
return Position(fen, false, NULL).material_key();
#endif
#endif
}

Expand Down
67 changes: 0 additions & 67 deletions src/notation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/

#include <cassert>
#include <iomanip>
#include <sstream>
#include <stack>

#include "movegen.h"
#include "notation.h"
Expand Down Expand Up @@ -95,68 +93,3 @@ Move move_from_uci(const Position& pos, string& str) {

return MOVE_NONE;
}


/// pretty_pv() formats human-readable search information, typically to be
/// appended to the search log file. It uses the two helpers below to pretty
/// format the time and score respectively.

static string format(int64_t msecs) {

const int MSecMinute = 1000 * 60;
const int MSecHour = 1000 * 60 * 60;

int64_t hours = msecs / MSecHour;
int64_t minutes = (msecs % MSecHour) / MSecMinute;
int64_t seconds = ((msecs % MSecHour) % MSecMinute) / 1000;

stringstream ss;

if (hours)
ss << hours << ':';

ss << setfill('0') << setw(2) << minutes << ':' << setw(2) << seconds;

return ss.str();
}

static string format(Value v) {

stringstream ss;

if (v >= VALUE_MATE_IN_MAX_PLY)
ss << "#" << (VALUE_MATE - v + 1) / 2;

else if (v <= VALUE_MATED_IN_MAX_PLY)
ss << "-#" << (VALUE_MATE + v) / 2;

else
ss << setprecision(2) << fixed << showpos << double(v) / PawnValueEg;

return ss.str();
}

string pretty_pv(const Position& pos, int depth, Value value, int64_t msecs, Move pv[]) {

const uint64_t K = 1000;
const uint64_t M = 1000000;

stringstream ss;
ss << setw(2) << depth << setw(8) << format(value) << setw(8) << format(msecs);

if (pos.nodes_searched() < M)
ss << setw(8) << pos.nodes_searched() / 1 << " ";

else if (pos.nodes_searched() < K * M)
ss << setw(7) << pos.nodes_searched() / K << "K ";

else
ss << setw(7) << pos.nodes_searched() / M << "M ";

string str = ss.str();

for (Move *m = pv; *m != MOVE_NONE; m++)
str += move_to_uci(*m, pos.is_chess960()) + ' ';

return str;
}
1 change: 0 additions & 1 deletion src/notation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Position;
std::string score_to_uci(Value v, Value alpha = -VALUE_INFINITE, Value beta = VALUE_INFINITE);
Move move_from_uci(const Position& pos, std::string& str);
const std::string move_to_uci(Move m, bool chess960);
std::string pretty_pv(const Position& pos, int depth, Value score, int64_t msecs, Move pv[]);

inline char to_char(File f, bool tolower = true) {
return char(f - FILE_A + (tolower ? 'a' : 'A'));
Expand Down
81 changes: 81 additions & 0 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ CheckInfo::CheckInfo(const Position& pos) {
Color them = ~pos.side_to_move();
ksq = pos.king_square(them);

#ifdef HORDE
if (pos.is_horde() && ksq == SQ_NONE) {
pinned = pos.pinned_pieces(pos.side_to_move());
dcCandidates = pos.discovered_check_candidates();

checkSq[PAWN] = 0;
checkSq[KNIGHT] = 0;
checkSq[BISHOP] = 0;
checkSq[ROOK] = 0;
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
checkSq[KING] = 0;
} else {
#endif
pinned = pos.pinned_pieces(pos.side_to_move());
dcCandidates = pos.discovered_check_candidates();

Expand All @@ -105,6 +118,9 @@ CheckInfo::CheckInfo(const Position& pos) {
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
checkSq[KING] = 0;
#ifdef HORDE
}
#endif
}


Expand Down Expand Up @@ -181,21 +197,31 @@ void Position::clear() {
startState.epSquare = SQ_NONE;
st = &startState;

#ifdef HORDE
for (int i = 0; i < PIECE_TYPE_NB; ++i)
for (int j = 0; j < SQUARE_NB; ++j)
pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE;
#else
for (int i = 0; i < PIECE_TYPE_NB; ++i)
for (int j = 0; j < 16; ++j)
pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE;
#endif
}


/// Position::set() initializes the position object with the given FEN string.
/// This function is not very robust - make sure that input FENs are correct,
/// this is assumed to be the responsibility of the GUI.

#ifdef HORDE
void Position::set(const string& fenStr, bool isChess960, bool isHorde, Thread* th) {
#else
#ifdef KOTH
void Position::set(const string& fenStr, bool isChess960, bool isKOTH, Thread* th) {
#else
void Position::set(const string& fenStr, bool isChess960, Thread* th) {
#endif
#endif
/*
A FEN string defines a particular position using only the ASCII character set.
Expand Down Expand Up @@ -304,6 +330,11 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) {
gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK);

chess960 = isChess960;
#ifdef HORDE
// TODO: Fix
//isHorde = true;
horde = isHorde;
#endif
#ifdef KOTH
koth = isKOTH;
#endif
Expand Down Expand Up @@ -352,7 +383,12 @@ void Position::set_state(StateInfo* si) const {
si->npMaterial[WHITE] = si->npMaterial[BLACK] = VALUE_ZERO;
si->psq = SCORE_ZERO;

#ifdef HORDE
Square ksq = king_square(sideToMove);
si->checkersBB = ksq == SQ_NONE ? 0 : attackers_to(ksq) & pieces(~sideToMove);
#else
si->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
#endif

for (Bitboard b = pieces(); b; )
{
Expand Down Expand Up @@ -487,6 +523,9 @@ Bitboard Position::check_blockers(Color c, Color kingColor) const {

Bitboard b, pinners, result = 0;
Square ksq = king_square(kingColor);
#ifdef HORDE
if (ksq == SQ_NONE) return result;
#endif

// Pinners are sliders that give check when a pinned piece is removed
pinners = ( (pieces( ROOK, QUEEN) & PseudoAttacks[ROOK ][ksq])
Expand Down Expand Up @@ -528,8 +567,17 @@ bool Position::legal(Move m, Bitboard pinned) const {
Square from = from_sq(m);

assert(color_of(moved_piece(m)) == us);
#ifdef HORDE
assert(is_horde() && us == BLACK ? king_square(us) == SQ_NONE : piece_on(king_square(us)) == make_piece(us, KING));
#else
assert(piece_on(king_square(us)) == make_piece(us, KING));
#endif

#ifdef HORDE
// If the game is already won or lost, further moves are illegal
if (is_horde() && is_horde_loss())
return false;
#endif
#ifdef KOTH
// If the game is already won or lost, further moves are illegal
if (is_koth() && (is_koth_win() || is_koth_loss()))
Expand All @@ -551,6 +599,9 @@ bool Position::legal(Move m, Bitboard pinned) const {
assert(piece_on(capsq) == make_piece(~us, PAWN));
assert(piece_on(to) == NO_PIECE);

#ifdef HORDE
if (is_horde() && ksq != SQ_NONE)
#endif
return !(attacks_bb< ROOK>(ksq, occ) & pieces(~us, QUEEN, ROOK))
&& !(attacks_bb<BISHOP>(ksq, occ) & pieces(~us, QUEEN, BISHOP));
}
Expand All @@ -561,6 +612,10 @@ bool Position::legal(Move m, Bitboard pinned) const {
if (type_of(piece_on(from)) == KING)
return type_of(m) == CASTLING || !(attackers_to(to_sq(m)) & pieces(~us));

#ifdef HORDE
if (is_horde() && king_square(us) == SQ_NONE)
return true;
#endif
// A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king.
return !pinned
Expand All @@ -580,6 +635,11 @@ bool Position::pseudo_legal(const Move m) const {
Square to = to_sq(m);
Piece pc = moved_piece(m);

#ifdef HORDE
// If the game is already won or lost, further moves are illegal
if (is_horde() && is_horde_loss())
return false;
#endif
#ifdef KOTH
// If the game is already won or lost, further moves are illegal
if (is_koth() && (is_koth_win() || is_koth_loss()))
Expand Down Expand Up @@ -661,6 +721,10 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
Square to = to_sq(m);
PieceType pt = type_of(piece_on(from));

#ifdef HORDE
if (is_horde() && king_square(~sideToMove) == SQ_NONE)
return false;
#endif
// Is there a direct check?
if (ci.checkSq[pt] & to)
return true;
Expand Down Expand Up @@ -1184,10 +1248,14 @@ void Position::flip() {
std::getline(ss, token); // Half and full moves
f += token;

#ifdef HORDE
set(f, is_chess960(), is_horde(), this_thread());
#else
#ifdef KOTH
set(f, is_chess960(), is_koth(), this_thread());
#else
set(f, is_chess960(), this_thread());
#endif
#endif

assert(pos_is_ok());
Expand Down Expand Up @@ -1215,7 +1283,11 @@ bool Position::pos_is_ok(int* step) const {

if ( (sideToMove != WHITE && sideToMove != BLACK)
|| piece_on(king_square(WHITE)) != W_KING
#ifdef HORDE
|| is_horde() ? king_square(BLACK) != SQ_NONE : piece_on(king_square(BLACK)) != B_KING
#else
|| piece_on(king_square(BLACK)) != B_KING
#endif
|| ( ep_square() != SQ_NONE
&& relative_rank(sideToMove, ep_square()) != RANK_6))
return false;
Expand Down Expand Up @@ -1253,12 +1325,21 @@ bool Position::pos_is_ok(int* step) const {
}

if (step && ++*step, testKingCount)
#ifdef HORDE
if ( std::count(board, board + SQUARE_NB, W_KING) != 1
|| std::count(board, board + SQUARE_NB, B_KING) != (is_horde() ? 0 : 1))
#else
if ( std::count(board, board + SQUARE_NB, W_KING) != 1
|| std::count(board, board + SQUARE_NB, B_KING) != 1)
#endif
return false;

if (step && ++*step, testKingCapture)
#ifdef HORDE
if (is_horde() && king_square(~sideToMove) != SQ_NONE && attackers_to(king_square(~sideToMove)) & pieces(sideToMove))
#else
if (attackers_to(king_square(~sideToMove)) & pieces(sideToMove))
#endif
return false;

if (step && ++*step, testPieceCounts)
Expand Down
Loading

0 comments on commit c06cbcc

Please sign in to comment.