From 2511138a5a18fc636ed91aadff18040db8e4b28d Mon Sep 17 00:00:00 2001 From: aah13002 Date: Sat, 30 Apr 2016 21:41:14 -0400 Subject: [PATCH] Added different heuristics --- src/controller/GameConstants.java | 8 +++++ src/model/Board.java | 50 ++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/controller/GameConstants.java b/src/controller/GameConstants.java index 381d95c..8ac6678 100644 --- a/src/controller/GameConstants.java +++ b/src/controller/GameConstants.java @@ -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; + } diff --git a/src/model/Board.java b/src/model/Board.java index 4871ff9..93aecae 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -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. @@ -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]; }