Rules now become static which makes apparently much more sense.
This commit is contained in:
@ -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,8 +66,8 @@ 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;
|
||||||
|
|
||||||
Piece movingPiece = board.getPiece(fromSquare);
|
Piece movingPiece = board.getPiece(fromSquare);
|
||||||
@ -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
|
||||||
|
Reference in New Issue
Block a user