Skip to content

Commit

Permalink
Added different heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed May 1, 2016
1 parent e4b23eb commit 2511138
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/controller/GameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public class GameConstants {
public static final int MAX_PASSIVE_MOVES = 50;
public static final int MAX_SEARCH_DEPTH = 7;
public static final int BOARD_SIZE = 8;

/* Parameters to the heuristic */
public static final boolean APEX = true;
public static final boolean BACK = true;
public static final boolean CENT = true;
public static final boolean MOB = true;
public static final boolean PIECE_DIFFERENTIAL = true;

}
50 changes: 46 additions & 4 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;

import controller.GameConstants;

/**
* The representation is a 8x8 grid where
* A[row][col] marks the position of the checker piece.
Expand Down Expand Up @@ -387,16 +389,56 @@ public boolean isPromotionLocation(Location location) {
location.row == BOARD_SIZE - 1 );
}

public int getHeuristic(Color color) {
/* Kings are weighted more, so we count for them twice */

public int pieceDifferentialHeuristic(Color color) {
int blackHeuristic = blackPieces + blackKings;
int whiteHeuristic = whitePieces + whiteKings;
return - (color == Color.BLACK ?
return - (color == Color.BLACK ?
(blackHeuristic - whiteHeuristic) :
(whiteHeuristic - blackHeuristic));
}

public int apexHeuristic(Color color) {

return 0;
}

public int backHeuristic(Color color) {

return 0;
}

public int centHeuristic(Color color) {

return 0;
}

public int mobHeuristic(Color color) {

return 0;
}

public int getHeuristic(Color color) {
/* Kings are weighted more, so we count for them twice */
int heuristic = 0;
if (GameConstants.PIECE_DIFFERENTIAL) {
heuristic += pieceDifferentialHeuristic(color);
}
if (GameConstants.APEX) {
heuristic += apexHeuristic(color);
}
if (GameConstants.BACK) {
heuristic += backHeuristic(color);
}
if (GameConstants.CENT) {
heuristic += centHeuristic(color);
}
if (GameConstants.MOB) {
heuristic += mobHeuristic(color);
}

return heuristic;
}

public Piece getPiece(Location location) {
return representation[location.row][location.column];
}
Expand Down

0 comments on commit 2511138

Please sign in to comment.