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