Skip to content

Commit 7d36628

Browse files
committed
late move reductions
1 parent 059c269 commit 7d36628

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

board.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ enum PIECES { EMPTY,
130130

131131
#define PAWN_VALUE 100
132132
#define KNIGHT_VALUE 300
133-
#define BISHOP_VALUE 300
133+
#define BISHOP_VALUE 310
134134
#define ROOK_VALUE 500
135135
#define QUEEN_VALUE 900
136136

137137
#define STARTPAWNS 1600
138-
#define STARTMATERIAL 6200
138+
#define STARTMATERIAL 6240
139139
#include "hashtable.h"
140140
#include "pawns.h"
141141

@@ -302,12 +302,12 @@ inline MOVE Move(PIECE piece, SQUARE dest, SQUARE orig)
302302
/*Game stage according to material present; 0 -> 1 as game progresses.*/
303303
inline float PawnStage(const BOARD *board)
304304
{
305-
return 1.0 - (float)(board->pawn_material[0] + board->pawn_material[1])/STARTPAWNS;
305+
return 1.0f - (float)(board->pawn_material[0] + board->pawn_material[1])/STARTPAWNS;
306306
}
307307

308308
inline float GameStage(const BOARD *board)
309309
{
310-
return 1.0 - (float)(board->piece_material[0] + board->piece_material[1])/STARTMATERIAL;
310+
return 1.0f - (float)(board->piece_material[0] + board->piece_material[1])/STARTMATERIAL;
311311
}
312312

313313
/* Some methods to convert coordinates to algebraic notation, and the other way round.*/

engine.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ static const int mobility_bonus[] = {
7878
#define KING_CENTER_BONUS 10
7979
#define SIMPLIFY_BONUS 0.1
8080
#define BISHOP_PAIR_BONUS 20
81+
#define PROMOTION_VALUE 10
82+
#define CHECK_VALUE 10 /*unused*/
8183

8284
#define DOUBLED_PAWN_BONUS 10
83-
#define ISOLATED_PAWN_BONUS 5
84-
#define PAWN_PUSH_BONUS 0.1
85+
#define ISOLATED_PAWN_BONUS 5 /*unused*/
86+
#define PAWN_PUSH_BONUS 0.1 /*unused*/
8587
#define PASSED_PAWN_BONUS 20
8688

8789
#endif
@@ -98,7 +100,7 @@ static const int mobility_bonus[] = {
98100
static const clock_t CPMS = CLOCKS_PER_SEC/1000;
99101

100102
typedef struct CONTROL {
101-
int wtime, btime, wtime_inc, btime_inc;
103+
clock_t wtime, btime, wtime_inc, btime_inc;
102104
clock_t init_time, wish_time, max_time;
103105
unsigned int max_depth;
104106
unsigned long long node_count;

moveeval.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ static int SEE(BOARD *board, MOVE *main_capture)
5959
}
6060
else move_hist[depth] = Move(0, dest, less_attack_sq);
6161

62-
MakeMove(board, &move_hist[depth]);
63-
depth++;
62+
MakeMove(board, &move_hist[depth++]);
6463
attackers = AttackingPieces(board, dest, board->white_to_move, attacking_sqs);
6564
}
6665

@@ -77,20 +76,30 @@ static int SEE(BOARD *board, MOVE *main_capture)
7776
return val;
7877
}
7978

79+
static int QuietMoveEval(BOARD *board, MOVE *move, const MOVE killers[])
80+
{
81+
if(SQSMASK(*move) == SQSMASK(killers[0]) || SQSMASK(*move) == SQSMASK(killers[1])){
82+
return KILLER_VALUE;
83+
}else if(PROMMASK(*move)){
84+
return PROMOTION_VALUE;
85+
}else{
86+
return 0;
87+
}
88+
}
89+
8090
static int EvaluateMove(BOARD *board, MOVE *curr_move, const MOVE hash_move, const MOVE killers[])
8191
{
8292
/*Compare with hash_move, using only orig, des; curr_move may not have captured or ep info.*/
8393
if(SQSMASK(*curr_move) == SQSMASK(hash_move)){
8494
return HASHMOVE_VALUE; /*search HashMove first.*/
8595
}
86-
if(SQSMASK(*curr_move) == SQSMASK(killers[0])
87-
|| SQSMASK(*curr_move) == SQSMASK(killers[1])){
88-
return KILLER_VALUE;
89-
}
9096
/*Evaluate captures with SEE:*/
9197
SQUARE dest = DESTMASK(*curr_move);
92-
if(board->squares[dest] != EMPTY) return SEE(board, curr_move);
93-
else return 0;
98+
if(board->squares[dest] != EMPTY){
99+
return SEE(board, curr_move);
100+
}else{
101+
return QuietMoveEval(board, curr_move, killers);
102+
}
94103
}
95104

96105
int SortMoves(BOARD *board, MOVE *moves, int nmoves, MOVE killers[])

search.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
116116
MOVE moves[MAXMOVES];
117117
MOVE best_move = 0;
118118
char str_mov[MVLEN];
119-
SQUARE checking_sqs[5];
120119
int val = ERRORVALUE;
121120
char hash_flag = HASH_ALPHA;
122121
int reduce = 0, LMR = 0;
@@ -155,7 +154,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
155154
val = AssesDraw(board);
156155
if(val) {
157156
if(best_move){
158-
LMR = (reduce && i > good) ? 1 : 0;
157+
LMR = (reduce && i > good && !CAPTMASK(moves[i]) && !InCheck(board, 0)) ? 1 : 0;
159158
val = -AlphaBeta(board, depth-LMR-1, -alpha-1, -alpha, root+1, control, 0, killers);
160159
if(val > alpha){
161160
val = -AlphaBeta(board, depth-1, -alpha-1, -alpha, root+1, control, 0, killers);
@@ -166,7 +165,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
166165
}else val = -AlphaBeta(board, depth-1, -beta, -alpha, root+1, control, 0, killers);
167166
}
168167
Takeback(board, moves[i]);
169-
if(control->stop) return alpha;
168+
if(!control->ponder && control->stop) return alpha;
170169
if(val >= beta){
171170
UpdateTable(&hash_table, board->zobrist_key, val, moves[i], depth, HASH_BETA);
172171
if(CAPTMASK(moves[i]) == 0
@@ -183,9 +182,9 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
183182
best_move = moves[i];
184183
if(root == 0) control->best_move = best_move;
185184
}
186-
if(root == 0 && !control->ponder && ((clock() - control->init_time) > control->wish_time*CPMS)){
185+
if(root == 0 && ((clock() - control->init_time) > control->wish_time*CPMS)){
187186
/* if short of time, don't search anymore after current move */
188-
control->max_depth = depth;
187+
control->stop = 1;
189188
return alpha;
190189
}
191190
}else Takeback(board, moves[i]);
@@ -216,17 +215,20 @@ void IterativeDeep(BOARD *board, CONTROL *control)
216215
int eval = 0, pvlen = 0;
217216
int alpha = -INFINITE;
218217
int beta = INFINITE;
218+
int widening = ASP_WINDOW;
219219
unsigned long long nps = 0;
220220
MOVE killers[MAXDEPTH][2];
221221
control->best_move = 0;
222+
223+
/*printf("time %llu %llu\n", control->max_time, control->wish_time);*/
222224

223225
for(unsigned int depth = 1; depth <= control->max_depth;){
224226
clock_t curr_time = clock();
225227
memset(sPV, 0, SPVLEN);
226228
control->node_count = 0;
227229

228230
eval = AlphaBeta(board, depth, alpha, beta, 0, control, 1, killers);
229-
if(control->stop){
231+
if(control->stop && !control->ponder){
230232
break;
231233
}
232234
pvlen = RetrievePV(board, iPV, depth+10);
@@ -253,8 +255,9 @@ void IterativeDeep(BOARD *board, CONTROL *control)
253255
alpha = -INFINITE;
254256
beta = INFINITE;
255257
}else{
256-
if(3*curr_time > control->wish_time-(clock()-control->init_time)
257-
&& !control->ponder) break;
258+
if(3*curr_time > control->wish_time*CPMS - (clock()-control->init_time)){
259+
control->stop = 1;
260+
}
258261
alpha = eval - ASP_WINDOW;
259262
beta = eval + ASP_WINDOW;
260263
depth++;

uci.c

Lines changed: 5 additions & 4 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 *0.2;
79+
stat->control->max_time = stat->control->wtime;
8080
}else{
8181
stat->control->wish_time = stat->control->btime/nmoves + stat->control->btime_inc;
82-
stat->control->max_time = stat->control->btime *0.2;
82+
stat->control->max_time = stat->control->btime;
8383
}
8484
}
8585

@@ -113,7 +113,7 @@ int go(char *input, ENGINE_STATE *stat)
113113
stat->control->stop = 1;
114114
stat->control->ponder = 0;
115115
ResetTimes(stat);
116-
int movestogo = 30;
116+
int movestogo = 20;
117117
char manage_times = 1;
118118
char *str_param = strtok(input, " \n\t");
119119
for(str_param = strtok(NULL, " \n\t"); str_param; str_param = strtok(NULL, " \n\t")){
@@ -127,7 +127,7 @@ int go(char *input, ENGINE_STATE *stat)
127127
}else if(!strcmp("time", str_param)){
128128
str_param = strtok(NULL, " \n\t");
129129
if(str_param){
130-
stat->control->wish_time = atol(str_param);
130+
stat->control->wish_time = INFINITE;
131131
stat->control->max_time = atol(str_param);
132132
manage_times = 0;
133133
}
@@ -186,6 +186,7 @@ int go(char *input, ENGINE_STATE *stat)
186186

187187
int stop(char *input, ENGINE_STATE *stat)
188188
{
189+
stat->control->ponder = 0;
189190
stat->control->stop = 1;
190191
return 1;
191192
}

0 commit comments

Comments
 (0)