Version 0.9.2

=============
External config file.
Move ordering.
This commit is contained in:
2006-07-04 18:24:40 +00:00
parent f67d82d129
commit 7dc781c25e
5 changed files with 119 additions and 13 deletions

View 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;
}
}