Version 0.1

===========
This is a first version where it is possible to play in console.
Rules are not implemented and program crashes when moving a piece that does not
exit or when trying to capture our own pieces...
This commit is contained in:
2006-01-07 16:38:45 +00:00
parent f61b6bb90d
commit 9cd26bfd0c
8 changed files with 818 additions and 0 deletions

View File

@ -0,0 +1,61 @@
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));
//perform extra check ?
if (SuicideChess.SQUARE_CHECK_INVALID) {
if (fileNb<1 || fileNb>Board.NB_OF_FILES) {
throw new NotAValidSquare(square);
}
if (rank<1 || rank>Board.NB_OF_RANKS) {
throw new NotAValidSquare(square);
}
}
}
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);
}
}