diff --git a/include/Heuristic.hpp b/include/Heuristic.hpp index 2deda63..c440fe3 100644 --- a/include/Heuristic.hpp +++ b/include/Heuristic.hpp @@ -9,10 +9,10 @@ class Heuristic int coeff[10] = {1,1,1,1,1,1,1,1,1,1}; // Feature Functions - int h1() const; - int h2() const; - int h3() const; - int h4() const; + int pawnCount() const; + double kingCount() const; + int safePawns() const; + int safeKings() const; int h5() const; int h6() const; int h7() const; @@ -22,13 +22,13 @@ class Heuristic const int count(uint32_t i) const; - uint32_t b,w,k; + uint32_t b,w,k, active; bool isBlacksTurn; BitBoard *board; public: // Heuristic(int *co[10]) { coeff = *co;}; - const int evaluate(bup &bitboard); + int evaluate(bup &bitboard); }; #endif diff --git a/include/MinimaxSearch.h b/include/MinimaxSearch.h index 845bc1f..fa56d7e 100644 --- a/include/MinimaxSearch.h +++ b/include/MinimaxSearch.h @@ -13,7 +13,7 @@ typedef std::unique_ptr mup; class MinimaxSearch { private: - static const int maxDepth = 1; + static const int maxDepth = 6; Heuristic heuristic; double minValue(std::unique_ptr &board, int currentDepth); diff --git a/src/Heuristic.cpp b/src/Heuristic.cpp index 6a66bfe..b940baf 100644 --- a/src/Heuristic.cpp +++ b/src/Heuristic.cpp @@ -13,18 +13,19 @@ const int Heuristic::count(uint32_t i) const{ return std::bitset<32>(i).count(); } -const int Heuristic::evaluate(bup &bitboard){ +int Heuristic::evaluate(bup &bitboard){ b = bitboard->getBlackPieces(); w = bitboard->getWhitePieces(); k = bitboard->getKings(); isBlacksTurn = bitboard->getIsBlacksTurn(); + active = isBlacksTurn ? b : w; board = &(*bitboard); return - coeff[0]*h1() + - coeff[1]*h2() + - coeff[2]*h3() + - coeff[3]*h4();// + + coeff[0] * pawnCount() + + coeff[1] * kingCount() + + coeff[2] * safePawns() + + coeff[3] * safeKings();// + // Test game was taking too long, let just do 4 for now... @@ -37,27 +38,27 @@ const int Heuristic::evaluate(bup &bitboard){ } // Number of pawns -int Heuristic::h1() const +int Heuristic::pawnCount() const { - return count((isBlacksTurn ? b : w) & ~k); + return count(b & ~k) - count(w & ~k); } -// Number of kings -int Heuristic::h2() const +// Number of kings with 3/2 weight +double Heuristic::kingCount() const { - return count((isBlacksTurn ? b : w) & k); + return 1.5 * (count(b & k) - count(w & k)); } // Number of safe pawns -int Heuristic::h3() const +int Heuristic::safePawns() const { - return count((isBlacksTurn ? b : w) & ~k & BB::edgeLoc); + return count((active & ~k) & BB::edgeLoc); } // Number of safe kings -int Heuristic::h4() const +int Heuristic::safeKings() const { - return count((isBlacksTurn ? b : w) & k & BB::edgeLoc); + return 1.5 * count((active & k) & BB::edgeLoc); } // Aggregated distance of pawns to promotion line