Skip to content

Commit

Permalink
Changed the king heuristic so that kings are worth twice as much as n…
Browse files Browse the repository at this point in the history
…ormal pieces. For some reason Collections.max blows up on containers of type Double.
  • Loading branch information
Aaron committed Apr 30, 2016
1 parent df046c5 commit a2189bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Move getThunkMove() {
public Move getMinimaxMove(int depth, boolean inJumpSequence) {
ArrayList<Board> boardFrontier = null;
ArrayList<Move> moveFrontier = null;
ArrayList<Double> moveScores = new ArrayList<Double>();
ArrayList<Integer> moveScores = new ArrayList<Integer>();

if (inJumpSequence) {
/* Generate the frontier only for the piece that just moves */
Expand Down Expand Up @@ -140,7 +140,7 @@ public Move getMinimaxMove(int depth, boolean inJumpSequence) {
}

/* Determine the maximum minimax score and which move led to that score */
double maxScore = Double.MIN_VALUE;
int maxScore = Integer.MIN_VALUE;
Move bestMove = null;

for (int i = 0; i < moveScores.size(); ++i) {
Expand All @@ -159,9 +159,9 @@ public Move getMinimaxMove(int depth, boolean inJumpSequence) {
return bestMove;
}

public double getMinimaxScore(Color color, Board b, int depth, boolean inJumpSequence) {
public int getMinimaxScore(Color color, Board b, int depth, boolean inJumpSequence) {
ArrayList<Board> boardFrontier;
ArrayList<Double> moveScores = new ArrayList<Double>();
ArrayList<Integer> moveScores = new ArrayList<Integer>();
Color otherColor = (color == Color.BLACK ? Color.WHITE : Color.BLACK);

if (depth == 0) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public double getMinimaxScore(Color color, Board b, int depth, boolean inJumpSeq
}

for (Board board : boardFrontier) {
double moveScore = getMinimaxScore(nextColor, board, depth - 1, inJumpSequence);
int moveScore = getMinimaxScore(nextColor, board, depth - 1, inJumpSequence);
moveScores.add(moveScore);
}

Expand Down
6 changes: 3 additions & 3 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ public boolean isPromotionLocation(Location location) {
location.row == BOARD_SIZE - 1 );
}

public double getHeuristic(Color color) {
public int getHeuristic(Color color) {
/* Kings are weighted more, so we count for them twice */
double blackHeuristic = blackPieces + blackKings * 1.5;
double whiteHeuristic = whitePieces + whiteKings * 1.5;
int blackHeuristic = blackPieces + blackKings * 2;
int whiteHeuristic = whitePieces + whiteKings * 2;
return - (color == Color.BLACK ?
(blackHeuristic - whiteHeuristic) :
(whiteHeuristic - blackHeuristic));
Expand Down

0 comments on commit a2189bb

Please sign in to comment.