Skip to content

Commit 852d073

Browse files
author
Oliver Brausch
committed
5.11.4 Code simplify. Elimnate battacked. Raising in nullmove. Hismax change.
1 parent 9e1feae commit 852d073

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

src/Readme.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
OliThink5 (c) Oliver Brausch 24.Mai.2025, ob112@web.de, http://brausch.org
1+
OliThink5 (c) Oliver Brausch 08.Jun.2025, ob112@web.de, http://brausch.org
22

3-
Version: 5.11.3
3+
Version: 5.11.4
44
Protocol: CECP v2 (winboard/xboard)
55
HashSize: 128MB
66
Ponder: Yes
@@ -9,10 +9,13 @@ EndgameTables: No
99
AnalyzeMode: Basic
1010
SearchMethods: Nullmove, Internal Iterative Reduction, Check Extension, LMR
1111
Evaluation: Just mobility and a very simple pawnprogressing evaluation
12-
LinesOfCode: 1335
12+
LinesOfCode: 1322
1313
Stability: 100%
1414
Special thanks to Dann Corbit for his support and contribution.
1515

16+
v5.11.4: changes since 5.11.3:
17+
Code simplify. Elimnate battacked. Raising in nullmove. Hismax change.
18+
1619
v5.11.3: changes since 5.11.2:
1720
Small adaptions in eval, search and time control
1821

src/olithink.c

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#define VER "5.11.3"
2-
/* OliThink5 (c) Oliver Brausch 24.Mai.2025, ob112@web.de, http://brausch.org */
1+
#define VER "5.11.4"
2+
/* OliThink5 (c) Oliver Brausch 08.Jun.2025, ob112@web.de, http://brausch.org */
33
#include <stdio.h>
44
#include <string.h>
55
#ifdef _WIN64
@@ -376,28 +376,15 @@ int key090(u64 b, int f) {
376376
return (int)((_b * 0x0080402010080400LL) >> 58);
377377
}
378378

379-
int keyDiag(u64 _b) {
380-
return (int)((_b * 0x0202020202020202LL) >> 58);
381-
}
382-
383379
int key045(u64 b, int f) {
384-
return keyDiag(b & bmask45[f]);
380+
return (int)(((b & bmask45[f]) * 0x0202020202020202LL) >> 58);
385381
}
386382

387383
int key135(u64 b, int f) {
388-
return keyDiag(b & bmask135[f]);
389-
}
390-
391-
#define DUALATT(x, y, c) (battacked(x, c) || battacked(y, c))
392-
int battacked(int f, int c) {
393-
if (PCAP(f, c) & P.piece[PAWN]) return 1;
394-
if (NCAP(f, c) & P.piece[KNIGHT]) return 1;
395-
if (KCAP(f, c) & P.piece[KING]) return 1;
396-
if (RCAP(f, c) & RQU) return 1;
397-
if (BCAP(f, c) & BQU) return 1;
398-
return 0;
384+
return (int)(((b & bmask135[f]) * 0x0202020202020202LL) >> 58);
399385
}
400386

