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 3de1901..a28df7d 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -449,15 +449,13 @@ public class Board { noKings = (color == Color.BLACK && this.blackKings == 0) || (color == Color.WHITE && this.whiteKings == 0); - if (piece7.getColor() == color) { - eitherSquaresOccupiedByActiveMan |= active7; + if (piece7 != null && piece7.getColor() == color) { + eitherSquaresOccupiedByActiveMan |= (active7 && piece7.getType() == Type.NORMAL); + neitherSquaresOccupiedByPassiveMan &= (active7 && piece7.getType() == Type.NORMAL); } - if (piece26.getColor() == color) { - eitherSquaresOccupiedByActiveMan |= active26; - } - - if (piece7.getColor() == color && piece26.getColor() == color) { - if () + if (piece26 != null && piece26.getColor() == color) { + eitherSquaresOccupiedByActiveMan |= (active26 && piece26.getType() == Type.NORMAL); + neitherSquaresOccupiedByPassiveMan &= (active26 && piece26.getType() == Type.NORMAL); } if (noKings && eitherSquaresOccupiedByActiveMan && neitherSquaresOccupiedByPassiveMan) @@ -499,6 +497,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; @@ -516,6 +532,9 @@ public class Board { } if (GameConstants.MOB) { heuristic += mobHeuristic(color); + } + if (GameConstants.KCENT) { + heuristic += kcentHeuristic(color); } return heuristic;