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

@ -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);
}
}