diff --git a/playshogi-library-shogi-files/src/main/java/com/playshogi/library/shogi/files/BatchDiagramGenerator.java b/playshogi-library-shogi-files/src/main/java/com/playshogi/library/shogi/files/BatchDiagramGenerator.java index 234407f3..e5689682 100644 --- a/playshogi-library-shogi-files/src/main/java/com/playshogi/library/shogi/files/BatchDiagramGenerator.java +++ b/playshogi-library-shogi-files/src/main/java/com/playshogi/library/shogi/files/BatchDiagramGenerator.java @@ -9,27 +9,29 @@ import java.nio.file.Files; import java.util.stream.Stream; +// generates many diagrams at once from one file into SVGs public class BatchDiagramGenerator { public static void main(String[] args) throws IOException { + // takes file with many sfens, one in each line File file = new File("C:\\Users\\Oneye\\Documents\\SFEN for book\\sfen.txt"); try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { - int counter = 0; + int exportedFileEnumeration = 0; // saves in files with increasing numbers in its name for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) { System.out.println(line); try { - ShogiPosition shogiPosition = SfenConverter.fromSFEN(line); - String svg = SVGConverter.toSVG(shogiPosition); + ShogiPosition shogiPosition = SfenConverter.fromSFEN(line); // get position + String svg = SVGConverter.toSVG(shogiPosition); // convert into SVG then save it System.out.println(svg); - counter++; - writeToFile(svg, counter); + exportedFileEnumeration++; + writeToFile(svg, exportedFileEnumeration); }catch (Exception ignored){} } } } - private static void writeToFile(final String svg, final int counter) throws IOException { - File file = new File("C:\\Users\\Oneye\\Documents\\SFEN for book\\diagrams\\Diagram"+counter+".svg"); + private static void writeToFile(final String svg, final int fileSuffix) throws IOException { + File file = new File("C:\\Users\\Oneye\\Documents\\SFEN for book\\diagrams\\Diagram"+fileSuffix+".svg"); FileWriter wr = new FileWriter(file); wr.write(svg); diff --git a/playshogi-library-shogi/src/main/java/com/playshogi/library/shogi/models/formats/svg/SVGConverter.java b/playshogi-library-shogi/src/main/java/com/playshogi/library/shogi/models/formats/svg/SVGConverter.java index 986c6bc6..4e875d27 100644 --- a/playshogi-library-shogi/src/main/java/com/playshogi/library/shogi/models/formats/svg/SVGConverter.java +++ b/playshogi-library-shogi/src/main/java/com/playshogi/library/shogi/models/formats/svg/SVGConverter.java @@ -40,6 +40,7 @@ public static String toSVG(final ReadOnlyShogiPosition position) { appendBoard(svg); appendPieces(position, svg); + // todo "all the remaining pieces in hand" for tsumeshogi appendBlackPiecesInHand(position, svg); appendWhitePiecesInHand(position, svg); @@ -161,7 +162,7 @@ private static void appendBlackPiecesInHand(final ReadOnlyShogiPosition position if(hand.length() == 1) { //hand.append("なし"); - hand.append("Nothing"); + hand.append("-"); // nothing in hand } int x = MARGIN_LEFT + 9 * SQUARE_WIDTH + 10; @@ -177,7 +178,7 @@ private static void appendBlackPiecesInHand(final ReadOnlyShogiPosition position .append(""); } - svg.append("\n"); // black hand + svg.append("\n"); // end of the black-hand } @@ -195,7 +196,8 @@ private static void appendWhitePiecesInHand(final ReadOnlyShogiPosition position } if(hand.length() == 1) { - hand.append("なし"); + //hand.append("なし"); + hand.append("-"); // nothing in hand } int x = - (MARGIN_LEFT - 10); @@ -211,7 +213,7 @@ private static void appendWhitePiecesInHand(final ReadOnlyShogiPosition position .append(""); } - svg.append("\n"); // black hand + svg.append("\n"); // end of the white-hand }