MCPcopy Index your code
hub / github.com/coding-parrot/chess-engine / fenRepresentation

Method fenRepresentation

src/main/java/game/Board.java:838–881  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

836 }
837
838 public String fenRepresentation() {
839 final StringBuilder stringBuilder = new StringBuilder();
840 for (int i = 7; i >= 0; i--) {
841 int count = 0;
842 for (int j = 0; j < 8; j++) {
843 if (isEmpty(i, j)) {
844 count++;
845 } else {
846 if (count > 0) {
847 stringBuilder.append(count);
848 count = 0;
849 }
850 final Piece piece = getPiece(i, j);
851 char letter = piece.pieceType.getLetter();
852 if (piece.color == Color.WHITE) {
853 letter = (char) (letter - 'a' + 'A');
854 }
855 stringBuilder.append(letter);
856 }
857 }
858 if (count > 0) {
859 stringBuilder.append(count);
860 }
861 if (i > 0) {
862 stringBuilder.append('/');
863 }
864 }
865 stringBuilder.append(' ')
866 .append(playerToMove == Color.WHITE ? 'w' : 'b')
867 .append(' ')
868 .append(castlingAllowanceFen(canCastle))
869 .append(' ');
870 if (!moveList.isEmpty()) {
871 final Move lastMove = moveList.get(moveList.size() - 1);
872 if (lastMove.piece.sameType(PieceType.PAWN) && Math.abs(lastMove.piece.position.row - lastMove.target.row) == 2) {
873 stringBuilder.append((char) (lastMove.target.col + 'a')).append((lastMove.target.row + (lastMove.piece.color == Color.BLACK ? 2 : 0)));
874 } else {
875 stringBuilder.append('-');
876 }
877 } else {
878 stringBuilder.append('-');
879 }
880 return stringBuilder.toString();
881 }
882
883 public static Board getBoard(String fen) {
884 Board board = new Board();

Callers 8

captureOnEdgeMethod · 0.95
fenRepresentationMethod · 0.95
otherBoardMethod · 0.95
countMovesAfterMoveMethod · 0.95
mateInOneMethod · 0.95
countAllMovesMethod · 0.95
minMaxMethod · 0.95
alphaBetaMethod · 0.45

Calls 7

isEmptyMethod · 0.95
getPieceMethod · 0.95
castlingAllowanceFenMethod · 0.95
getLetterMethod · 0.80
sameTypeMethod · 0.80
getMethod · 0.45
toStringMethod · 0.45

Tested by 5

captureOnEdgeMethod · 0.76
fenRepresentationMethod · 0.76
otherBoardMethod · 0.76
countMovesAfterMoveMethod · 0.76
mateInOneMethod · 0.76