Skip to content

Commit

Permalink
fixed pieces in hand to show - instead of nothing
Browse files Browse the repository at this point in the history
added comments and renamed counter variable
  • Loading branch information
sleepingchinchilla committed Feb 25, 2024
1 parent a5b19ba commit 674bb94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -177,7 +178,7 @@ private static void appendBlackPiecesInHand(final ReadOnlyShogiPosition position
.append("</tspan></text>");
}

svg.append("</g>\n"); // black hand
svg.append("</g>\n"); // end of the black-hand
}


Expand All @@ -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);
Expand All @@ -211,7 +213,7 @@ private static void appendWhitePiecesInHand(final ReadOnlyShogiPosition position
.append("</tspan></text>");
}

svg.append("</g>\n"); // black hand
svg.append("</g>\n"); // end of the white-hand
}


Expand Down

0 comments on commit 674bb94

Please sign in to comment.