TestXBoardProtocol hasn't changed much. Now it is in a package called test.
NEW FILE: TestMoves -> purpose is to test the Move class NEW FILE: Move -> this is a first implementation of a simple class that reads a string and converts it to a move or the opposite. NEW FILE: BitBoard -> this class really doesn't do anything yet. It only has definition of 14 bitboards but they are not created yet.
This commit is contained in:
96
src/suicideChess/Move.java
Normal file
96
src/suicideChess/Move.java
Normal file
@ -0,0 +1,96 @@
|
||||
package suicideChess;
|
||||
|
||||
/**
|
||||
* @author djib
|
||||
*
|
||||
* This file contains the moves representation.
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRev$
|
||||
* $LastChangedBy$
|
||||
*/
|
||||
|
||||
public class Move {
|
||||
|
||||
/********
|
||||
* DATA *
|
||||
********/
|
||||
|
||||
//integers
|
||||
private String fromSquare;
|
||||
private String toSquare;
|
||||
private String promotionPiece;
|
||||
private boolean isPromotion;
|
||||
|
||||
public class NotAValidMoveException extends Exception {
|
||||
NotAValidMoveException(String s) { super(s); };
|
||||
}
|
||||
|
||||
/***************
|
||||
* CONSTRUCTOR *
|
||||
***************/
|
||||
|
||||
//The string is of type e2e4 (4 chars), b7b8q (5 chars) for promotions
|
||||
public Move(String move) throws NotAValidMoveException {
|
||||
isPromotion = false;
|
||||
promotionPiece = "";
|
||||
switch (move.length()) {
|
||||
case 5:
|
||||
isPromotion = true;
|
||||
promotionPiece = move.substring(4,5);
|
||||
//no break statement here on purpose
|
||||
case 4:
|
||||
fromSquare = move.substring(0,2);
|
||||
toSquare = move.substring(2,4);
|
||||
break;
|
||||
default:
|
||||
throw new NotAValidMoveException("Invalid Move: "+move);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***********
|
||||
* METHODS *
|
||||
***********/
|
||||
|
||||
public String fromSquare() {
|
||||
return fromSquare;
|
||||
}
|
||||
public String toSquare() {
|
||||
return toSquare;
|
||||
}
|
||||
public boolean isPromotionMove() {
|
||||
return isPromotion;
|
||||
}
|
||||
|
||||
public void setFromSquare(String square) {
|
||||
fromSquare = square;
|
||||
}
|
||||
public void setToSquare(String square) {
|
||||
toSquare = square;
|
||||
}
|
||||
public void setIsPromotionMove(String piece) {
|
||||
if (promotionPiece.length()==0) {
|
||||
isPromotion=false;
|
||||
} else {
|
||||
isPromotion=true;
|
||||
promotionPiece=piece;
|
||||
}
|
||||
}
|
||||
|
||||
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(" ");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user