Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Pole heuristic parameter
  • Loading branch information
Aaron committed May 1, 2016
1 parent f1dd4c9 commit 553371f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/controller/GameConstants.java
Expand Up @@ -17,6 +17,7 @@ public class GameConstants {
public static final boolean CENT = true;
public static final boolean KCENT = true;
public static final boolean MOB = true;
public static final boolean POLE = true;
public static final boolean PIECE_DIFFERENTIAL = true;

/* Heuristic parameter weights */
Expand All @@ -25,6 +26,7 @@ public class GameConstants {
public static final int CENT_WEIGHT = 2;
public static final int KCENT_WEIGHT = 2;
public static final int MOB_WEIGHT = 1;
public static final int PIECE_DIFFERENTIAL_WEIGHT = 2;
public static final int POLE_WEIGHT = 2;
public static final int PIECE_DIFFERENTIAL_WEIGHT = 3;

}
31 changes: 29 additions & 2 deletions src/model/Board.java
Expand Up @@ -410,9 +410,9 @@ public class Board {
int row = piece.getLocation().row;
int col = piece.getLocation().column;
boolean up = row > 0,
down = row < GameConstants.BOARD_SIZE,
down = row < GameConstants.BOARD_SIZE - 1,
left = col > 0,
right = row < GameConstants.BOARD_SIZE;
right = col < GameConstants.BOARD_SIZE - 1;
if (up && left && this.representation[row-1][col-1] == null) ++num;
if (up && right && this.representation[row-1][col+1] == null) ++num;
if (down && left && this.representation[row+1][col-1] == null) ++num;
Expand Down Expand Up @@ -504,6 +504,30 @@ public class Board {
return sum;
}

/**
* "The parameter is credited with 1 for
* each passive man that is completely
* surrounded by empty squares."
* @param color
* @return
*/
public int poleHeuristic(Color color) {
int sum = 0;
for (int i = 0; i < GameConstants.BOARD_SIZE; ++i) {
for (int j = 0; j < GameConstants.BOARD_SIZE; ++j) {
Piece p = this.representation[i][j];
if (p != null) {
if (p.getType() == Type.NORMAL &&
!isActive(p) &&
emptySquaresSurrounding(p) == 4) {
++sum;
}
}
}
}
return sum;
}

public int getHeuristic(Color color) {
/* Kings are weighted more, so we count for them twice */
int heuristic = 0;
Expand All @@ -522,6 +546,9 @@ public class Board {
if (GameConstants.MOB) {
heuristic += mobHeuristic(color)*GameConstants.MOB_WEIGHT;
}
if (GameConstants.POLE) {
heuristic += poleHeuristic(color)*GameConstants.POLE_WEIGHT;
}
if (GameConstants.KCENT) {
heuristic += kcentHeuristic(color)*GameConstants.KCENT_WEIGHT;
}
Expand Down

0 comments on commit 553371f

Please sign in to comment.