Version 0.9.2
============= External config file. Move ordering.
This commit is contained in:
52
src/suicideChess/MoveComparator.java
Normal file
52
src/suicideChess/MoveComparator.java
Normal file
@ -0,0 +1,52 @@
|
||||
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) {
|
||||
sortOrder= +1;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user