Skip to content

Commit

Permalink
TM: try always to finish the iteration
Browse files Browse the repository at this point in the history
tc=10+0.1, hash=32MB
Score of Xiphos 0.2.6 SSE vs Xiphos 0.2.5 SSE: 1195 - 767 - 2038  [0.553] 4000
Elo difference: 37.32 +/- 7.53

tc=60+0.6, hash=128MB
Score of Xiphos 0.2.6 SSE vs Xiphos 0.2.5 SSE: 503 - 309 - 1688  [0.539] 2500
Elo difference: 27.02 +/- 7.73

tc=40/90, hash=128MB
Score of Xiphos 0.2.6 SSE vs Xiphos 0.2.5 SSE: 477 - 328 - 1695  [0.530] 2500
Elo difference: 20.73 +/- 7.70
  • Loading branch information
milostatarevic committed May 15, 2018
1 parent 312c43d commit 13b0224
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 54 deletions.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/game.h
Expand Up @@ -21,7 +21,7 @@

#include <inttypes.h>

#define VERSION "Xiphos 0.2.5"
#define VERSION "Xiphos 0.2.6"
#define AUTHOR "Milos Tatarevic"

#ifdef _BMI2
Expand Down
35 changes: 17 additions & 18 deletions src/search.c
Expand Up @@ -65,9 +65,9 @@ void init_lmr()
lmr[d][m] = sqrt(d * m / 8);
}

static inline int draw(search_data_t *sd, int repetitions)
static inline int draw(search_data_t *sd)
{
int i, cnt, fifty_cnt;
int i, fifty_cnt;

fifty_cnt = sd->pos->fifty_cnt;
if (fifty_cnt >= 100 || insufficient_material(sd->pos))
Expand All @@ -76,14 +76,9 @@ static inline int draw(search_data_t *sd, int repetitions)
if (fifty_cnt < 4)
return 0;

cnt = 0;
for (i = sd->hash_keys_cnt - 2; i >= (sd->hash_keys_cnt - fifty_cnt); i -= 2)
{
if (sd->hash_keys[i] == sd->hash_key)
cnt ++;
if (cnt >= repetitions)
return 1;
}
return 0;
}

Expand All @@ -101,7 +96,7 @@ int qsearch(search_data_t *sd, int alpha, int beta, int depth, int ply)

pos = sd->pos;
if (ply >= MAX_PLY) return eval(pos);
if (draw(sd, 1)) return 0;
if (draw(sd)) return 0;

hash_depth = (pos->in_check || depth == 0) ? 0 : -1;
use_hash = hash_depth == 0 || shared_search_info.max_threads > 1;
Expand Down Expand Up @@ -190,7 +185,7 @@ int pvs(search_data_t *sd, int root_node, int pv_node, int alpha, int beta,
if (ply >= MAX_PLY) return eval(pos);

if (shared_search_info.done) return 0;
if (!root_node && draw(sd, 1)) return 0;
if (!root_node && draw(sd)) return 0;

// load hash data
use_hash = !skip_move;
Expand Down Expand Up @@ -468,7 +463,7 @@ void *search_thread(void *thread_data)
alpha = _max(score - delta, -MATE_SCORE);
beta = _min(score + delta, MATE_SCORE);

while (1)
while (delta <= MATE_SCORE)
{
score = pvs(sd, 1, 1, alpha, beta, depth, 0, 0, 0);
if (shared_search_info.done) break;
Expand All @@ -482,10 +477,20 @@ void *search_thread(void *thread_data)
break;
}
if (shared_search_info.done) break;

if (depth >= MIN_DEPTH_TO_REACH &&
time_in_ms() - shared_search_info.time_in_ms >= shared_search_info.min_time)
{
pthread_mutex_lock(&mutex);
shared_search_info.done = 1;
pthread_mutex_unlock(&mutex);
break;
}
}

if (depth > shared_search_info.max_depth)
shared_search_info.done = 1;
pthread_mutex_lock(&mutex);
shared_search_info.done = 1;
pthread_mutex_unlock(&mutex);

pthread_exit(NULL);
}
Expand Down Expand Up @@ -529,12 +534,6 @@ void search(search_data_t *sd, search_data_t *threads_search_data)
pthread_attr_t attr;
pthread_t threads[MAX_THREADS];

if (draw(sd, 2))
{
print("bestmove (none)\n");
return;
}

