NEW CLASS: Square
Class Square and Move work. I'm still working on BitBoard.
This commit is contained in:
51
src/suicideChess/Square.java
Normal file
51
src/suicideChess/Square.java
Normal file
@ -0,0 +1,51 @@
|
||||
package suicideChess;
|
||||
|
||||
/**
|
||||
* @author djib
|
||||
*
|
||||
* This class avoids the use of strings for squares
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRevision$
|
||||
* $LastChangedBy$
|
||||
*/
|
||||
|
||||
|
||||
public class Square {
|
||||
private char file;
|
||||
private int fileNb;
|
||||
private int rank;
|
||||
|
||||
public class NotAValidSquare extends Exception {
|
||||
/**
|
||||
* Generated by Eclipse
|
||||
*/
|
||||
private static final long serialVersionUID = 7586171991212094565L;
|
||||
|
||||
NotAValidSquare(String s) { super(s); };
|
||||
}
|
||||
|
||||
public Square(String square) throws NotAValidSquare {
|
||||
if (square.length()!=2 || !(Character.isLetter(square.toCharArray()[0])) ||
|
||||
!(Character.isDigit(square.toCharArray()[1]))) {
|
||||
throw new NotAValidSquare(square);
|
||||
}
|
||||
file = Character.toLowerCase(square.toCharArray()[0]);
|
||||
fileNb = ((int)file) - ((int)'a') + 1;
|
||||
rank = Integer.parseInt(square.substring(1,2));
|
||||
}
|
||||
|
||||
public char getFile() {
|
||||
return file;
|
||||
}
|
||||
public int getRank() {
|
||||
return rank;
|
||||
}
|
||||
public int getFileNb() {
|
||||
return fileNb;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(file)+String.valueOf(rank);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user