NEW CLASS: Square

Class Square and Move work.

I'm still working on BitBoard.
This commit is contained in:
2006-01-05 13:22:38 +00:00
parent 7ce943724c
commit f737485337
5 changed files with 126 additions and 30 deletions

View File

@ -1,5 +1,7 @@
package suicideChess;
import suicideChess.Square.NotAValidSquare;
/**
* @author djib
*
@ -17,12 +19,17 @@ public class Move {
********/
//integers
private String fromSquare;
private String toSquare;
private Square fromSquare;
private Square toSquare;
private String promotionPiece;
private boolean isPromotion;
public class NotAValidMoveException extends Exception {
/**
* Generated by Eclipse
*/
private static final long serialVersionUID = 2194133427162274651L;
NotAValidMoveException(String s) { super(s); };
}
@ -31,7 +38,7 @@ public class Move {
***************/
//The string is of type e2e4 (4 chars), b7b8q (5 chars) for promotions
public Move(String move) throws NotAValidMoveException {
public Move(String move) throws NotAValidMoveException, NotAValidSquare {
isPromotion = false;
promotionPiece = "";
switch (move.length()) {
@ -40,8 +47,8 @@ public class Move {
promotionPiece = move.substring(4,5);
//no break statement here on purpose
case 4:
fromSquare = move.substring(0,2);
toSquare = move.substring(2,4);
fromSquare = new Square(move.substring(0,2));
toSquare = new Square(move.substring(2,4));
break;
default:
throw new NotAValidMoveException("Invalid Move: "+move);
@ -54,20 +61,23 @@ public class Move {
* METHODS *
***********/
public String fromSquare() {
public Square fromSquare() {
return fromSquare;
}
public String toSquare() {
public Square toSquare() {
return toSquare;
}
public boolean isPromotionMove() {
return isPromotion;
}
public String getPromotionPiece() {
return promotionPiece;
}
public void setFromSquare(String square) {
public void setFromSquare(Square square) {
fromSquare = square;
}
public void setToSquare(String square) {
public void setToSquare(Square square) {
toSquare = square;
}
public void setIsPromotionMove(String piece) {
@ -80,17 +90,6 @@ public class Move {
}
public String toString() {
return fromSquare+toSquare+promotionPiece;
}
public void display() {
System.out.println(" ");
System.out.println("==== Move ====");
System.out.println("From square:"+fromSquare);
System.out.println("To square: "+toSquare);
System.out.println((isPromotion ? "Promotion: "+promotionPiece : "No Promotion"));
System.out.println("===============");
System.out.println(" ");
System.out.println(" ");
return fromSquare.toString()+toSquare+promotionPiece;
}
}