Skip to content

Commit 80fd626

Browse files
committed
v1.1.2
Bugfixes
1 parent 1896c4c commit 80fd626

File tree

4 files changed

+74
-87
lines changed

4 files changed

+74
-87
lines changed

makemove.c

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ static void ClearPiece(const int sq, S_BOARD *pos) {
2727

2828
ASSERT(SqOnBoard(sq));
2929
ASSERT(CheckBoard(pos));
30-
30+
3131
int pce = pos->pieces[sq];
32-
32+
3333
ASSERT(PieceValid(pce));
34-
34+
3535
int col = PieceCol[pce];
3636
int index = 0;
3737
int t_pceNum = -1;
38-
38+
3939
ASSERT(SideValid(col));
40-
40+
4141
HASH_PCE(pce,sq);
42-
42+
4343
pos->pieces[sq] = EMPTY;
4444
pos->material[col] -= PieceVal[pce];
45-
45+
4646
if(PieceBig[pce]) {
4747
pos->bigPce[col]--;
4848
if(PieceMaj[pce]) {
@@ -54,34 +54,34 @@ static void ClearPiece(const int sq, S_BOARD *pos) {
5454
CLRBIT(pos->pawns[col],SQ64(sq));
5555
CLRBIT(pos->pawns[BOTH],SQ64(sq));
5656
}
57-
57+
5858
for(index = 0; index < pos->pceNum[pce]; ++index) {
5959
if(pos->pList[pce][index] == sq) {
6060
t_pceNum = index;
6161
break;
6262
}
6363
}
64-
64+
6565
ASSERT(t_pceNum != -1);
6666
ASSERT(t_pceNum>=0&&t_pceNum<10);
67-
68-
pos->pceNum[pce]--;
69-
67+
68+
pos->pceNum[pce]--;
69+
7070
pos->pList[pce][t_pceNum] = pos->pList[pce][pos->pceNum[pce]];
71-
71+
7272
}
7373

7474

7575
static void AddPiece(const int sq, S_BOARD *pos, const int pce) {
7676

7777
ASSERT(PieceValid(pce));
7878
ASSERT(SqOnBoard(sq));
79-
79+
8080
int col = PieceCol[pce];
8181
ASSERT(SideValid(col));
8282

8383
HASH_PCE(pce,sq);
84-
84+
8585
pos->pieces[sq] = pce;
8686

8787
if(PieceBig[pce]) {
@@ -95,40 +95,40 @@ static void AddPiece(const int sq, S_BOARD *pos, const int pce) {
9595
SETBIT(pos->pawns[col],SQ64(sq));
9696
SETBIT(pos->pawns[BOTH],SQ64(sq));
9797
}
98-
98+
9999
pos->material[col] += PieceVal[pce];
100100
pos->pList[pce][pos->pceNum[pce]++] = sq;
101-
101+
102102
}
103103

104104
static void MovePiece(const int from, const int to, S_BOARD *pos) {
105105

106106
ASSERT(SqOnBoard(from));
107107
ASSERT(SqOnBoard(to));
108-
108+
109109
int index = 0;
110-
int pce = pos->pieces[from];
110+
int pce = pos->pieces[from];
111111
int col = PieceCol[pce];
112112
ASSERT(SideValid(col));
113113
ASSERT(PieceValid(pce));
114-
114+
115115
#ifdef DEBUG
116116
int t_PieceNum = FALSE;
117117
#endif
118118

119119
HASH_PCE(pce,from);
120120
pos->pieces[from] = EMPTY;
121-
121+
122122
HASH_PCE(pce,to);
123123
pos->pieces[to] = pce;
124-
124+
125125
if(!PieceBig[pce]) {
126126
CLRBIT(pos->pawns[col],SQ64(from));
127127
CLRBIT(pos->pawns[BOTH],SQ64(from));
128128
SETBIT(pos->pawns[col],SQ64(to));
129-
SETBIT(pos->pawns[BOTH],SQ64(to));
130-
}
131-
129+
SETBIT(pos->pawns[BOTH],SQ64(to));
130+
}
131+
132132
for(index = 0; index < pos->pceNum[pce]; ++index) {
133133
if(pos->pList[pce][index] == from) {
134134
pos->pList[pce][index] = to;
@@ -144,20 +144,20 @@ static void MovePiece(const int from, const int to, S_BOARD *pos) {
144144
int MakeMove(S_BOARD *pos, int move) {
145145

146146
ASSERT(CheckBoard(pos));
147-
147+
148148
int from = FROMSQ(move);
149149
int to = TOSQ(move);
150150
int side = pos->side;
151-
151+
152152
ASSERT(SqOnBoard(from));
153153
ASSERT(SqOnBoard(to));
154154
ASSERT(SideValid(side));
155155
ASSERT(PieceValid(pos->pieces[from]));
156156
ASSERT(pos->hisPly >= 0 && pos->hisPly < MAXGAMEMOVES);
157157
ASSERT(pos->ply >= 0 && pos->ply < MAXDEPTH);
158-
158+
159159
pos->history[pos->hisPly].posKey = pos->posKey;
160-
160+
161161
if(move & MFLAGEP) {
162162
if(side == WHITE) {
163163
ClearPiece(to-10,pos);
@@ -180,11 +180,11 @@ int MakeMove(S_BOARD *pos, int move) {
180180
break;
181181
default: ASSERT(FALSE); break;
182182
}
183-
}
184-
183+
}
184+
185185
if(pos->enPas != NO_SQ) HASH_EP;
186186
HASH_CA;
187-
187+
188188
pos->history[pos->hisPly].move = move;
189189
pos->history[pos->hisPly].fiftyMove = pos->fiftyMove;
190190
pos->history[pos->hisPly].enPas = pos->enPas;
@@ -195,22 +195,22 @@ int MakeMove(S_BOARD *pos, int move) {
195195
pos->enPas = NO_SQ;
196196

197197
HASH_CA;
198-
198+
199199
int captured = CAPTURED(move);
200200
pos->fiftyMove++;
201-
201+
202202
if(captured != EMPTY) {
203203
ASSERT(PieceValid(captured));
204204
ClearPiece(to, pos);
205205
pos->fiftyMove = 0;
206206
}
207-
207+
208208
pos->hisPly++;
209209
pos->ply++;
210-
210+
211211
ASSERT(pos->hisPly >= 0 && pos->hisPly < MAXGAMEMOVES);
212212
ASSERT(pos->ply >= 0 && pos->ply < MAXDEPTH);
213-
213+
214214
if(PiecePawn[pos->pieces[from]]) {
215215
pos->fiftyMove = 0;
216216
if(move & MFLAGPS) {
@@ -224,52 +224,52 @@ int MakeMove(S_BOARD *pos, int move) {
224224
HASH_EP;
225225
}
226226
}
227-
227+
228228
MovePiece(from, to, pos);
229-
229+
230230
int prPce = PROMOTED(move);
231231
if(prPce != EMPTY) {
232232
ASSERT(PieceValid(prPce) && !PiecePawn[prPce]);
233233
ClearPiece(to, pos);
234234
AddPiece(to, pos, prPce);
235235
}
236-
236+
237237
if(PieceKing[pos->pieces[to]]) {
238238
pos->KingSq[pos->side] = to;
239239
}
240-
240+
241241
pos->side ^= 1;
242242
HASH_SIDE;
243243

244244
ASSERT(CheckBoard(pos));
245-
246-
245+
246+
247247
if(SqAttacked(pos->KingSq[side],pos->side,pos)) {
248248
TakeMove(pos);
249249
return FALSE;
250250
}
251-
251+
252252
return TRUE;
253-
253+
254254
}
255255

256256
void TakeMove(S_BOARD *pos) {
257-
257+
258258
ASSERT(CheckBoard(pos));
259-
259+
260260
pos->hisPly--;
261261
pos->ply--;
262-
262+
263263
ASSERT(pos->hisPly >= 0 && pos->hisPly < MAXGAMEMOVES);
264264
ASSERT(pos->ply >= 0 && pos->ply < MAXDEPTH);
265-
265+
266266
int move = pos->history[pos->hisPly].move;
267267
int from = FROMSQ(move);
268-
int to = TOSQ(move);
269-
268+
int to = TOSQ(move);
269+
270270
ASSERT(SqOnBoard(from));
271271
ASSERT(SqOnBoard(to));
272-
272+
273273
if(pos->enPas != NO_SQ) HASH_EP;
274274
HASH_CA;
275275

@@ -282,7 +282,7 @@ void TakeMove(S_BOARD *pos) {
282282

283283
pos->side ^= 1;
284284
HASH_SIDE;
285-
285+
286286
if(MFLAGEP & move) {
287287
if(pos->side == WHITE) {
288288
AddPiece(to-10, pos, bP);
@@ -298,25 +298,25 @@ void TakeMove(S_BOARD *pos) {
298298
default: ASSERT(FALSE); break;
299299
}
300300
}
301-
301+
302302
MovePiece(to, from, pos);
303-
303+
304304
if(PieceKing[pos->pieces[from]]) {
305305
pos->KingSq[pos->side] = from;
306306
}
307-
307+
308308
int captured = CAPTURED(move);
309309
if(captured != EMPTY) {
310310
ASSERT(PieceValid(captured));
311311
AddPiece(to, pos, captured);
312312
}
313-
313+
314314
if(PROMOTED(move) != EMPTY) {
315315
ASSERT(PieceValid(PROMOTED(move)) && !PiecePawn[PROMOTED(move)]);
316316
ClearPiece(from, pos);
317317
AddPiece(from, pos, (PieceCol[PROMOTED(move)] == WHITE ? wP : bP));
318318
}
319-
319+
320320
ASSERT(CheckBoard(pos));
321321

322322
}
@@ -341,7 +341,7 @@ void MakeNullMove(S_BOARD *pos) {
341341
pos->side ^= 1;
342342
pos->hisPly++;
343343
HASH_SIDE;
344-
344+
345345
ASSERT(CheckBoard(pos));
346346
ASSERT(pos->hisPly >= 0 && pos->hisPly < MAXGAMEMOVES);
347347
ASSERT(pos->ply >= 0 && pos->ply < MAXDEPTH);
@@ -364,21 +364,8 @@ void TakeNullMove(S_BOARD *pos) {
364364
if(pos->enPas != NO_SQ) HASH_EP;
365365
pos->side ^= 1;
366366
HASH_SIDE;
367-
367+
368368
ASSERT(CheckBoard(pos));
369369
ASSERT(pos->hisPly >= 0 && pos->hisPly < MAXGAMEMOVES);
370370
ASSERT(pos->ply >= 0 && pos->ply < MAXDEPTH);
371371
}
372-
373-
374-
375-
376-
377-
378-
379-
380-
381-
382-
383-
384-

search.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static const int minDepth = 3;
1010

1111
// Razoring Values
1212
static const int RazorDepth = 2;
13-
static const int RazorMargin = 400;
13+
static const int RazorMargin[3] = {0, 350, 500};
1414

1515
// LMR Values
1616
static const int LateMoveDepth = 3;
@@ -106,17 +106,17 @@ static int Quiescence(int alpha, int beta, S_BOARD *pos, S_SEARCHINFO *info) {
106106
return 0;
107107
}
108108

109+
if(pos->ply > MAXDEPTH - 1) {
110+
return EvalPosition(pos);
111+
}
112+
109113
// Mate Distance Pruning
110114
alpha = MAX(alpha, -INFINITE + pos->ply);
111115
beta = MIN(beta, INFINITE - pos->ply);
112116
if (alpha >= beta) {
113117
return alpha;
114118
}
115119

116-
if(pos->ply > MAXDEPTH - 1) {
117-
return EvalPosition(pos);
118-
}
119-
120120
int Score = EvalPosition(pos);
121121

122122
ASSERT(Score>-INFINITE && Score<INFINITE);
@@ -224,21 +224,21 @@ static int AlphaBeta(int alpha, int beta, int depth, S_BOARD *pos, S_SEARCHINFO
224224
return 0;
225225
}
226226

227-
// Razoring (not done if in null move)
228-
if (depth <= RazorDepth && !PvMove && !InCheck && pos->history[pos->hisPly].move) {
229-
if (EvalPosition(pos) + RazorMargin < alpha) {
230-
// drop into qSearch if move most likely won't beat alpha
231-
info->nodesPruned++;
232-
return Quiescence(alpha, beta, pos, info);
233-
}
234-
}
235-
236227
if (Score >= beta && abs(Score) < ISMATE) {
237228
info->nullCut++;
238229
return beta;
239230
}
240231
}
241232

233+
// Razoring (not done if in null move)
234+
if (depth <= RazorDepth && !PvMove && !InCheck && pos->history[pos->hisPly].move) {
235+
if (EvalPosition(pos) + RazorMargin[depth] <= alpha) {
236+
// drop into qSearch if move most likely won't beat alpha
237+
info->nodesPruned++;
238+
return Quiescence(alpha, beta, pos, info);
239+
}
240+
}
241+
242242
S_MOVELIST list[1];
243243
GenerateAllMoves(pos,list);
244244

seeChess.exe

0 Bytes
Binary file not shown.

seeChessAN.exe

81 KB
Binary file not shown.

0 commit comments

Comments
 (0)