Skip to content

Commit

Permalink
incremental open file detection
Browse files Browse the repository at this point in the history
+ earlier LMR reduction of 2 plies
  • Loading branch information
nescitus committed Jan 18, 2015
1 parent 8a1562f commit 106f2a5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Quiescence.cpp
Expand Up @@ -100,7 +100,7 @@ int badCapture(smove move) {
**************************************************************************/

if (b.pawn_ctrl[b.color[move.from] ^ 1][move.to]
&& e.PIECE_VALUE[move.piece_cap] + 200 < e.PIECE_VALUE[move.piece_from])
&& e.PIECE_VALUE[move.piece_cap] + 200 < e.PIECE_VALUE[move.piece_from])
return 1;

/* if a capture is not processed, it cannot be considered bad */
Expand Down
11 changes: 10 additions & 1 deletion board(0x88).cpp
Expand Up @@ -44,6 +44,11 @@ void clearBoard() {
b.PieceCount[ WHITE ] [ i ] = 0;
b.PieceCount[ BLACK ] [ i ] = 0;
}

for (int i = 0; i<8; i++) {
b.PawnsOnFile[WHITE][i] = 0;
b.PawnsOnFile[BLACK][i] = 0;
}
}

/******************************************************************************
Expand Down Expand Up @@ -72,9 +77,12 @@ void fillSq(U8 color, U8 piece, S8 sq) {
// update pawn material
b.PawnMaterial[color] += e.PIECE_VALUE[piece];

// update pawn hashkey - please note conversion to a 32-bit integer
// update pawn hashkey
b.phash ^= zobrist.piecesquare[piece][color][sq];

// update counter of pawns on a given file
++b.PawnsOnFile[color][COL(sq)];

// update squares controlled by pawns
if (color == WHITE) {
if (IS_SQ(sq + NE)) b.pawn_ctrl[WHITE][sq + NE]++;
Expand Down Expand Up @@ -121,6 +129,7 @@ void clearSq(S8 sq) {
if (IS_SQ(sq + SW)) b.pawn_ctrl[BLACK][sq + SW]--;
}

--b.PawnsOnFile[color][COL(sq)];
b.PawnMaterial[color] -= e.PIECE_VALUE[piece];
b.phash ^= zobrist.piecesquare[piece][color][sq];
}
Expand Down
2 changes: 2 additions & 0 deletions changes.txt
@@ -1,3 +1,5 @@
v. 1.1.12(2005.01.18) : two-ply late move reduction is triggered earlier
v. 1.1.11(2005.01.17) : history table takes color into account
v. 1.1.10(2015.01.15) : bad captures sorted behind ordinary moves
v. 1.1.9 (2015.01.13) : Blind() fuction to sort captures
v. 1.1.8 (2015.01.12) : much better passed pawn eval #TUNE
Expand Down
2 changes: 1 addition & 1 deletion com.cpp
Expand Up @@ -219,7 +219,7 @@ int com_uci(char * command) {
if (!strcmp(command, "uci")) {
mode = PROTO_UCI;

com_send("id name CPW-Engine 1.1.11");
com_send("id name CPW-Engine 1.1.12");
com_send("id author Computer Chess Wiki");

printf("option name Hash type spin default 64 min 1 max 1024\n");
Expand Down
32 changes: 4 additions & 28 deletions eval.cpp
Expand Up @@ -345,46 +345,22 @@ void EvalBishop(S8 sq, S8 side) {
void EvalRook(S8 sq, S8 side) {
int att = 0;
int mob = 0;
int ownBlockingPawns = 0;
int oppBlockingPawns = 0;
int stepFwd;
int nextSq;

v.gamePhase += 2;

/**************************************************************************
* An ugly hack to detect open files. Merging it with mobility eval would *
* have been better, but less readable *
/*************************************************************************/

if (side == WHITE) stepFwd = NORTH;
else stepFwd = SOUTH;
nextSq = sq + stepFwd;

while (IS_SQ(nextSq)) {
if (b.pieces[nextSq] == PAWN) {
if (b.color[nextSq] == side) {
ownBlockingPawns++;
break;
}
else
oppBlockingPawns++;
}
nextSq += stepFwd;
}


/**************************************************************************
* Bonus for open and half-open files is merged with mobility score. *
* Bonus for open files targetting enemy king is added to attWeight[] *
/*************************************************************************/

if ( !ownBlockingPawns ) {
if ( !oppBlockingPawns ) {
if (b.PawnsOnFile[side][COL(sq)] == 0) {
if (b.PawnsOnFile[!side][COL(sq)] == 0) { // fully open file
v.mgMob[side] += e.ROOK_OPEN;
v.egMob[side] += e.ROOK_OPEN;
if (abs(COL(sq) - COL(b.KingLoc[!side])) < 2)
v.attWeight[side] += 1;
} else {
} else { // half open file
v.mgMob[side] += e.ROOK_HALF;
v.egMob[side] += e.ROOK_HALF;
if (abs(COL(sq) - COL(b.KingLoc[!side])) < 2)
Expand Down
9 changes: 4 additions & 5 deletions move.cpp
Expand Up @@ -34,15 +34,14 @@ int move_make(smove move) {
if ( (move.piece_from == PAWN) || move_iscapt(move) )
b.ply = 0;

/* a piece vacates its initial square */
clearSq(move.from);

/* in case of a capture, the "to" square must be cleared,
else incrementally updated stuff gets blown up
*/
else incrementally updated stuff gets blown up */
if ( b.pieces[move.to] != PIECE_EMPTY )
clearSq(move.to);

/* a piece vacates its initial square */
clearSq(move.from);

/* a piece arrives to its destination square */
fillSq( !b.stm, move.piece_to, move.to );

Expand Down
18 changes: 9 additions & 9 deletions search.cpp
Expand Up @@ -413,7 +413,7 @@ int Search( U8 depth, U8 ply, int alpha, int beta, int can_null, int is_pv ) {
******************************************************************/

reduction_depth = 1;
if (moves_tried > 8) reduction_depth += 1;
if (moves_tried > 6) reduction_depth += 1;
new_depth -= reduction_depth;
}

Expand Down Expand Up @@ -654,10 +654,10 @@ int isRepetition() {

void clearHistoryTable() {
for (int cl = 0; cl < 2; cl++)
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++) {
sd.history[cl][i][j] = 0;
}
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++) {
sd.history[cl][i][j] = 0;
}
}

/******************************************************************************
Expand All @@ -668,10 +668,10 @@ void clearHistoryTable() {

void ageHistoryTable() {
for (int cl = 0; cl < 2; cl++)
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++) {
sd.history[cl][i][j] = sd.history[cl][i][j] / 8;
}
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++) {
sd.history[cl][i][j] = sd.history[cl][i][j] / 8;
}
}

/******************************************************************************
Expand Down
1 change: 1 addition & 0 deletions stdafx.h
Expand Up @@ -100,6 +100,7 @@ struct sboard {
int PieceMaterial[2];
int PawnMaterial[2];
U8 PieceCount[2][6];
U8 PawnsOnFile[2][8];
U8 pawn_ctrl[2][128];
};
extern sboard b;
Expand Down

0 comments on commit 106f2a5

Please sign in to comment.