Rules now become static which makes apparently much more sense.

This commit is contained in:
2006-01-16 16:42:32 +00:00
parent 9167829467
commit 42e56fde4f

View File

@ -13,23 +13,23 @@ import suicideChess.Square.NotAValidSquare;
public class Rules { public class Rules {
private ArrayList<Move> legalMovesNonCapture; private static ArrayList<Move> legalMovesNonCapture;
private ArrayList<Move> legalMovesCapture; private static ArrayList<Move> legalMovesCapture;
public class UnexpectedError extends Exception { // public class UnexpectedError extends Exception {
/* // /*
* Generated by Eclipse // * Generated by Eclipse
*/ // */
private static final long serialVersionUID = 7448113740797323379L; // private static final long serialVersionUID = 7448113740797323379L;
//
UnexpectedError(String s) { super(s); }; // UnexpectedError(String s) { super(s); };
} // }
public Rules () { // public Rules () {
legalMovesNonCapture = new ArrayList<Move>(); // legalMovesNonCapture = new ArrayList<Move>();
legalMovesCapture = new ArrayList<Move>(); // legalMovesCapture = new ArrayList<Move>();
} // }
/** /**
* Computes the possible moves according to the current status of the {@link Board} and the * Computes the possible moves according to the current status of the {@link Board} and the
@ -41,8 +41,10 @@ public class Rules {
* @see Square * @see Square
* @see Board * @see Board
*/ */
public void legalMovesForPlayer(Board board, int color) throws NotAValidSquare, UnexpectedError { public static void legalMovesForPlayer(Board board, int color) throws NotAValidSquare {
// Find it! There is only one king, so look for it and stop legalMovesNonCapture = new ArrayList<Move>();
legalMovesCapture = new ArrayList<Move>();
Square square; Square square;
for(int squareNb = 0; squareNb < Board.NB_OF_SQUARES; squareNb++) { for(int squareNb = 0; squareNb < Board.NB_OF_SQUARES; squareNb++) {
square = new Square(squareNb); square = new Square(squareNb);
@ -64,7 +66,7 @@ public class Rules {
* @see Square * @see Square
* @see Board * @see Board
*/ */
public void legalMovesFromSquare(Square fromSquare, Board board) throws NotAValidSquare, UnexpectedError { public static void legalMovesFromSquare(Square fromSquare, Board board) throws NotAValidSquare {
Move validMove; Move validMove;
Square toSquare; Square toSquare;
@ -156,7 +158,7 @@ public class Rules {
} }
break; break;
default: default:
throw new UnexpectedError("ERROR 01."); throw new RuntimeException("ERROR 01.");
} }
if (board.getPiece(toSquare).getPieceNumber()!=Piece.NONE) { if (board.getPiece(toSquare).getPieceNumber()!=Piece.NONE) {
normalMove= false; //cannot move forward if there is a piece normalMove= false; //cannot move forward if there is a piece