Permalink
Browse files

Merge remote-tracking branch 'upstream/master' into endgame

  • Loading branch information...
2 parents c91bfb1 + a56322f commit 5d1829fab267380b0762b9918226e57b5c34229a @glinscott committed Mar 27, 2012
Showing with 196 additions and 213 deletions.
  1. +2 −1 src/benchmark.cpp
  2. +10 −10 src/evaluate.cpp
  3. +0 −2 src/main.cpp
  4. +0 −6 src/material.cpp
  5. +3 −2 src/material.h
  6. +5 −5 src/platform.h
  7. +3 −4 src/search.cpp
  8. +135 −159 src/thread.cpp
  9. +26 −14 src/thread.h
  10. +3 −6 src/tt.h
  11. +8 −3 src/uci.cpp
  12. +1 −1 src/ucioption.cpp
View
@@ -118,7 +118,8 @@ void benchmark(int argc, char* argv[]) {
}
else
{
- Threads.start_thinking(pos, limits);
+ Threads.start_searching(pos, limits);
+ Threads.wait_for_search_finished();
nodes += Search::RootPosition.nodes_searched();
}
}
View
@@ -357,13 +357,12 @@ namespace {
template<bool Trace>
Value do_evaluate(const Position& pos, Value& margin) {
+ assert(!pos.in_check());
+
EvalInfo ei;
Value margins[2];
Score score, mobilityWhite, mobilityBlack;
- assert(pos.thread() >= 0 && pos.thread() < MAX_THREADS);
- assert(!pos.in_check());
-
// Initialize score by reading the incrementally updated scores included
// in the position object (material + piece square tables).
score = pos.value();
@@ -679,23 +678,24 @@ Value do_evaluate(const Position& pos, Value& margin) {
const Color Them = (Us == WHITE ? BLACK : WHITE);
- Bitboard b;
+ Bitboard b, undefended, undefendedMinors, weakEnemies;
Score score = SCORE_ZERO;
// Undefended pieces get penalized even if not under attack
- Bitboard undefended = pos.pieces(Them) & ~ei.attackedBy[Them][0];
- const Bitboard undefendedMinors = undefended & (pos.pieces(BISHOP) | pos.pieces(KNIGHT));
-
+ undefended = pos.pieces(Them) & ~ei.attackedBy[Them][0];
+ undefendedMinors = undefended & (pos.pieces(BISHOP) | pos.pieces(KNIGHT));
+
if (undefendedMinors)
score += single_bit(undefendedMinors) ? UndefendedPiecePenalty
: UndefendedPiecePenalty * 2;
if (undefended & pos.pieces(ROOK))
score += UndefendedPiecePenalty;
// Enemy pieces not defended by a pawn and under our attack
- Bitboard weakEnemies = pos.pieces(Them)
- & ~ei.attackedBy[Them][PAWN]
- & ei.attackedBy[Us][0];
+ weakEnemies = pos.pieces(Them)
+ & ~ei.attackedBy[Them][PAWN]
+ & ei.attackedBy[Us][0];
+
if (!weakEnemies)
return score;
View
@@ -55,6 +55,4 @@ int main(int argc, char* argv[]) {
cerr << "\nUsage: stockfish bench [hash size = 128] [threads = 1] "
<< "[limit = 12] [fen positions file = default] "
<< "[limited by depth, time, nodes or perft = depth]" << endl;
-
- Threads.exit();
}
View
@@ -84,12 +84,6 @@ namespace {
} // namespace
-/// MaterialInfoTable c'tor and d'tor allocate and free the space for Endgames
-
-void MaterialInfoTable::init() { Base::init(); if (!funcs) funcs = new Endgames(); }
-MaterialInfoTable::~MaterialInfoTable() { delete funcs; }
-
-
/// MaterialInfoTable::material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
View
@@ -72,8 +72,9 @@ class MaterialInfo {
class MaterialInfoTable : public SimpleHash<MaterialInfo, MaterialTableSize> {
public:
- ~MaterialInfoTable();
- void init();
+ MaterialInfoTable() : funcs(new Endgames()) {}
+ ~MaterialInfoTable() { delete funcs; }
+
MaterialInfo* material_info(const Position& pos) const;
static Phase game_phase(const Position& pos);
View
@@ -53,8 +53,8 @@ inline uint64_t time_to_msec(const sys_time_t& t) { return t.tv_sec * 1000LL + t
# include <pthread.h>
typedef pthread_mutex_t Lock;
typedef pthread_cond_t WaitCondition;
-typedef pthread_t ThreadHandle;
-typedef void*(*start_fn)(void*);
+typedef pthread_t NativeHandle;
+typedef void*(*pt_start_fn)(void*);
# define lock_init(x) pthread_mutex_init(&(x), NULL)
# define lock_grab(x) pthread_mutex_lock(&(x))
@@ -65,7 +65,7 @@ typedef void*(*start_fn)(void*);
# define cond_signal(x) pthread_cond_signal(&(x))
# define cond_wait(x,y) pthread_cond_wait(&(x),&(y))
# define cond_timedwait(x,y,z) pthread_cond_timedwait(&(x),&(y),z)
-# define thread_create(x,f,id) !pthread_create(&(x),NULL,(start_fn)f,&(id))
+# define thread_create(x,f,t) !pthread_create(&(x),NULL,(pt_start_fn)f,t)
# define thread_join(x) pthread_join(x, NULL)
#else // Windows and MinGW
@@ -90,7 +90,7 @@ inline uint64_t time_to_msec(const sys_time_t& t) { return t.time * 1000LL + t.m
// but apart from this they have the same speed performance of SRW locks.
typedef CRITICAL_SECTION Lock;
typedef HANDLE WaitCondition;
-typedef HANDLE ThreadHandle;
+typedef HANDLE NativeHandle;
# define lock_init(x) InitializeCriticalSection(&(x))
# define lock_grab(x) EnterCriticalSection(&(x))
@@ -101,7 +101,7 @@ typedef HANDLE ThreadHandle;
# define cond_signal(x) SetEvent(x)
# define cond_wait(x,y) { lock_release(y); WaitForSingleObject(x, INFINITE); lock_grab(y); }
# define cond_timedwait(x,y,z) { lock_release(y); WaitForSingleObject(x,z); lock_grab(y); }
-# define thread_create(x,f,id) (x = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)f,&(id),0,NULL), x != NULL)
+# define thread_create(x,f,t) (x = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)f,t,0,NULL), x != NULL)
# define thread_join(x) { WaitForSingleObject(x, INFINITE); CloseHandle(x); }
#endif
View
@@ -298,7 +298,7 @@ void Search::think() {
<< endl;
}
- Threads.set_size(Options["Threads"]);
+ Threads.wake_up();
// Set best timer interval to avoid lagging under time pressure. Timer is
// used to check for remaining available thinking time.
@@ -310,9 +310,8 @@ void Search::think() {
// We're ready to start searching. Call the iterative deepening loop function
id_loop(pos);
- // Stop timer and send all the slaves to sleep, if not already sleeping
- Threads.set_timer(0);
- Threads.set_size(1);
+ Threads.set_timer(0); // Stop timer
+ Threads.sleep();
if (Options["Use Search Log"])
{
Oops, something went wrong.

0 comments on commit 5d1829f

Please sign in to comment.