387+
#define DUALATT(x, y, c) (attacked(x, c) | attacked(y, c) | ((KCAP(x, c) | KCAP(y, c)) & P.piece[KING]))
401388
u64 reach(int f, int c) {
402389
return (NCAP(f, c) & P.piece[KNIGHT]) | (RCAP(f, c) & RQU) | (BCAP(f, c) & BQU);
403390
}
@@ -447,7 +434,7 @@ void move(Move m, int c, int d) {
447434
if (a) {
448435
if (a == ENP) { // Enpassant Capture
449436
t = (t&7) | (f&56); a = PAWN;
450-
} else if (a == ROOK && CASTLE(c^1)) { //Revoke castling rights.
437+
} else if (a == ROOK) { //Revoke castling rights.
451438
flags &= crevoke[t];
452439
}
453440
P.piece[a] ^= BIT[t];
@@ -477,7 +464,7 @@ void move(Move m, int c, int d) {
477464
P.hash ^= hashxor[f | ROOK << 6 | c << 9];
478465
P.hash ^= hashxor[t | ROOK << 6 | c << 9];
479466
}
480-
} else if (p == ROOK && CASTLE(c)) {
467+
} else if (p == ROOK) {
481468
flags &= crevoke[f];
482469
}
483470
BOARD = P.color[0] | P.color[1];
@@ -518,7 +505,7 @@ void regPromotions(int f, int c, u64 bt, Movep* mp, int cap, int queen) {
518505
void regKings(Move m, u64 bt, Movep* mp, int c, int cap) {
519506
while (bt) {
520507
int t = pullLsb(&bt);
521-
if (battacked(t, c)) continue;
508+
if (attacked(t, c) | (KCAP(t, c) & P.piece[KING])) continue;
522509
mp->list[mp->n++] = m | _TO(t) | (cap ? _CAP(identPiece(t)) : 0LL);
523510
}
524511
}
@@ -549,10 +536,10 @@ int generateCheckEsc(u64 ch, u64 apin, int c, int k, Movep *mp) {
549536
if (ch & (nmoves[k] | kmoves[k])) return 1; //We can't move anything in between!
550537

551538
d = getDir(bf, k);
552-
if (d == 8) fl = RATT1(bf) & RATT1(k) & ~BOARD;
553-
else if (d == 16) fl = RATT2(bf) & RATT2(k) & ~BOARD;
554-
else if (d == 32) fl = BATT3(bf) & BATT3(k) & ~BOARD;
555-
else fl = BATT4(bf) & BATT4(k) & ~BOARD;
539+
if (d == 8) fl = RATT1(bf) & RATT1(k);
540+
else if (d == 16) fl = RATT2(bf) & RATT2(k);
541+
else if (d == 32) fl = BATT3(bf) & BATT3(k);
542+
else fl = BATT4(bf) & BATT4(k);
556543

557544
while (fl) {
558545
int f = pullLsb(&fl);
@@ -935,17 +922,18 @@ int search(u64 ch, int c, int d, int ply, int alpha, int beta, int null, Move se
935922
if (!hmove) hmove = he->move;
936923
}
937924

938-
int wstat = wstack[COUNT] = ch ? -MAXSCORE+ply : he->key == hp ? he->value : eval(c);
925+
int wstat = wstack[COUNT] = ch ? -MAXSCORE : he->key == hp ? he->value : eval(c);
939926
if (!ch && !pvnode) {
940927
if (d <= 3 && wstat + 400 < beta) { w = quiesce(ch, c, ply, alpha, beta); if (w < beta) return w; }
941-
if (d <= 8 && wstat - 88*d > beta) return wstat;
928+
if (d <= 8 && wstat - 88*d > beta) return beta;
942929
}
943930

931+
int raising = !ch && ply >= 2 && wstat >= wstack[COUNT-2] && wstack[COUNT-2] != -MAXSCORE;
944932
hstack[COUNT] = hp;
945933
//Null Move - pvnode => null == 0
946934
null = null && !ch && beta > -MAXSCORE+500 && d > 1 && wstat > alpha && (ply < 2 || (mstack[COUNT-2] >> 27));
947935
if (null && bitcnt(P.color[c] & (~P.piece[PAWN]) & (~pinnedPieces(P.king[c], oc))) > 1) {
948-
int R = (10 + d + nullvariance(wstat - alpha))/4;
936+
int R = (9 + d + nullvariance(wstat - alpha))/4 + raising;
949937
doMove(0, c);
950938
w = -search(0LL, oc, d-R, ply+1, -beta, 1-beta, 0, 0);
951939
undoMove(0, c);
@@ -956,8 +944,7 @@ int search(u64 ch, int c, int d, int ply, int alpha, int beta, int null, Move se
956944

957945
Movep mp, mpq; mpq.n = 0;
958946
Pos pos; pos.hash = 0;
959-
int raising = !ch && ply >= 2 && wstat >= wstack[COUNT-2];
960-
int first = NO_MOVE, hismax = -1;
947+
int first = NO_MOVE, hismax = -9999;
961948
for (n = HASH; n <= (ch ? NOISY : QUIET); n++) {
962949
int nd = d - 1;
963950
if (n == HASH) {
@@ -992,15 +979,15 @@ int search(u64 ch, int c, int d, int ply, int alpha, int beta, int null, Move se
992979
else if (n == QUIET && m != killer[ply]) { // LMR, but don't reduce killers
993980
int his = history[m & 0x1FFF];
994981
if (his > hismax) hismax = his;
995-
else if (d < 5 && (his < -1 || his*his < hismax)) {
982+
else if (d < 5 && (his < 0 || his*his < hismax)) {
996983
undoMove(0, c); memcpy(&P, &pos, sizeof(Pos)); continue;
997984
} else if (d >= 2) ext-= (d + 1)/3;
998985
}
999986

1000987
int firstPVNode = first == NO_MOVE && pvnode;
1001988
if (!firstPVNode) w = -search(nch, oc, nd+ext, ply+1, -alpha-1, -alpha, 1, 0);
1002-
if (w > alpha && ext < 0) w = -search(nch, oc, nd, ply+1, -alpha-1, -alpha, 1, 0);
1003-
if ((w > alpha && w < beta) || firstPVNode) w = -search(nch, oc, nd, ply+1, -beta, -alpha, 0, 0);
989+
if (ext < 0 && w > alpha) w = -search(nch, oc, nd, ply+1, -alpha-1, -alpha, 1, 0);
990+
if (firstPVNode || (w > alpha && w < beta)) w = -search(nch, oc, nd, ply+1, -beta, -alpha, 0, 0);
1004991

1005992
undoMove(0, c); memcpy(&P, &pos, sizeof(Pos));
1006993
if (sabort) return alpha;
@@ -1285,8 +1272,8 @@ int main(int argc, char **argv) {
12851272
for (i = 0; i < 64; i++) BIT[i] = 1LL << i;
12861273
for (i = 0; i < 128; i++) pmoves[0][i] = pawnfree[0][i] = pawnfile[0][i] = pawnhelp[0][i] = 0LL;
12871274
for (i = 0; i < 384; i++) pcaps[0][i] = 0LL;
1288-
for (i = 0; i < 64; i++) bmask45[i] = _bishop45(i, 0LL, 0) | BIT[i];
1289-
for (i = 0; i < 64; i++) bmask135[i] = _bishop135(i, 0LL, 0) | BIT[i];
1275+
for (i = 0; i < 64; i++) bmask45[i] = _bishop45(i, 0LL, 0);
1276+
for (i = 0; i < 64; i++) bmask135[i] = _bishop135(i, 0LL, 0);
12901277
for (i = 0; i < 64; i++) crevoke[i] = 0x3FF, rankb[i/8] |= BIT[i], fileb[i&7] |= BIT[i];
12911278
for (i = 0; i < 64; i++) kmoves[i] = nmoves[i] = 0LL, RANK[0][i] = RANK[1][63-i] = 1 + (i >> 3);
12921279
for (i = 0; i < 64; i++) if ((i/8)%2 != (i&7)%2) whitesq |= BIT[i];

0 commit comments

Comments
 (0)