Skip to content

Commit e5fed98

Browse files
committed
2 slots in killer moves
1 parent 8aeb392 commit e5fed98

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

board.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int Perft(BOARD*, int);
9797
int SEE(BOARD*, MOVE*);
9898
int EvaluateMove(BOARD*, MOVE*, const MOVE);
9999
*/
100-
void SortMoves(BOARD*, MOVE*, int, MOVE);
100+
void SortMoves(BOARD*, MOVE*, int, MOVE[]);
101101
int FilterWinning(BOARD*, MOVE*, int);
102102

103103
int LazyEval(const BOARD*);
@@ -112,20 +112,20 @@ int KingStaticVal(const BOARD*, SQUARE, COLOR);
112112
*/
113113
int Value(PIECE);
114114

115-
static char WhiteInCheck(const BOARD* board){
115+
static char WhiteInCheck(const BOARD *board){
116116
return IsAttacked(board, board->wking_pos, BLACK);
117117
}
118118

119-
static char BlackInCheck(const BOARD* board){
119+
static char BlackInCheck(const BOARD *board){
120120
return IsAttacked(board, board->bking_pos, WHITE);
121121
}
122122

123-
static int InCheck(const BOARD* board, SQUARE *attacking_sqs){
123+
static int InCheck(const BOARD *board, SQUARE *attacking_sqs){
124124
if(board->white_to_move) return AttackingPieces(board, board->wking_pos, BLACK, attacking_sqs);
125125
else return AttackingPieces(board, board->bking_pos, WHITE, attacking_sqs);
126126
}
127127

128-
static char LeftInCheck(const BOARD* board){
128+
static char LeftInCheck(const BOARD *board){
129129
if(board->white_to_move) return IsAttacked(board, board->bking_pos, WHITE);
130130
else return IsAttacked(board, board->wking_pos, BLACK);
131131
}

engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct UCI_COMMAND{
5959
};
6060

6161
void IterativeDeep(BOARD*, CONTROL*);
62-
int AlphaBeta(BOARD*, unsigned int, int, int, int, CONTROL*, MOVE*);
62+
int AlphaBeta(BOARD*, unsigned int, int, int, int, CONTROL*, char, MOVE[][2]);
6363
int Quiescent(BOARD*, int, int, CONTROL*);
6464
int RetrievePV(BOARD*, MOVE*, unsigned int);
6565

moveeval.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ int SEE(BOARD *board, MOVE *main_capture)
7777
return val;
7878
}
7979

80-
int EvaluateMove(BOARD *board, MOVE *curr_move, const MOVE hash_move, const MOVE killer)
80+
int EvaluateMove(BOARD *board, MOVE *curr_move, const MOVE hash_move, const MOVE killers[])
8181
{
8282
/*Compare with hash_move, using only orig, des; curr_move may not have captured or ep info.*/
8383
if(SQSMASK(*curr_move) == SQSMASK(hash_move)){
8484
return HASHMOVE_VALUE; /*search HashMove first.*/
8585
}
86-
if(SQSMASK(*curr_move) == SQSMASK(killer)){
86+
if(SQSMASK(*curr_move) == SQSMASK(killers[0])
87+
|| SQSMASK(*curr_move) == SQSMASK(killers[1])){
8788
return KILLER_VALUE;
8889
}
8990
/*Evaluate captures with SEE:*/
@@ -92,13 +93,13 @@ int EvaluateMove(BOARD *board, MOVE *curr_move, const MOVE hash_move, const MOVE
9293
else return 0;
9394
}
9495

95-
void SortMoves(BOARD *board, MOVE *moves, int nmoves, MOVE killer)
96+
void SortMoves(BOARD *board, MOVE *moves, int nmoves, MOVE killers[])
9697
{
9798
int eval[MAXMOVES];
9899
MOVE hash_move = GetHashMove(board->zobrist_key);
99100
/*Evaluate every move, store evaluations:*/
100101
for(int i = 0; i < nmoves; i++){
101-
eval[i] = EvaluateMove(board, &moves[i], hash_move, killer);
102+
eval[i] = EvaluateMove(board, &moves[i], hash_move, killers);
102103
}
103104

104105
/*Order according to that evaluation: insertion sort*/

search.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ void IterativeDeep(BOARD *board, CONTROL *control)
6060
int alpha = -INFINITE;
6161
int beta = INFINITE;
6262
unsigned long long nps = 0;
63-
MOVE killers[MAXDEPTH] = {0};
63+
MOVE killers[MAXDEPTH][2];
6464

6565
for(unsigned int depth = 1; depth <= control->max_depth;){
6666
unsigned long long curr_time = clock();
6767
memset(sPV, 0, SPVLEN);
6868
control->node_count = 0;
6969

70-
eval = AlphaBeta(board, depth, alpha, beta, 1, control, killers);
70+
eval = AlphaBeta(board, depth, alpha, beta, 0, control, 1, killers);
7171
if(control->stop){
7272
break;
7373
}
@@ -106,7 +106,8 @@ void IterativeDeep(BOARD *board, CONTROL *control)
106106
printf("bestmove %s\n", str_mov);
107107
}
108108

109-
int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta, int root, CONTROL *control, MOVE *killers)
109+
int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
110+
int root, CONTROL *control, char skip_null, MOVE killers[][2])
110111
{
111112
int nposs_movs, nlegal = 0;
112113
MOVE poss_moves[MAXMOVES];
@@ -121,22 +122,22 @@ int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta, int root, C
121122
if(val != ERRORVALUE){
122123
return val;
123124
}
124-
if(root == 0 && depth > 2
125+
if(!skip_null && depth > 2
125126
&& board->piece_material[board->white_to_move] != 0
126127
&& !InCheck(board, 0)){
127128
MOVE null_mv = NULL_MOVE;
128129
MakeMove(board, &null_mv);
129-
val = -AlphaBeta(board, depth-3, -beta, -beta+1, -1, control, killers);
130+
val = -AlphaBeta(board, depth-3, -beta, -beta+1, root+1, control, 1, killers);
130131
Takeback(board, null_mv);
131132
if(val >= beta) return beta;
132133
}
133134
nposs_movs = MoveGen(board, poss_moves, 1);
134-
SortMoves(board, poss_moves, nposs_movs, killers[depth]);
135+
SortMoves(board, poss_moves, nposs_movs, killers[root]);
135136
for(int i = 0; i < nposs_movs; i++){
136137
MakeMove(board, &poss_moves[i]);
137138
control->node_count++;
138139
if(!LeftInCheck(board)){
139-
if(root== 1 && depth > 6){
140+
if(root == 0 && depth > 6){
140141
MoveToAlgeb(poss_moves[i], str_mov);
141142
printf("info depth %i hashfull %i currmove %s currmovenumber %i\n",
142143
depth, hash_table.full/(hash_table.size/1000), str_mov, i+1);
@@ -146,11 +147,11 @@ int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta, int root, C
146147

147148
if(val) {
148149
if(best_move){
149-
val = -AlphaBeta(board, depth - 1, -alpha-1, -alpha, 0, control, killers);
150+
val = -AlphaBeta(board, depth-1, -alpha-1, -alpha, root+1, control, 0, killers);
150151
if(val > alpha && val < beta){
151-
val = -AlphaBeta(board, depth - 1, -beta, -alpha, 0, control, killers);
152+
val = -AlphaBeta(board, depth-1, -beta, -alpha, root+1, control, 0, killers);
152153
}
153-
}else val = -AlphaBeta(board, depth - 1, -beta, -alpha, 0, control, killers);
154+
}else val = -AlphaBeta(board, depth-1, -beta, -alpha, root+1, control, 0, killers);
154155
}
155156
Takeback(board, poss_moves[i]);
156157

@@ -161,18 +162,21 @@ int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta, int root, C
161162
if(val >= beta){
162163
UpdateTable(board->zobrist_key, val, poss_moves[i], depth, HASH_BETA);
163164
MOVE hash_move = GetHashMove(board->zobrist_key);
164-
if(CAPTMASK(poss_moves[i]) == 0){
165-
killers[depth] = poss_moves[i];
165+
if(killers[root][0] != poss_moves[i]
166+
&& killers[root][1] != poss_moves[i]
167+
&& CAPTMASK(poss_moves[i]) == 0){
168+
killers[root][1] = killers[root][0];
169+
killers[root][0] = poss_moves[i];
166170
}
167171
return beta;
168172
}
169173
if(val > alpha){
170174
alpha = val;
171175
hash_flag = HASH_EXACT;
172176
best_move = poss_moves[i];
173-
if(root == 1) control->best_move = best_move;
177+
if(root == 0) control->best_move = best_move;
174178
}
175-
if(root == 1 && ((clock() - control->init_time) > control->wish_time*CPMS)){
179+
if(root == 0 && ((clock() - control->init_time) > control->wish_time*CPMS)){
176180
/*don't search anymore after current move; TODO: continue if fails low?*/
177181
control->max_depth = depth;
178182
return alpha;
@@ -190,7 +194,7 @@ int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta, int root, C
190194
}else UpdateTable(board->zobrist_key, alpha, best_move, depth, hash_flag);
191195

192196
}else if(InCheck(board, 0)){
193-
alpha = AlphaBeta(board, 1, alpha, beta, 0, control, killers);
197+
alpha = AlphaBeta(board, 1, alpha, beta, root+1, control, 1, killers);
194198
}else{
195199
alpha = Quiescent(board, alpha, beta, control);
196200
}

0 commit comments

Comments
 (0)