Browse Source

Rules now become static which makes apparently much more sense.

master
djib 16 years ago
parent
commit
42e56fde4f
  1. 40
      src/suicideChess/Rules.java

40
src/suicideChess/Rules.java

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

Loading…
Cancel
Save