Refined IO functionality, fixed FEN string serialization and deserialization #7

Merged
CyB3RC0nN0R merged 7 commits from feature/io into master 2019-10-25 17:01:56 +02:00
3 changed files with 14 additions and 14 deletions
Showing only changes of commit 73f5e17405 - Show all commits

View File

@ -561,7 +561,7 @@ public class Board {
log.setHalfmoveClock(Integer.parseInt(parts[4])); log.setHalfmoveClock(Integer.parseInt(parts[4]));
// Fullmove counter // Fullmove counter
log.setFullmoveCounter(Integer.parseInt(parts[5])); log.setFullmoveNumber(Integer.parseInt(parts[5]));
} }
/** /**

View File

@ -16,7 +16,7 @@ public class Log implements Iterable<MoveNode> {
private Position enPassant; private Position enPassant;
private Color activeColor; private Color activeColor;
private int fullmoveCounter, halfmoveClock; private int fullmoveNumber, halfmoveClock;
public Log() { public Log() {
reset(); reset();
@ -34,14 +34,14 @@ public class Log implements Iterable<MoveNode> {
public Log(Log other, boolean copyVariations) { public Log(Log other, boolean copyVariations) {
enPassant = other.enPassant; enPassant = other.enPassant;
activeColor = other.activeColor; activeColor = other.activeColor;
fullmoveCounter = other.fullmoveCounter; fullmoveNumber = other.fullmoveNumber;
halfmoveClock = other.halfmoveClock; halfmoveClock = other.halfmoveClock;
// The new root is the current node of the copied instance // The new root is the current node of the copied instance
if (!other.isEmpty()) { if (!other.isEmpty()) {
root = new MoveNode(other.current, copyVariations); root = new MoveNode(other.current, copyVariations);
root.setParent(null); root.setParent(null);
current = root; current = root;
} }
} }
@ -76,11 +76,11 @@ public class Log implements Iterable<MoveNode> {
*/ */
public void add(Move move, Piece capturedPiece, boolean pawnMove) { public void add(Move move, Piece capturedPiece, boolean pawnMove) {
enPassant = pawnMove && move.yDist == 2 ? new Position(move.pos.x, move.pos.y + move.ySign) : null; enPassant = pawnMove && move.yDist == 2 ? new Position(move.pos.x, move.pos.y + move.ySign) : null;
if (activeColor == Color.BLACK) ++fullmoveCounter; if (activeColor == Color.BLACK) ++fullmoveNumber;
if (pawnMove || capturedPiece != null) halfmoveClock = 0; if (pawnMove || capturedPiece != null) halfmoveClock = 0;
else++halfmoveClock; else++halfmoveClock;
activeColor = activeColor.opposite(); activeColor = activeColor.opposite();
final MoveNode leaf = new MoveNode(move, capturedPiece, enPassant, activeColor, fullmoveCounter, halfmoveClock); final MoveNode leaf = new MoveNode(move, capturedPiece, enPassant, activeColor, fullmoveNumber, halfmoveClock);
if (isEmpty()) { if (isEmpty()) {
root = leaf; root = leaf;
@ -118,7 +118,7 @@ public class Log implements Iterable<MoveNode> {
current = null; current = null;
enPassant = null; enPassant = null;
activeColor = Color.WHITE; activeColor = Color.WHITE;
fullmoveCounter = 1; fullmoveNumber = 1;
halfmoveClock = 0; halfmoveClock = 0;
} }
@ -156,7 +156,7 @@ public class Log implements Iterable<MoveNode> {
private void update() { private void update() {
activeColor = current.activeColor; activeColor = current.activeColor;
enPassant = current.enPassant; enPassant = current.enPassant;
fullmoveCounter = current.fullmoveCounter; fullmoveNumber = current.fullmoveCounter;
halfmoveClock = current.halfmoveClock; halfmoveClock = current.halfmoveClock;
} }
@ -178,9 +178,9 @@ public class Log implements Iterable<MoveNode> {
public void setActiveColor(Color activeColor) { this.activeColor = activeColor; } public void setActiveColor(Color activeColor) { this.activeColor = activeColor; }
public int getFullmoveCounter() { return fullmoveCounter; } public int getFullmoveNumber() { return fullmoveNumber; }
public void setFullmoveCounter(int fullmoveCounter) { this.fullmoveCounter = fullmoveCounter; } public void setFullmoveNumber(int fullmoveCounter) { this.fullmoveNumber = fullmoveCounter; }
public int getHalfmoveClock() { return halfmoveClock; } public int getHalfmoveClock() { return halfmoveClock; }

View File

@ -30,7 +30,7 @@ class LogTest {
assertNull(log.getRoot()); assertNull(log.getRoot());
assertEquals(log.getActiveColor(), Color.WHITE); assertEquals(log.getActiveColor(), Color.WHITE);
assertNull(log.getEnPassant()); assertNull(log.getEnPassant());
assertEquals(log.getFullmoveCounter(), 1); assertEquals(log.getFullmoveNumber(), 1);
assertEquals(log.getHalfmoveClock(), 0); assertEquals(log.getHalfmoveClock(), 0);
} }
@ -132,7 +132,7 @@ class LogTest {
} }
/** /**
* Test method for {@link dev.kske.chess.board.Log#getFullmoveCounter()}. * Test method for {@link dev.kske.chess.board.Log#getFullmoveNumber()}.
*/ */
@Test @Test
void testGetFullmoveCounter() { void testGetFullmoveCounter() {
@ -140,7 +140,7 @@ class LogTest {
} }
/** /**
* Test method for {@link dev.kske.chess.board.Log#setFullmoveCounter(int)}. * Test method for {@link dev.kske.chess.board.Log#setFullmoveNumber(int)}.
*/ */
@Test @Test
void testSetFullmoveCounter() { void testSetFullmoveCounter() {