aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 8b9273e..3054b0d 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -10,8 +10,16 @@ int KNIGHT_VALUE = 200;
int BISHOP_VALUE = 300;
int ROOK_VALUE = 400;
int QUEEN_VALUE = 900;
+int CHECK = 300;
int MATE = 10000;
+int KNIGHT_TABLE[64] = {-50, -40, -30, -30, -30, -30, -40, -50, -40, -20, 0,
+ 0, 0, 0, -20, -40, -30, 0, 10, 15, 15, 10,
+ 0, -30, -30, 5, 15, 20, 20, 15, 5, -30, -30,
+ 0, 15, 20, 20, 15, 0, -30, -30, 5, 10, 15,
+ 15, 10, 5, -30, -40, -20, 0, 5, 5, 0, -20,
+ -40, -50, -40, -30, -30, -30, -30, -40, -50};
+
const int SEARCH_DEPTH = 3;
Move EngineGetBestMove(Game *b) {
@@ -92,8 +100,8 @@ float EvaluateBoardForWhite(Game *b) {
float score = 0;
bool isStaleMate = false;
-
GetLegalMoves(b);
+
if (b->state == WHITE_WON) {
return MATE;
}
@@ -104,7 +112,8 @@ float EvaluateBoardForWhite(Game *b) {
isStaleMate = true;
}
- for (Piece piece : b->pieces) {
+ for (int i = 0; i < 64; i++) {
+ Piece piece = b->pieces[i];
if (piece.type == NONE)
continue;
@@ -116,6 +125,7 @@ float EvaluateBoardForWhite(Game *b) {
break;
case KNIGHT:
value = KNIGHT_VALUE;
+ value += KNIGHT_TABLE[i];
break;
case BISHOP:
value = BISHOP_VALUE;
@@ -135,6 +145,10 @@ float EvaluateBoardForWhite(Game *b) {
else
score -= value;
}
+ bool isCheck = IsPieceTypeAttacked(b, KING, 1);
+ if (isCheck) {
+ score += CHECK;
+ }
if (isStaleMate) {
return 0;
}