diff --git a/src/controller/Game.java b/src/controller/Game.java index 4555ee3..85a2a39 100755 --- a/src/controller/Game.java +++ b/src/controller/Game.java @@ -124,8 +124,6 @@ public Move getMinimaxMove(int depth, boolean inJumpSequence) { /* Generate the frontier for all pieces */ boardFrontier = board.generateFrontier(GameConstants.THUNK_COLOR); moveFrontier = board.generateAllMoves(GameConstants.THUNK_COLOR); - System.out.println("Board frontier size: " + boardFrontier.size()); - System.out.println("Move frontier size: " + moveFrontier.size()); } Color nextColor; @@ -174,7 +172,7 @@ public int getMinimaxScore(Color color, Board b, int depth, boolean inJumpSequen boardFrontier = b.generateFrontier(color); } - /* If we have reached the maximum depth or an end state for the gam */ + /* If we have reached the maximum depth or an end state for the game */ if (depth == 0 || b.getBlackPieces() == 0 || b.getWhitePieces() == 0 || boardFrontier.size() == 0) { Color otherColor = (color == Color.BLACK ? Color.WHITE : Color.BLACK); @@ -183,7 +181,9 @@ public int getMinimaxScore(Color color, Board b, int depth, boolean inJumpSequen Color nextColor; /* Determine the next color to move */ - if (GameConstants.THUNK_COLOR == Color.BLACK && !inJumpSequence) { + if (inJumpSequence) { + nextColor = color; + } else if (GameConstants.THUNK_COLOR == Color.BLACK) { nextColor = Color.WHITE; } else { nextColor = Color.BLACK; @@ -195,9 +195,7 @@ public int getMinimaxScore(Color color, Board b, int depth, boolean inJumpSequen } if (color == GameConstants.THUNK_COLOR) { - /* Since these scores are obtained from when it is the other - * player's turn, we want to minimize....I think - */ + // Maximize return Collections.max(moveScores); } else { diff --git a/src/controller/GameConstants.java b/src/controller/GameConstants.java index d4f3895..989e7fe 100644 --- a/src/controller/GameConstants.java +++ b/src/controller/GameConstants.java @@ -8,5 +8,5 @@ public class GameConstants { public static final Color THUNK_COLOR = Color.WHITE; public static final Color USER_COLOR = Color.BLACK; public static final int MAX_PASSIVE_MOVES = 50; - public static final int MAX_SEARCH_DEPTH = 4; + public static final int MAX_SEARCH_DEPTH = 5; } diff --git a/src/model/Board.java b/src/model/Board.java index 4dac958..131cec7 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -20,6 +20,8 @@ public class Board { private int blackPieces; private int whitePieces; + private int blackKings; + private int whiteKings; // Move properties private int movesSinceCapture; @@ -96,13 +98,15 @@ public void movePiece(Move move) { int monkeyRow = (destRow + sourceRow)/2; int monkeyCol = (destCol + sourceCol)/2; - Color color_removed = representation[monkeyRow][monkeyCol].getColor(); + Piece removed = representation[monkeyRow][monkeyCol]; - if (color_removed == Color.BLACK) { + if (removed.getColor() == Color.BLACK) { --blackPieces; + if (removed.getType() == Type.KING) --blackKings; } else { --whitePieces; + if (removed.getType() == Type.KING) --whiteKings; } /* Remove the piece being jumped ("monkey in the middle") */ @@ -127,6 +131,11 @@ public void movePiece(Move move) { if (canPromote(moved)) { moved.promote(); + if (moved.color == Color.BLACK) { + ++blackKings; + } else { + ++whiteKings; + } } /* Update the last piece that was moved */ @@ -379,9 +388,12 @@ public boolean isPromotionLocation(Location location) { } public int getHeuristic(Color color) { + /* Kings are weighted more, so we count for them twice */ + int blackHeuristic = blackPieces + blackKings; + int whiteHeuristic = whitePieces + whiteKings; return color == Color.BLACK ? - this.blackPieces - this.whitePieces : - this.whitePieces - this.blackPieces; + (blackHeuristic - whiteHeuristic) : + (whiteHeuristic - blackHeuristic); } public Piece getPiece(Location location) {