From f1dd4c98301979d13ca2f29bdb653ea083112d30 Mon Sep 17 00:00:00 2001 From: aah13002 Date: Sat, 30 Apr 2016 23:31:29 -0400 Subject: [PATCH] Added weighted coefficient constants for each heuristic paramter --- src/controller/GameConstants.java | 8 ++++++++ src/model/Board.java | 30 +++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/controller/GameConstants.java b/src/controller/GameConstants.java index 288c9b1..7bba8eb 100644 --- a/src/controller/GameConstants.java +++ b/src/controller/GameConstants.java @@ -19,4 +19,12 @@ public class GameConstants { public static final boolean MOB = true; public static final boolean PIECE_DIFFERENTIAL = true; + /* Heuristic parameter weights */ + public static final int APEX_WEIGHT = 2; + public static final int BACK_WEIGHT = 2; + 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; + } diff --git a/src/model/Board.java b/src/model/Board.java index c801115..9aa2f20 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -422,8 +422,8 @@ public class Board { } public boolean isActive(Piece piece) { - ArrayList jumpFrontier = this.generateJumpMovesForPiece(piece); if (piece == null) return false; + ArrayList jumpFrontier = this.generateJumpMovesForPiece(piece); return jumpFrontier.size() != 0; } @@ -473,15 +473,23 @@ public class Board { return 0; } + /** + * "The parameter is credited with 1 for each square + * to which the active side could move one or more pieces in + * the normal fashion, disregarding the fact that jump moves + * may or may not be available. + * @param color + * @return + */ public int mobHeuristic(Color color) { - - return 0; + ArrayList moves = this.generateAllMoves(color); + return moves.size(); } /** - * The parameter is credited with 1 for each of the + * "The parameter is credited with 1 for each of the * following squares: 11, 12, 15, 16, 20, 21, 24, and 25 - * which is occupied by a passive king. + * which is occupied by a passive king." * @param color * @return */ @@ -500,22 +508,22 @@ public class Board { /* Kings are weighted more, so we count for them twice */ int heuristic = 0; if (GameConstants.PIECE_DIFFERENTIAL) { - heuristic += pieceDifferentialHeuristic(color); + heuristic += pieceDifferentialHeuristic(color)*GameConstants.PIECE_DIFFERENTIAL_WEIGHT; } if (GameConstants.APEX) { - heuristic += apexHeuristic(color); + heuristic += apexHeuristic(color)*GameConstants.APEX_WEIGHT; } if (GameConstants.BACK) { - heuristic += backHeuristic(color); + heuristic += backHeuristic(color)*GameConstants.BACK_WEIGHT; } if (GameConstants.CENT) { - heuristic += centHeuristic(color); + heuristic += centHeuristic(color)*GameConstants.CENT_WEIGHT; } if (GameConstants.MOB) { - heuristic += mobHeuristic(color); + heuristic += mobHeuristic(color)*GameConstants.MOB_WEIGHT; } if (GameConstants.KCENT) { - heuristic += kcentHeuristic(color); + heuristic += kcentHeuristic(color)*GameConstants.KCENT_WEIGHT; } return heuristic;