Skip to content

Commit

Permalink
Added piece count tracker and simple heuristic function
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Apr 30, 2016
1 parent 70192da commit 4077858
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class Board {

private Piece lastPieceMoved;
private Move lastMove;

private int blackPieces;
private int whitePieces;

// Move properties
private int movesSinceCapture;
Expand All @@ -28,7 +31,9 @@ public Board() {
movesSinceCapture = 0;
init();
lastPieceMoved = null;
lastMove = null;
lastMove = null;
blackPieces = 12;
whitePieces = 12;
}

/**
Expand All @@ -46,6 +51,8 @@ public Board(Board other) {
movesSinceCapture = other.getMovesSinceCapture();
lastPieceMoved = other.getLastPieceMoved();
lastMove = other.getLastMove();
blackPieces = other.blackPieces;
whitePieces = other.whitePieces;
}

/**
Expand Down Expand Up @@ -87,6 +94,10 @@ public void movePiece(Move move) {
int monkeyRow = (destRow + sourceRow)/2;
int monkeyCol = (destCol + sourceCol)/2;

Color color_removed = representation[monkeyRow][monkeyCol].getColor();

if (color_removed == Color.BLACK) --blackPieces; else --whitePieces;

/* Remove the piece being jumped ("monkey in the middle") */
representation[monkeyRow][monkeyCol] = null;
}
Expand Down Expand Up @@ -355,10 +366,13 @@ public boolean canPromote(Piece p) {
(row == BOARD_SIZE - 1 && p.getColor() == Color.BLACK));
}

public int getHeuristic(Color color) {
return color == Color.BLACK ? this.blackPieces : this.whitePieces;
}

public Piece getPiece(Location location) {
return representation[location.row][location.column];
}


public Piece[][] getRepresentation() {
return this.representation;
Expand Down

0 comments on commit 4077858

Please sign in to comment.