001 package ai;
002 import core.Color;
003 import core.Piece;
004 import rules.Board;
005 import rules.GameState;
006 import rules.Pawn;
007
008 /**
009 * The ScaledPieceHeuristic minimizes the fraction of pieces controlled.
010 */
011 public class ScaledPieceHeuristic implements Heuristic {
012
013 /**
014 * @see Heuristic
015 */
016 public int heuristic(GameState currentState) {
017 int total = 0;
018 int diff = 0;
019 Board board = ((GameState) currentState).getBoard();
020 for(int x = 0; x < 8; x++){
021 for(int y = 0; y < 8; y++){
022 Piece p = board.get(x, y);
023 int weight = 1;
024 if (p instanceof Pawn)
025 weight = 1;
026 if (p.getColor() == Color.WHITE){
027 diff -= weight;
028 total += weight;
029 } else if (p.getColor() == Color.BLACK) {
030 diff += weight;
031 total += weight;
032 }
033 }
034 }
035 int ans = (diff * 100000 / total);
036 if (currentState.getCurrentColor() == Color.BLACK)
037 return -ans;
038 else
039 return ans;
040 }
041 }