Skip to content

Commit

Permalink
better naming for basic heuristic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 24, 2017
1 parent fdd007a commit ae13be0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
12 changes: 6 additions & 6 deletions include/Heuristic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
2 changes: 1 addition & 1 deletion include/MinimaxSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef std::unique_ptr<Move> mup;
class MinimaxSearch
{
private:
static const int maxDepth = 1;
static const int maxDepth = 6;
Heuristic heuristic;

double minValue(std::unique_ptr<BitBoard> &board, int currentDepth);
Expand Down
29 changes: 15 additions & 14 deletions src/Heuristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...

Expand All @@ -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
Expand Down

0 comments on commit ae13be0

Please sign in to comment.