From 42e56fde4f9def3e3028f6cd98ea0f40021ac55e Mon Sep 17 00:00:00 2001 From: djib Date: Mon, 16 Jan 2006 16:42:32 +0000 Subject: [PATCH] Rules now become static which makes apparently much more sense. --- src/suicideChess/Rules.java | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/suicideChess/Rules.java b/src/suicideChess/Rules.java index 7ee4a55..319d202 100644 --- a/src/suicideChess/Rules.java +++ b/src/suicideChess/Rules.java @@ -13,23 +13,23 @@ import suicideChess.Square.NotAValidSquare; public class Rules { - private ArrayList legalMovesNonCapture; - private ArrayList legalMovesCapture; + private static ArrayList legalMovesNonCapture; + private static ArrayList 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(); - legalMovesCapture = new ArrayList(); - } +// public Rules () { +// legalMovesNonCapture = new ArrayList(); +// legalMovesCapture = new ArrayList(); +// } /** * 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(); + legalMovesCapture = new ArrayList(); + 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