aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bot.cpp8
-rw-r--r--src/evaluate.cpp16
2 files changed, 17 insertions, 7 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 3ea6620..c269665 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -138,7 +138,7 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) {
return beta;
}
}
-static int minimax(int depth, Game *b, int alpha, int beta, int ply) {
+static int search(int depth, Game *b, int alpha, int beta, int ply) {
const uint64_t gameHash = GenerateZobristKey(b);
auto repIt = b->ThreeFoldMap.find(gameHash);
@@ -190,7 +190,7 @@ static int minimax(int depth, Game *b, int alpha, int beta, int ply) {
for (Move move : moves) {
UndoMove undo = MakeMove(move, b);
- int score = minimax(depth - 1, b, alpha, beta, ply + 1);
+ int score = search(depth - 1, b, alpha, beta, ply + 1);
UnMakeMove(undo, b);
@@ -216,7 +216,7 @@ static int minimax(int depth, Game *b, int alpha, int beta, int ply) {
for (Move move : moves) {
UndoMove undo = MakeMove(move, b);
- int score = minimax(depth - 1, b, alpha, beta, ply + 1);
+ int score = search(depth - 1, b, alpha, beta, ply + 1);
UnMakeMove(undo, b);
@@ -261,7 +261,7 @@ static SearchResult SearchDepth(Game *b, int depth, const Move *previousBest) {
for (Move move : moves) {
UndoMove undo = MakeMove(move, b);
- int eval = minimax(depth - 1, b, -INF, INF, 1);
+ int eval = search(depth - 1, b, -INF, INF, 1);
UnMakeMove(undo, b);
diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index a777e0c..3e4f72f 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -1,7 +1,9 @@
#include "evaluate.hpp"
#include "board/board.hpp"
#include "moves.hpp"
+#include <cassert>
#include <cstdlib>
+#include <iostream>
constexpr int PAWN_VALUE = 100;
constexpr int KNIGHT_VALUE = 320;
@@ -105,10 +107,18 @@ static int ForceKingToEdgeBonus(const Position enemyKing,
int CountBoardMaterial(Game *g) {
int score = 0;
- for (int i = 0; i < 64; i++) {
+ uint64_t piece_bitboard = g->PieceBitboard;
+ while (piece_bitboard != 0) {
+ int i = __builtin_ctzll(piece_bitboard);
+ piece_bitboard &= piece_bitboard - 1;
+
const Piece piece = g->pieces[i];
- if (piece.type == NONEPIECE)
- continue;
+
+ if (piece.type == NONEPIECE) {
+ assert(false && "in piece bitboard found none piece");
+ std::cout << "Internal error\n";
+ exit(1);
+ }
int value = 0;