Implemented loadFromFen method in Board
This commit is contained in:
parent
3fe6ea5540
commit
17f110e7f7
@ -400,8 +400,7 @@ public class Board implements Cloneable {
|
||||
for (int l = j; l < Character.digit(places[k], 10); l++, j++)
|
||||
boardArr[j][i] = null;
|
||||
--j;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Color color = Character.isUpperCase(places[k]) ? Color.WHITE : Color.BLACK;
|
||||
switch (Character.toLowerCase(places[k])) {
|
||||
case 'k':
|
||||
@ -435,7 +434,34 @@ public class Board implements Cloneable {
|
||||
// Active color
|
||||
log.setActiveColor(Color.fromFirstChar(parts[1].charAt(0)));
|
||||
|
||||
// TODO: other fields, synchronize with log and game
|
||||
// Castling rights
|
||||
for (char c : parts[2].toCharArray())
|
||||
switch (c) {
|
||||
case 'K':
|
||||
castlingRights.get(Color.WHITE).put(Type.KING, true);
|
||||
case 'Q':
|
||||
castlingRights.get(Color.WHITE).put(Type.QUEEN, true);
|
||||
case 'k':
|
||||
castlingRights.get(Color.BLACK).put(Type.KING, true);
|
||||
case 'q':
|
||||
castlingRights.get(Color.BLACK).put(Type.QUEEN, true);
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
System.err
|
||||
.printf("Unknown character '%c' in castling rights declaration of FEN string '%s'", c, fen);
|
||||
}
|
||||
|
||||
// En passant availability
|
||||
if (!parts[3].equals("-")) log.setEnPassant(Position.fromSAN(parts[3]));
|
||||
|
||||
// Halfmove clock
|
||||
log.setHalfmoveClock(Integer.parseInt(parts[4]));
|
||||
|
||||
// Fullmove counter
|
||||
log.setFullmoveCounter(Integer.parseInt(parts[5]));
|
||||
|
||||
// TODO: Synchronize with game
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user