Added en passant availability logging and FEN string export
This commit is contained in:
		| @@ -458,11 +458,11 @@ public class Board implements Cloneable { | ||||
| 		if (castlingSb.length() == 0) sb.append("-"); | ||||
| 		sb.append(castlingSb); | ||||
|  | ||||
| 		// TODO: en passant availability | ||||
| 		sb.append(" -"); | ||||
|  | ||||
| 		final LoggedMove lastMove = log.getLast(); | ||||
|  | ||||
| 		// En passant availabillity | ||||
| 		sb.append(" " + (lastMove == null || lastMove.enPassant == null ? "-" : lastMove.enPassant.toSAN())); | ||||
|  | ||||
| 		// Halfmove clock | ||||
| 		sb.append(" " + String.valueOf(lastMove == null ? 0 : lastMove.halfmoveClock)); | ||||
|  | ||||
|   | ||||
| @@ -22,6 +22,11 @@ public class Log implements Cloneable { | ||||
| 	} | ||||
|  | ||||
| 	public void add(Move move, Piece capturedPiece, boolean pawnMove) { | ||||
| 		// En passant availability | ||||
| 		Position enPassant = null; | ||||
| 		if (pawnMove && move.yDist == 2) enPassant = new Position(move.pos.x, move.pos.y + move.ySign); | ||||
|  | ||||
| 		// Fullmove counter and halfmove clock | ||||
| 		int fullmoveCounter, halfmoveClock; | ||||
| 		if (moves.isEmpty()) { | ||||
| 			fullmoveCounter	= 1; | ||||
| @@ -32,7 +37,7 @@ public class Log implements Cloneable { | ||||
| 			halfmoveClock = capturedPiece != null || pawnMove ? 0 : getLast().halfmoveClock + 1; | ||||
| 		} | ||||
| 		activeColor = activeColor.opposite(); | ||||
| 		moves.add(new LoggedMove(move, capturedPiece, fullmoveCounter, halfmoveClock)); | ||||
| 		moves.add(new LoggedMove(move, capturedPiece, enPassant, fullmoveCounter, halfmoveClock)); | ||||
| 	} | ||||
|  | ||||
| 	public LoggedMove getLast() { return moves.isEmpty() ? null : moves.get(moves.size() - 1); } | ||||
| @@ -63,11 +68,13 @@ public class Log implements Cloneable { | ||||
|  | ||||
| 		public final Move	move; | ||||
| 		public final Piece	capturedPiece; | ||||
| 		public final Position	enPassant; | ||||
| 		public final int	fullmoveCounter, halfmoveClock; | ||||
|  | ||||
| 		public LoggedMove(Move move, Piece capturedPiece, int fullmoveCounter, int halfmoveClock) { | ||||
| 		public LoggedMove(Move move, Piece capturedPiece, Position enPassant, int fullmoveCounter, int halfmoveClock) { | ||||
| 			this.move				= move; | ||||
| 			this.capturedPiece		= capturedPiece; | ||||
| 			this.enPassant			= enPassant; | ||||
| 			this.fullmoveCounter	= fullmoveCounter; | ||||
| 			this.halfmoveClock		= halfmoveClock; | ||||
| 		} | ||||
|   | ||||
| @@ -30,9 +30,9 @@ public class Move { | ||||
| 		this(new Position(xPos, yPos), new Position(xDest, yDest)); | ||||
| 	} | ||||
|  | ||||
| 	public static Move fromAlgebraicNotation(String move) { | ||||
| 		return new Move(Position.fromAlgebraicNotation(move.substring(0, 2)), | ||||
| 				Position.fromAlgebraicNotation(move.substring(2))); | ||||
| 	public static Move fromSAN(String move) { | ||||
| 		return new Move(Position.fromSAN(move.substring(0, 2)), | ||||
| 				Position.fromSAN(move.substring(2))); | ||||
| 	} | ||||
|  | ||||
| 	public boolean isHorizontal() { return yDist == 0; } | ||||
|   | ||||
| @@ -15,8 +15,12 @@ public class Position { | ||||
| 		this.y	= y; | ||||
| 	} | ||||
|  | ||||
| 	public static Position fromAlgebraicNotation(String pos) { | ||||
| 		return new Position(pos.charAt(0) - 97, 7 - (Character.getNumericValue(pos.charAt(1)) - 1)); | ||||
| 	public static Position fromSAN(String pos) { | ||||
| 		return new Position(pos.charAt(0) - 97, 8 - Character.getNumericValue(pos.charAt(1))); | ||||
| 	} | ||||
|  | ||||
| 	public String toSAN() { | ||||
| 		return String.valueOf((char) (x + 97)) + String.valueOf(8 - y); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
|   | ||||
| @@ -74,7 +74,7 @@ public class UCIPlayer extends Player implements UCIListener { | ||||
|  | ||||
| 	@Override | ||||
| 	public void onBestMove(String move) { | ||||
| 		Move moveObj = Move.fromAlgebraicNotation(move); | ||||
| 		Move moveObj = Move.fromSAN(move); | ||||
| 		game.onMove(this, moveObj); | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user