Skip to content

Commit

Permalink
Cornered Bishop Fix (#325)
Browse files Browse the repository at this point in the history
Bench: 3332916

ELO | 37.00 +- 12.06 (95%)
SPRT | 8.0+0.08s Threads=1 Hash=8MB
LLR | 2.95 (-2.94, 2.94) [-1.00, 4.00]
GAMES | N: 1216 W: 297 L: 168 D: 751
  • Loading branch information
jhonnold authored Dec 29, 2021
1 parent 3ac1057 commit 80df1c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "board.h"
#include "nn.h"
#include "search.h"
#include "uci.h"
#include "util.h"

const int PHASE_VALUES[6] = {0, 3, 3, 5, 10, 0};
Expand Down Expand Up @@ -65,13 +66,38 @@ BitBoard Threats(Board* board, int stm) {
return threatened;
}

// Idea from SF to correct positions not in classical chess
// https://tcec-chess.com/#div=frc4ld&game=27&season=21
Score FRCCorneredBishop(Board* board) {
static const Score v = 25;

Score fix = 0;

if (getBit(PieceBB(BISHOP, WHITE), A1) && getBit(PieceBB(PAWN, WHITE), B2))
fix -= (3 + !!getBit(OccBB(BOTH), B3)) * v;

if (getBit(PieceBB(BISHOP, WHITE), H1) && getBit(PieceBB(PAWN, WHITE), G2))
fix -= (3 + !!getBit(OccBB(BOTH), G3)) * v;

if (getBit(PieceBB(BISHOP, BLACK), A8) && getBit(PieceBB(PAWN, BLACK), B7))
fix += (3 + !!getBit(OccBB(BOTH), B6)) * v;

if (getBit(PieceBB(BISHOP, BLACK), H8) && getBit(PieceBB(PAWN, BLACK), G7))
fix += (3 + !!getBit(OccBB(BOTH), G6)) * v;

return board->stm == WHITE ? fix : -fix;
}

// Main evalution method
Score Evaluate(Board* board, ThreadData* thread) {
SearchData* data = &thread->data;

if (IsMaterialDraw(board)) return 0;

int score = OutputLayer(board->accumulators[board->stm][board->ply], board->accumulators[board->xstm][board->ply]);

if (CHESS_960) score += FRCCorneredBishop(board);

score += data->contempt[board->stm];

int scalar = 128 + board->phase;
Expand Down
17 changes: 15 additions & 2 deletions src/uci.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,15 @@ void UCILoop() {
} else if (!strncmp(in, "threats", 7)) {
PrintBB(Threats(&board, board.stm));
} else if (!strncmp(in, "eval", 4)) {
int score = Predict(&board);
board.ply = 0;

board.accumulators[WHITE] = threads->accumulators[WHITE];
board.accumulators[BLACK] = threads->accumulators[BLACK];

RefreshAccumulator(board.accumulators[WHITE][0], &board, WHITE);
RefreshAccumulator(board.accumulators[BLACK][0], &board, BLACK);

int score = Evaluate(&board, threads);
score = board.stm == WHITE ? score : -score;

for (int r = 0; r < 8; r++) {
Expand All @@ -270,8 +278,13 @@ void UCILoop() {
printf(" %c |", PIECE_TO_CHAR[board.squares[sq]]);
} else if (board.squares[sq] < WHITE_KING) {
popBit(board.occupancies[BOTH], sq);
int new = Predict(&board);

RefreshAccumulator(board.accumulators[WHITE][0], &board, WHITE);
RefreshAccumulator(board.accumulators[BLACK][0], &board, BLACK);

int new = Evaluate(&board, threads);
new = board.stm == WHITE ? new : -new;

int diff = score - new;
printf("%+7d|", diff);
setBit(board.occupancies[BOTH], sq);
Expand Down

0 comments on commit 80df1c7

Please sign in to comment.