Files
Sushi/src/suicideChess/MoveComparator.java
djib 9c4916fb1b Version 1.0.2
=============
Corrected a major but in move ordering
and a major bug in the evaluation function.
2006-07-16 17:17:40 +00:00

55 lines
1.7 KiB
Java

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<Move> {
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()<anotherBoardCopy.getBoardValue()) {
return sortOrder;
} else if (oneBoardCopy.getBoardValue()==anotherBoardCopy.getBoardValue()) {
return 0;
}
return -sortOrder;
}
}