Skip to content

Commit

Permalink
I think its a little smarter now. Kings are now weighted more
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 30, 2016
1 parent 00afb30 commit b702042
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/GameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 16 additions & 4 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Board {

private int blackPieces;
private int whitePieces;
private int blackKings;
private int whiteKings;

// Move properties
private int movesSinceCapture;
Expand Down Expand Up @@ -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") */
Expand All @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b702042

Please sign in to comment.