Skip to content

Commit 79105fa

Browse files
authored
Merge pull request #28 from konsolas/king-safety
Better evaluation
2 parents d810b27 + 87d7d3c commit 79105fa

File tree

12 files changed

+421
-161
lines changed

12 files changed

+421
-161
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9)
22
project(Topple)
33

44
set(CMAKE_CXX_STANDARD 17)
5-
set(TOPPLE_VERSION 0.7.1)
5+
set(TOPPLE_VERSION 0.7.2)
66

77
# Source files for different targets
88
set(SOURCE_FILES
@@ -50,7 +50,7 @@ if (MINGW)
5050
endif ()
5151

5252
# Set -march for the Topple target
53-
target_compile_options(Topple PUBLIC -march=native -O3)
53+
target_compile_options(Topple PUBLIC -march=broadwell -O3)
5454

5555
# Configure the "Release" target
5656
if (CMAKE_BUILD_TYPE STREQUAL "Release")

board.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "board.h"
1212
#include "testing/catch.hpp"
1313
#include "move.h"
14+
#include "hash.h"
1415

1516
void board_t::move(move_t move) {
1617
// Copy the record
@@ -388,7 +389,7 @@ void board_t::switch_piece(Team side, Piece piece, uint8_t sq) {
388389
if (HASH) { // Update hash
389390
U64 square_hash = zobrist::squares[sq][side][piece];
390391
record[now].hash ^= square_hash;
391-
if(piece == PAWN) record[now].pawn_hash ^= square_hash;
392+
if(piece == PAWN || piece == KING) record[now].kp_hash ^= square_hash;
392393
if(sq_data[sq].occupied) record[now].material.info.inc(side, piece);
393394
else record[now].material.info.dec(side, piece);
394395
}
@@ -569,6 +570,17 @@ bool board_t::is_repetition_draw(int search_ply) const {
569570
return false;
570571
}
571572

573+
bool board_t::is_material_draw() const {
574+
if(record[now].material.info.w_pawns || record[now].material.info.b_pawns ||
575+
record[now].material.info.w_queens || record[now].material.info.b_queens ||
576+
record[now].material.info.w_rooks || record[now].material.info.b_rooks) {
577+
return false;
578+
} else {
579+
return record[now].material.info.w_bishops + record[now].material.info.b_bishops
580+
+ record[now].material.info.w_knights + record[now].material.info.b_knights <= 1;
581+
}
582+
}
583+
572584
void board_t::mirror() {
573585
// Mirror side
574586
record[now].next_move = (Team) !record[now].next_move;

board.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct game_record_t {
2828
uint8_t ep_square; // Target square for en-passant after last double pawn move
2929
int halfmove_clock; // Moves since last pawn move or capture
3030
U64 hash;
31-
U64 pawn_hash;
31+
U64 kp_hash;
3232
material_data_t material;
3333
};
3434

@@ -67,6 +67,7 @@ struct alignas(64) board_t {
6767
bool gives_check(move_t move) const;
6868

6969
bool is_repetition_draw(int search_ply) const;
70+
bool is_material_draw() const;
7071

7172
int see(move_t move) const;
7273
U64 non_pawn_material(Team side) const;

eval.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,29 +278,16 @@ void evaluator_t::eval_pst(const board_t &board, int &mg, int &eg) {
278278
eg -= params.pst[BLACK][type][sq][EG];
279279
}
280280
}
281-
282-
pieces = board.bb_pieces[WHITE][KING];
283-
while (pieces) {
284-
uint8_t sq = pop_bit(pieces);
285-
mg += params.pst[WHITE][KING][sq][MG];
286-
eg += params.pst[WHITE][KING][sq][EG];
287-
}
288-
289-
pieces = board.bb_pieces[BLACK][KING];
290-
while (pieces) {
291-
uint8_t sq = pop_bit(pieces);
292-
mg -= params.pst[BLACK][KING][sq][MG];
293-
eg -= params.pst[BLACK][KING][sq][EG];
294-
}
295281
}
296282

297283
void evaluator_t::eval_pawns(const board_t &board, int &mg, int &eg) {
298-
U64 pawn_hash = board.record[board.now].pawn_hash;
284+
U64 pawn_hash = board.record[board.now].kp_hash;
299285
size_t index = (pawn_hash & pawn_hash_entries);
300286
pawns::structure_t *entry = pawn_hash_table.data() + index;
301287
if(entry->get_hash() != pawn_hash) {
302288
*entry = pawns::structure_t(params, pawn_hash,
303-
board.bb_pieces[WHITE][PAWN], board.bb_pieces[BLACK][PAWN]);
289+
board.bb_pieces[WHITE][PAWN], board.bb_pieces[BLACK][PAWN],
290+
board.bb_pieces[WHITE][KING], board.bb_pieces[BLACK][KING]);
304291
}
305292

306293
mg += entry->get_eval_mg();
@@ -342,7 +329,7 @@ void evaluator_t::eval_movement(const board_t &board, int &mg, int &eg) {
342329
mg -= params.ks_pawn_shield[pawn_shield_b];
343330

344331
// Check for attacks on the king
345-
int king_danger[2] = {};
332+
int king_danger[2] = {params.kat_zero, params.kat_zero};
346333

347334
if(board.bb_pieces[BLACK][ROOK] != 0) {
348335
if(king_circle[WHITE] & open_files) {

0 commit comments

Comments
 (0)