From ef64023a4915b96dec7911195f9e303865888d57 Mon Sep 17 00:00:00 2001 From: aah13002 Date: Sat, 30 Apr 2016 23:10:36 -0400 Subject: [PATCH] added KCENT heuristic --- src/controller/GameConstants.java | 1 + src/model/Board.java | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/controller/GameConstants.java b/src/controller/GameConstants.java index 8ac6678..288c9b1 100644 --- a/src/controller/GameConstants.java +++ b/src/controller/GameConstants.java @@ -15,6 +15,7 @@ public class GameConstants { public static final boolean APEX = true; public static final boolean BACK = true; public static final boolean CENT = true; + public static final boolean KCENT = 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 03e243d..c801115 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -450,12 +450,12 @@ public class Board { noKings = (color == Color.BLACK && this.blackKings == 0) || (color == Color.WHITE && this.whiteKings == 0); if (piece7 != null && piece7.getColor() == color) { - eitherSquaresOccupiedByActiveMan |= active7; - neitherSquaresOccupiedByPassiveMan &= active7; + eitherSquaresOccupiedByActiveMan |= (active7 && piece7.getType() == Type.NORMAL); + neitherSquaresOccupiedByPassiveMan &= (active7 && piece7.getType() == Type.NORMAL); } if (piece26 != null && piece26.getColor() == color) { - eitherSquaresOccupiedByActiveMan |= active26; - neitherSquaresOccupiedByPassiveMan &= active26; + eitherSquaresOccupiedByActiveMan |= (active26 && piece26.getType() == Type.NORMAL); + neitherSquaresOccupiedByPassiveMan &= (active26 && piece26.getType() == Type.NORMAL); } if (noKings && eitherSquaresOccupiedByActiveMan && neitherSquaresOccupiedByPassiveMan) @@ -478,6 +478,24 @@ public class Board { return 0; } + /** + * 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. + * @param color + * @return + */ + public int kcentHeuristic(Color color) { + int sum = 0; + int[] locations = {11, 12, 15, 16, 20, 21, 24, 25}; + for (int k : locations) { + Piece p = this.getPiece(this.samuelMapping(k)); + if (p != null && p.getType() == Type.KING && !isActive(p)) + ++sum; + } + return sum; + } + public int getHeuristic(Color color) { /* Kings are weighted more, so we count for them twice */ int heuristic = 0; @@ -495,6 +513,9 @@ public class Board { } if (GameConstants.MOB) { heuristic += mobHeuristic(color); + } + if (GameConstants.KCENT) { + heuristic += kcentHeuristic(color); } return heuristic;