Reputation: 39
I am curious what adjustments I can make to my evaluation function in a chess game for different difficulties. Assuming the player is an average player, if I were to have say, easy, medium and hard, what would I evaluate? Currently I am just checking material, piece-square tables and mobility and I cannot beat it. Are there some aspects of an evaluation function(I am talking about the Basic Evaluation Features on this page: https://www.chessprogramming.org/Evaluation) that are essential to keep and some that I can implement that will have a more of an effect than others.
My search algorithm (minimax with alpha-beta):
public int miniMaxAlphaBeta(int depth, boolean maximisingPlayer, int alpha, int beta) {
if(maximisingPlayer) {
if(depth == 0) return evaluate();
int best = -9999;
m: for(Piece piece : getWhitePieces()) for(Move move : piece.getMoves()) {
movePiece(piece, move.x, move.y);
if(piece.isFriendlyKingInCheck()) { undoMove(); continue; }
int score = miniMaxAlphaBeta(depth-1, !maximisingPlayer, alpha, beta);
undoMove();
if(score > best) {
best = score;
//here I'll record the piece and move to make
}
alpha = Math.max(alpha, best);
if(beta<=alpha) break m;
}
return best;
} else {
if(depth == 0) return -evaluate();
int best = 9999;
m: for(Piece piece : getBlackPieces()) for(Move move : piece.getMoves()) {
MovePiece(piece, move.x, (move.y);
if(piece.isFriendlyKingInCheck) { undoMove(); continue; }
int score = miniMaxAlphaBeta(depth-1, !maximisingPlayer, alpha, beta);
undoMove();
if(score < best) {
best = score;
//here I'll record the piece and move to make
}
beta = Math.min(beta, best);
if(beta<=alpha) break m;
}
return best;
}
}
My evaluation function:
public int evaluate() {
int whiteMaterial = 0;
int blackMaterial = 0;
int positionalValue = 0;
int mobility = 0;
for(Piece piece : getAllPieces()) {
if (piece.isBlackPiece()) blackMaterial += getPieceValue(piece); //returns relative piece value of piece
else if (p.isWhitePiece()) whiteMaterial += getPieceValue(piece);
positionalValue += getPieceSquareTableValue(piece); //adds whichever value it is on it's piece-square table at it's current position
mobility += getMobility(piece); //adds 15 for every move this piece can make
}
return (whiteMaterial-blackMaterial) + positionalValue + mobility;
}
Upvotes: 2
Views: 252
Reputation: 7
Hard - use everything you've got: - search for the max depth - count pieces - count mobility - count king's safety - count controlling center of the board - use quiescence search, check extention
Medium and Easy - properly lower serach depth and skip some of the mentioned features.
Upvotes: 0