shared_search_info.time_in_ms = time_in_ms();
set_hash_iteration();
reevaluate_position(sd->pos);
Expand Down
4 changes: 2 additions & 2 deletions src/search.h
Expand Up @@ -38,10 +38,10 @@ typedef struct {
} search_data_t;

struct {
int max_threads, max_depth, max_time, done, score, depth,
int max_threads, max_depth, done, score, depth,
search_depth_cnt[MAX_DEPTH];
move_t best_move;
uint64_t time_in_ms;
uint64_t time_in_ms, min_time, max_time;
struct {
int time, inc, movestogo, depth, movetime;
} go;
Expand Down
56 changes: 23 additions & 33 deletions src/uci.c
Expand Up @@ -44,12 +44,11 @@

#define MAX_REDUCE_TIME 1000
#define REDUCE_TIME 80
#define REDUCE_TIME_PER_MOVE 5
#define EXTEND_MOVE_TIME 80
#define TIME_REDUCTION_COEFF 0.9
#define REDUCE_TIME_PERCENT 5
#define MIN_TIME_RATIO 0.6
#define MAX_TIME_MOVES_TO_GO 3

#define EXTEND_TIME_FOR_CNT 25
#define DEFAULT_MOVES_TO_GO 25
#define MAX_MOVES_TO_GO 25
#define READ_BUFFER_SIZE 65536

search_data_t *threads_search_data;
Expand Down Expand Up @@ -169,7 +168,8 @@ void uci_position_startpos(search_data_t *sd, char *buf)

void uci_go(search_data_t *sd, char *buf)
{
int max_threads, max_time, max_time_allowed, moves_to_go;
int max_threads, max_time, max_time_allowed, target_time, reduce_time,
moves_to_go;
char *t;
position_t *pos;

Expand Down Expand Up @@ -212,46 +212,37 @@ void uci_go(search_data_t *sd, char *buf)
}

shared_search_info.max_depth = MAX_DEPTH - 1;
shared_search_info.max_time = 0;
shared_search_info.min_time = shared_search_info.max_time = 0;

if (shared_search_info.go.depth > 0)
{
shared_search_info.max_time = (1 << 30);
shared_search_info.min_time = shared_search_info.max_time = (1 << 30);
shared_search_info.max_depth =
_min(shared_search_info.go.depth, shared_search_info.max_depth);
}
else
{
if (shared_search_info.go.movetime > 0)
shared_search_info.max_time =
shared_search_info.min_time = shared_search_info.max_time =
_max(shared_search_info.go.movetime - REDUCE_TIME, 1);
else
{
if (shared_search_info.go.time < 0)
shared_search_info.go.time = 1;

moves_to_go = _min(shared_search_info.go.movestogo, EXTEND_TIME_FOR_CNT);
moves_to_go = _min(shared_search_info.go.movestogo, MAX_MOVES_TO_GO);
if (moves_to_go == 0)
moves_to_go = DEFAULT_MOVES_TO_GO;

max_time_allowed = _max(shared_search_info.go.time - REDUCE_TIME, 1);
max_time = _max(
max_time_allowed / moves_to_go +
shared_search_info.go.inc - REDUCE_TIME_PER_MOVE, 1
);

// if possible, try to leave more time to GUI
if (shared_search_info.go.movestogo <= 1 && max_time > EXTEND_MOVE_TIME &&
max_time - MAX_REDUCE_TIME < shared_search_info.go.time)
{
max_time =
_min(max_time,
_max(max_time * TIME_REDUCTION_COEFF,
shared_search_info.go.time - MAX_REDUCE_TIME)
);
max_time = _max(max_time, EXTEND_MOVE_TIME);
}
moves_to_go = MAX_MOVES_TO_GO;

reduce_time = _min(
shared_search_info.go.time * REDUCE_TIME_PERCENT / 100, MAX_REDUCE_TIME
) + REDUCE_TIME;
max_time_allowed = _max(shared_search_info.go.time - reduce_time, 1);

target_time = max_time_allowed / moves_to_go + shared_search_info.go.inc;
shared_search_info.min_time =
_min(MIN_TIME_RATIO * target_time, max_time_allowed);

max_time =
max_time_allowed / _min(moves_to_go, MAX_TIME_MOVES_TO_GO) +
shared_search_info.go.inc;
shared_search_info.max_time = _min(max_time, max_time_allowed);
}
}
Expand Down Expand Up @@ -408,4 +399,3 @@ void uci()
set_max_threads(atoi(buf));
}
}

0 comments on commit 13b0224

Please sign in to comment.