Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyGrant committed Jul 1, 2018
1 parent 3cba6d0 commit bb4aaf2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/makefile
Expand Up @@ -40,6 +40,8 @@ nopopcnt:
pext:
$(CC) $(CFLAGS) $(SRC) $(LIBS) $(PEXTFLAGS) -o $(EXE)

android:
$(CCDROID) $(AFLAGS) $(SRC) $(LIBS) -o $(EXE)$(VER)-android
release:
mkdir ../dist
$(CC) $(RFLAGS) $(SRC) $(LIBS) -o ../dist/$(EXE)$(VER)-x64-nopopcnt.exe
Expand Down
15 changes: 10 additions & 5 deletions src/search.c
Expand Up @@ -21,6 +21,7 @@
#include <math.h>
#include <pthread.h>
#include <setjmp.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -47,7 +48,7 @@

int LMRTable[64][64]; // Late Move Reductions, LMRTable[depth][played]

volatile int ABORT_SIGNAL; // Global ABORT flag for threads
atomic_int ABORT_SIGNAL; // Global ABORT flag for threads

pthread_mutex_t LOCK = PTHREAD_MUTEX_INITIALIZER; // Global LOCK for threads

Expand All @@ -61,7 +62,7 @@ void initSearch(){

uint16_t getBestMove(Thread* threads, Board* board, Limits* limits){

ABORT_SIGNAL = 0; // Clear the ABORT signal for the new search
atomic_store(&ABORT_SIGNAL, 0); // Clear the ABORT signal for the new search

updateTT(); // Table is on a new search, thus a new generation

Expand Down Expand Up @@ -193,7 +194,9 @@ void* iterativeDeepening(void* vthread){
break;
}

if (mainThread) ABORT_SIGNAL = 1;
// Force shutdown of all other threads
if (mainThread)
atomic_store(&ABORT_SIGNAL, 1);

return NULL;
}
Expand Down Expand Up @@ -284,7 +287,8 @@ int search(Thread* thread, PVariation* pv, int alpha, int beta, int depth, int h
longjmp(thread->jbuffer, 1);

// Step 1B. Check to see if the master thread finished
if (ABORT_SIGNAL) longjmp(thread->jbuffer, 1);
if (atomic_load_explicit(&ABORT_SIGNAL, memory_order_relaxed))
longjmp(thread->jbuffer, 1);

// Step 2. Check for early exit conditions, including the fifty move rule,
// mate distance pruning, max depth exceeded, or drawn by repitition. We
Expand Down Expand Up @@ -739,7 +743,8 @@ int qsearch(Thread* thread, PVariation* pv, int alpha, int beta, int height){
longjmp(thread->jbuffer, 1);

// Step 1B. Check to see if the master thread finished
if (ABORT_SIGNAL) longjmp(thread->jbuffer, 1);
if (atomic_load_explicit(&ABORT_SIGNAL, memory_order_relaxed))
longjmp(thread->jbuffer, 1);

// Step 2. Max Draft Cutoff. If we are at the maximum search draft,
// then end the search here with a static eval of the current board
Expand Down
14 changes: 9 additions & 5 deletions src/uci.c
Expand Up @@ -18,6 +18,7 @@

#include <inttypes.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -46,7 +47,7 @@ extern int MoveOverhead; // Defined by Time.c

extern unsigned TB_PROBE_DEPTH; // Defined by Syzygy.c

extern volatile int ABORT_SIGNAL; // For killing active search
extern atomic_int ABORT_SIGNAL; // For killing active search

pthread_mutex_t READYLOCK = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -104,29 +105,30 @@ int main(int argc, char **argv) {
}

else if (stringEquals(str, "isready")){
pthread_mutex_lock(&READYLOCK);
printf("readyok\n");
fflush(stdout);
pthread_mutex_unlock(&READYLOCK);
}

else if (stringStartsWith(str, "setoption")){

if (stringStartsWith(str, "setoption name Hash value ")){
megabytes = atoi(str + strlen("setoption name Hash value "));
megabytes = MAX(1, MIN(65536, megabytes));
initTT(megabytes);
printf("info string set Hash to %dMB\n", megabytes);
}

if (stringStartsWith(str, "setoption name Threads value ")){
free(threads);
nthreads = atoi(str + strlen("setoption name Threads value "));
nthreads = MAX(1, MIN(2048, nthreads));
threads = createThreadPool(nthreads);
printf("info string set Threads to %d\n", nthreads);
}

if (stringStartsWith(str, "setoption name MoveOverhead value ")){
MoveOverhead = atoi(str + strlen("setoption name MoveOverhead value "));
MoveOverhead = MAX(0, MIN(10000, MoveOverhead));
printf("info string set MoveOverhead to %d\n", MoveOverhead);
}

Expand All @@ -137,6 +139,7 @@ int main(int argc, char **argv) {

if (stringStartsWith(str, "setoption name SyzygyProbeDepth value ")){
TB_PROBE_DEPTH = atoi(str + strlen("setoption name SyzygyProbeDepth value "));
TB_PROBE_DEPTH = MIN(127, TB_PROBE_DEPTH);
printf("info string set SyzygyProbeDepth to %u\n", TB_PROBE_DEPTH);
}

Expand All @@ -159,7 +162,7 @@ int main(int argc, char **argv) {
}

else if (stringEquals(str, "stop")){
ABORT_SIGNAL = 1;
atomic_store(&ABORT_SIGNAL, 1);
pthread_join(pthreadsgo, NULL);
}

Expand Down Expand Up @@ -297,7 +300,8 @@ void uciPosition(char* str, Board* board){
}

// Skip over all white space
while (*ptr == ' ') ptr++;
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\r' || *ptr == '\n')
ptr++;

// Reset move history whenever we reset the fifty move rule
if (board->fiftyMoveRule == 0) board->numMoves = 0;
Expand Down

0 comments on commit bb4aaf2

Please sign in to comment.