diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-29 16:57:12 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-29 16:57:12 +0200 |
| commit | 163f59d29b2c3a6236d825373437955667a1d5d5 (patch) | |
| tree | 44d468180bb00213a8e268eb9b6cd07be82a199d /src/bot.cpp | |
| parent | 9ce8ba4a63c1fbfa49af17ee7364b9165098a20f (diff) | |
improving check generation
Diffstat (limited to 'src/bot.cpp')
| -rw-r--r-- | src/bot.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/bot.cpp b/src/bot.cpp index a1b4fb2..f1f1fd6 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -17,7 +17,7 @@ const int KNIGHT_VALUE = 320; const int BISHOP_VALUE = 330; const int ROOK_VALUE = 500; const int QUEEN_VALUE = 900; -const int CHECK = 10; +const int CHECK_BIAS = 10; const int MATE = 10000; const int PAWN_TABLE[64] = { @@ -218,21 +218,21 @@ float minimax(int depth, Game *b, float alpha, float beta) { } int PSTIndex(int square, bool white) { return white ? square : (56 ^ square); } -float EvaluateBoardForWhite(Game *b, int depth) { +float EvaluateBoardForWhite(Game *g, int depth) { float score = 0; - if (b->state == WHITE_WON) { + if (g->state == WHITE_WON) { return MATE + depth; } - if (b->state == BLACK_WON) { + if (g->state == BLACK_WON) { return -MATE - depth; } - if (b->state == STALEMATE || b->state == DRAW) { + if (g->state == STALEMATE || g->state == DRAW) { return 0; } for (int i = 0; i < 64; i++) { - Piece piece = b->pieces[i]; + Piece piece = g->pieces[i]; if (piece.type == NONEPIECE) continue; @@ -271,11 +271,18 @@ float EvaluateBoardForWhite(Game *b, int depth) { else score -= value; } - if (IsPieceTypeAttacked(b, KING, true)) { - score -= CHECK; // white king attacked + + Position WhiteKingPosition = FindKing(g, g->turn); + bool IsWhiteIncheck = IsSquareAttacked(g, WhiteKingPosition, !g->turn); + + Position BlackKingPosition = FindKing(g, g->turn); + bool IsBlackInCheck = IsSquareAttacked(g, BlackKingPosition, !g->turn); + + if (IsWhiteIncheck) { + score -= CHECK_BIAS; // white king attacked } - if (IsPieceTypeAttacked(b, KING, false)) { - score += CHECK; // black king attacked + if (IsBlackInCheck) { + score += CHECK_BIAS; // black king attacked } return score; } |
