Skip to content

Commit dab82b4

Browse files
committed
time management tuning; bishop pair
1 parent 9da088b commit dab82b4

File tree

8 files changed

+42
-35
lines changed

8 files changed

+42
-35
lines changed

attacked.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030

3131
#include "board.h"
3232

33-
inline int IsAttacked(const BOARD *board, SQUARE square, COLOR attacking_color)
34-
{
35-
return AttackingPieces(board, square, attacking_color, 0);
36-
}
37-
3833
int AttackingPieces(const BOARD *board, SQUARE square, COLOR attacking_color, SQUARE *attacking_sqs)
3934
{
4035
int attackers = 0;

board.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum PIECES { EMPTY,
7373
#define BLACK 0
7474
#define TURN_BLACK(piece) (piece & 0xE)
7575
#define TURN_WHITE(piece) (piece | 0x1)
76-
#define BLACK_TO_COLOR(blackpiece, piece) ((blackpiece)|(piece & 0x1))
76+
/* #define BLACK_TO_COLOR(blackpiece, piece) ((blackpiece)|(piece & 0x1)) */
7777
#define GET_COLOR(piece) (piece & 0x1)
7878

7979
#define FIRST_ROW 0x00
@@ -269,9 +269,13 @@ int LazyEval(const BOARD*);
269269
int StaticEval(const BOARD*);
270270
int Value(PIECE);
271271

272-
int IsAttacked(const BOARD*, SQUARE, COLOR);
273272
int AttackingPieces(const BOARD*, SQUARE, COLOR, SQUARE*);
274273

274+
inline int IsAttacked(const BOARD *board, SQUARE square, COLOR attacking_color)
275+
{
276+
return AttackingPieces(board, square, attacking_color, 0);
277+
}
278+
275279
inline int WhiteInCheck(const BOARD *board){
276280
return IsAttacked(board, board->wking_pos, BLACK);
277281
}

book.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ int PolyglotChooseMove(KEY key)
400400
}
401401
int offset = PolyglotFindKey(f,key,&entry);
402402
if(entry.key!=key){
403-
printf("info string Out of book.\n");
404403
fclose(f);
405404
return 0;
406405
}

engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static const int mobility_bonus[] = {
7777
#define CASTLE_RIGHT_BONUS 20
7878
#define KING_CENTER_BONUS 10
7979
#define SIMPLIFY_BONUS 0.1
80+
#define BISHOP_PAIR_BONUS 20
8081

8182
#define DOUBLED_PAWN_BONUS 10
8283
#define ISOLATED_PAWN_BONUS 5

eval.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static inline int MobilityEval(const BOARD *board)
5858

5959
static inline int PawnStructureEval(const BOARD *board)
6060
{
61-
BITBOARD bp = board->pawns[0], wp = board->pawns[1];
61+
BITBOARD bp = board->pawns[BLACK], wp = board->pawns[WHITE];
6262
BITBOARD b = bp | wp;
6363
int val = GetPawnEval(&pawn_table, b);
6464
if(val != ERRORVALUE) return val;
@@ -82,8 +82,10 @@ static inline int MaterialDraw(const BOARD *board)
8282

8383
static inline int MaterialEval(const BOARD *board)
8484
{
85-
return (board->piece_material[1] + board->pawn_material[1]
86-
- board->piece_material[0] - board->pawn_material[0]);
85+
return (board->piece_material[WHITE] + board->pawn_material[WHITE]
86+
- board->piece_material[BLACK] - board->pawn_material[BLACK])
87+
+ ((board->bishops[WHITE] == 2) - (board->bishops[BLACK] == 2))
88+
* BISHOP_PAIR_BONUS * PawnStage(board);
8789
}
8890

8991
int LazyEval(const BOARD *board)

movegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,4 @@ int MoveGen(const BOARD *board, MOVE *poss_moves, char noncaptures)
292292
}
293293
return nmoves;
294294
}
295-
#endif
295+
#endif

search.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static int RetrievePV(BOARD *board, MOVE *PV, unsigned int depth)
4444
unsigned int PVlen = 0;
4545
MOVE mov = GetHashMove(&hash_table, board->zobrist_key);
4646
while(mov && PVlen <= depth && IsLegal(board, &mov)){
47-
PV[PVlen] = mov;
48-
PVlen++;
47+
PV[PVlen++] = mov;
4948
MakeMove(board, &mov);
5049
mov = GetHashMove(&hash_table, board->zobrist_key);
5150
}
@@ -74,7 +73,11 @@ static int Quiescent(BOARD *board, int alpha, int beta, CONTROL *control)
7473
int nposs_movs, nlegal = 0;
7574
int val;
7675
MOVE poss_moves[MAXMOVES];
77-
76+
77+
if(!control->ponder && clock() - control->init_time >= control->max_time*CPMS){
78+
control->stop = 1;
79+
}
80+
7881
val = LazyEval(board);
7982
if(val-LAZYBETA >= beta) return beta;
8083
if(val+LAZYALPHA < alpha) return alpha;
@@ -109,7 +112,7 @@ static int Quiescent(BOARD *board, int alpha, int beta, CONTROL *control)
109112
static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
110113
int root, CONTROL *control, char skip_null, MOVE killers[][2])
111114
{
112-
int nposs_movs, nlegal = 0;
115+
int nmoves, nlegal = 0;
113116
MOVE poss_moves[MAXMOVES];
114117
MOVE best_move = 0;
115118
char str_mov[MVLEN];
@@ -131,16 +134,19 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
131134
Takeback(board, null_mv);
132135
if(val >= beta) return beta;
133136
}
134-
nposs_movs = MoveGen(board, poss_moves, 1);
135-
SortMoves(board, poss_moves, nposs_movs, killers[root]);
136-
for(int i = 0; i < nposs_movs; i++){
137+
nmoves = MoveGen(board, poss_moves, 1);
138+
SortMoves(board, poss_moves, nmoves, killers[root]);
139+
for(int i = 0; i < nmoves; i++){
137140
MakeMove(board, &poss_moves[i]);
138141
control->node_count++;
139142
if(!LeftInCheck(board)){
140-
if(root == 0 && depth > 6){
141-
MoveToAlgeb(poss_moves[i], str_mov);
142-
printf("info depth %i hashfull %i currmove %s currmovenumber %i\n",
143-
depth, hash_table.full/(hash_table.size/1000), str_mov, i+1);
143+
if(root == 0){
144+
if(!control->best_move) control->best_move = poss_moves[0]; /* Better than nothing. */
145+
if(depth > 6 && !control->ponder){
146+
MoveToAlgeb(poss_moves[i], str_mov);
147+
printf("info depth %i hashfull %i currmove %s currmovenumber %i\n",
148+
depth, hash_table.full/(hash_table.size/1000), str_mov, i+1);
149+
}
144150
}
145151
nlegal++;
146152
val = AssesDraw(board);
@@ -153,10 +159,6 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
153159
}else val = -AlphaBeta(board, depth-1, -beta, -alpha, root+1, control, 0, killers);
154160
}
155161
Takeback(board, poss_moves[i]);
156-
157-
if(!control->ponder && clock() - control->init_time > control->max_time*CPMS*0.95){
158-
control->stop = 1;
159-
}
160162
if(control->stop) return alpha;
161163
if(val >= beta){
162164
UpdateTable(&hash_table, board->zobrist_key, val, poss_moves[i], depth, HASH_BETA);
@@ -177,7 +179,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
177179
if(root == 0 && !control->ponder && ((clock() - control->init_time) > control->wish_time*CPMS)){
178180
/* if short of time, don't search anymore after current move */
179181
control->max_depth = depth;
180-
return alpha; // val???
182+
return alpha;
181183
}
182184
}else Takeback(board, poss_moves[i]);
183185
}
@@ -209,9 +211,10 @@ void IterativeDeep(BOARD *board, CONTROL *control)
209211
int beta = INFINITE;
210212
unsigned long long nps = 0;
211213
MOVE killers[MAXDEPTH][2];
214+
control->best_move = 0;
212215

213216
for(unsigned int depth = 1; depth <= control->max_depth;){
214-
unsigned long long curr_time = clock();
217+
clock_t curr_time = clock();
215218
memset(sPV, 0, SPVLEN);
216219
control->node_count = 0;
217220

@@ -225,19 +228,19 @@ void IterativeDeep(BOARD *board, CONTROL *control)
225228
strcat(sPV, str_mov);
226229
}
227230

228-
curr_time = (unsigned long long)((clock() - curr_time)/CPMS);
231+
curr_time = (clock() - curr_time)/CPMS;
229232
if(curr_time){
230233
nps = 1000*(control->node_count/curr_time);
231234
}
232235
if(eval > MATE_VALUE/2 && -eval > MATE_VALUE/2){
233236
printf("info depth %u time %llu nodes %llu nps %llu score cp %i pv %s\n",
234-
depth, curr_time, control->node_count, nps, eval, sPV);
237+
depth, (unsigned long long)curr_time, control->node_count, nps, eval, sPV);
235238
}else if(-eval < MATE_VALUE/2){
236239
printf("info depth %u time %llu nodes %llu nps %llu score mate %i pv %s\n",
237-
depth, curr_time, control->node_count, nps, (pvlen+1)/2, sPV);
240+
depth, (unsigned long long)curr_time, control->node_count, nps, (pvlen+1)/2, sPV);
238241
}else if(eval < MATE_VALUE/2){
239242
printf("info depth %u time %llu nodes %llu nps %llu score mate %i pv %s\n",
240-
depth, curr_time, control->node_count, nps, -(pvlen+1)/2, sPV);
243+
depth, (unsigned long long)curr_time, control->node_count, nps, -(pvlen+1)/2, sPV);
241244
}
242245
if(eval <= alpha || eval >= beta){
243246
alpha = -INFINITE;

uci.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ inline void ManageTimes(int nmoves, ENGINE_STATE *stat)
7676
{
7777
if(stat->board->white_to_move){
7878
stat->control->wish_time = stat->control->wtime/nmoves + stat->control->wtime_inc;
79-
stat->control->max_time = stat->control->wtime;
79+
stat->control->max_time = stat->control->wtime *0.2;
8080
}else{
8181
stat->control->wish_time = stat->control->btime/nmoves + stat->control->btime_inc;
82-
stat->control->max_time = stat->control->btime;
82+
stat->control->max_time = stat->control->btime *0.2;
8383
}
8484
}
8585

@@ -250,15 +250,18 @@ int setoption(char *input, ENGINE_STATE *stat)
250250
int val = 0;
251251
if(!sscanf(input, "setoption name Hash value %i", &val)) return 1;
252252
DeleteTable(&hash_table);
253+
DeletePawnTable(&pawn_table);
253254
if(AllocPawnTable(&pawn_table, 0.2*val) == 0) return 0;
254255
if(AllocTable(&hash_table, 0.8*val) == 0) return 0;
255256
ClearHashTable(&hash_table);
257+
ClearPawnTable(&pawn_table);
256258
return 1;
257259
}
258260

259261
int ucinewgame(char *input, ENGINE_STATE *stat)
260262
{
261263
ClearHashTable(&hash_table);
264+
ClearPawnTable(&pawn_table);
262265
return 1;
263266
}
264267

0 commit comments

Comments
 (0)