package suicideChess; import java.util.Comparator; import suicideChess.Board.NoPieceOnSquare; import suicideChess.Square.NotAValidSquare; /** * This class is used to sort Moves in the alpha beta pruning. * * @author Jean-Baptiste Hétier * @version $LastChangedRevision$, $LastChangedDate$ * */ class MoveCompare implements Comparator { private Board bitboard; //the bitboard to do the moves from private int sortOrder; //increasing or decreasing order /** * Constructor * @param bitboard, the bitboard to do the moves from * @param order, who is playing (black or white) -> will give the order in which to sort (black minimises and white maximises) */ public MoveCompare(Board bitboard) { this.bitboard = bitboard; if(this.bitboard.getCurrentPlayer()==Piece.BLACK) { // low scores are considered "smaller" than high ones and thus will be first after ordering sortOrder= -1; } else { // high scores are consideres "smaller" than low ones sortOrder= +1; } } public int compare(Move one, Move another) { Board oneBoardCopy = new Board(bitboard); Board anotherBoardCopy = new Board(bitboard); try { oneBoardCopy.doMove(one); anotherBoardCopy.doMove(another); } catch (NoPieceOnSquare e) { e.printStackTrace(); } catch (NotAValidSquare e) { e.printStackTrace(); } if(oneBoardCopy.getBoardValue()