aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 3054b0d..e976d11 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -10,7 +10,7 @@ int KNIGHT_VALUE = 200;
int BISHOP_VALUE = 300;
int ROOK_VALUE = 400;
int QUEEN_VALUE = 900;
-int CHECK = 300;
+int CHECK = 20;
int MATE = 10000;
int KNIGHT_TABLE[64] = {-50, -40, -30, -30, -30, -30, -40, -50, -40, -20, 0,
@@ -22,6 +22,21 @@ int KNIGHT_TABLE[64] = {-50, -40, -30, -30, -30, -30, -40, -50, -40, -20, 0,
const int SEARCH_DEPTH = 3;
+#include <fstream>
+
+void LogMove(const Move &move) {
+ std::ofstream file("moves.txt", std::ios::app);
+
+ if (!file.is_open())
+ return;
+
+ file << static_cast<char>('a' + move.From.file)
+ << static_cast<char>('8' - move.From.rank)
+ << static_cast<char>('a' + move.To.file)
+ << static_cast<char>('8' - move.To.rank);
+
+ file << '\n';
+}
Move EngineGetBestMove(Game *b) {
auto moves = GetLegalMoves(b);
if (moves.size() == 0) {
@@ -30,6 +45,7 @@ Move EngineGetBestMove(Game *b) {
Move bestMove = moves[0];
float BestEval = (b->turn ? -INFINITY : INFINITY);
for (Move move : moves) {
+ LogMove(move);
Game TestBoard = *b;
PlayMove(move, &TestBoard);
float alpha = -INFINITY;
@@ -95,6 +111,7 @@ float minimax(int depth, Game *b, float alpha, float beta) {
return BestEval;
}
}
+int PSTIndex(int square, bool white) { return white ? square : (56 ^ square); }
float EvaluateBoardForWhite(Game *b) {
float score = 0;
@@ -125,7 +142,7 @@ float EvaluateBoardForWhite(Game *b) {
break;
case KNIGHT:
value = KNIGHT_VALUE;
- value += KNIGHT_TABLE[i];
+ value += KNIGHT_TABLE[PSTIndex(i, piece.color)];
break;
case BISHOP:
value = BISHOP_VALUE;
@@ -145,10 +162,11 @@ float EvaluateBoardForWhite(Game *b) {
else
score -= value;
}
- bool isCheck = IsPieceTypeAttacked(b, KING, 1);
- if (isCheck) {
- score += CHECK;
- }
+ if (IsPieceTypeAttacked(b, KING, true))
+ score -= CHECK; // white king attacked
+
+ if (IsPieceTypeAttacked(b, KING, false))
+ score += CHECK; // black king attacked
if (isStaleMate) {
return 0;
}