aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp27
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;
}