Skip to content

Commit

Permalink
Fixed export bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Slavrick committed Jan 6, 2021
1 parent cdabc9d commit dbe908d
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 28 deletions.
Binary file modified bin/GUI/Controller$1.class
Binary file not shown.
Binary file modified bin/GUI/Controller$2.class
Binary file not shown.
Binary file modified bin/GUI/Controller$3.class
Binary file not shown.
Binary file modified bin/GUI/Controller.class
Binary file not shown.
Binary file modified bin/engine/CoordFour.class
Binary file not shown.
Binary file modified bin/engine/GameStateManager.class
Binary file not shown.
Binary file modified bin/engine/MoveGenerator.class
Binary file not shown.
Binary file modified bin/fileIO/FENExporter.class
Binary file not shown.
Binary file modified bin/main/Main.class
Binary file not shown.
Binary file modified bin/test/BranchTester.class
Binary file not shown.
Binary file modified bin/test/FENParserTest.class
Binary file not shown.
Binary file modified bin/test/MoveTester.class
Binary file not shown.
3 changes: 3 additions & 0 deletions res/BishopMoveTester.FEN5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
8;8;0;1;0;w
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR;KQkq;-;w1
(6,0,1,0)(5,2,1,0);(6,7,1,0)(5,5,1,0);(4,1,2,0)(4,3,2,0);(4,6,2,0)(4,4,2,0);(5,2,3,0)(5,4,2,0);(4,6,2,1)(4,5,2,1);(4,1,3,1)(4,2,3,1);(5,7,3,1)(2,4,3,1);(1,7,3,0)(2,5,3,0);(5,0,4,0)(2,3,4,0);(5,0,4,1)(3,2,4,1);(5,5,4,1)(4,3,4,1);(5,5,4,0)(3,4,4,0);
3 changes: 3 additions & 0 deletions res/ExampleGameAdditionTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
8;8;0;1;0;b
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR;KQkq;-;w1
(6,0,1,0)(5,2,1,0);(6,7,1,0)(5,5,1,0);(4,1,2,0)(4,3,2,0);(4,6,2,0)(4,4,2,0);(5,2,3,0)(5,4,2,0);(4,6,2,1)(4,5,2,1);(4,1,3,1)(4,2,3,1);(5,7,3,1)(2,4,3,1);(1,7,3,0)(2,5,3,0);(5,2,4,1)(4,4,4,1);(5,1,4,0)(5,2,4,0);
9 changes: 6 additions & 3 deletions src/GUI/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Popup;

import java.awt.MouseInfo;
Expand Down Expand Up @@ -146,10 +147,8 @@ public void handle(MouseEvent e) {
notationStringArray = FXCollections.observableArrayList();
notationList.setItems(notationStringArray);
drawStage();
// define max font size you need
statusLabel.setFont(new Font(MAX_FONT_SIZE));
setStatusLabel();
g.printMultiverse();
}

//===========================Event Functions=========================================================================
Expand Down Expand Up @@ -224,8 +223,12 @@ private void saveGameState(ActionEvent event) {
Popup p = new Popup();
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(new File("").getAbsolutePath()));
fileChooser.setTitle("Open Resource File");
fileChooser.setTitle("Save Game");
fileChooser.getExtensionFilters().addAll(new ExtensionFilter("Text File", "*.txt"));
File selectedFile = fileChooser.showSaveDialog(p.getOwnerWindow());
if(selectedFile == null) {
return;
}
FENExporter.exportString(selectedFile, FENExporter.GameStateToFEN(this.g));
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/CoordFour.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static int GCD(int num1, int num2) {

// sub
public static CoordFour sub(CoordFour c1, CoordFour c2) {
return new CoordFour(c2.x - c1.x, c2.y - c1.y, c2.T - c1.T, c2.L - c1.L);
return new CoordFour(c1.x - c2.x, c1.y - c2.y, c1.T - c2.T, c1.L - c2.L);
}

// add
Expand Down
12 changes: 2 additions & 10 deletions src/engine/GameStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

public class GameStateManager extends GameState{

//TODO make this more good so it can be exportable etc.
public Move[] preMoves;
public Board originBoards[];
public Timeline[] originsTL;
public int startminTL;

//TODO make this into a tree, that way we can have diff lines.
Expand All @@ -17,15 +16,8 @@ public class GameStateManager extends GameState{
public GameStateManager(Timeline[] origins, int width, int height, boolean evenStart, boolean color, int minTL, Move[] moves) {
super(origins, width, height, evenStart, color, minTL, moves);
this.preMoves = moves;
originBoards = new Board[origins.length];
originsTL = origins;
this.turns = new ArrayList<Turn>();
for(int i = 0; i < origins.length ; i++){
if(origins[i].colorStart) {
originBoards[i] = origins[i].wboards.get(0);
}else {
originBoards[i] = origins[i].bboards.get(0);
}
}
}

public boolean submitMoves() {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/MoveGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public boolean canCaptureSquare(GameState g, boolean color, CoordFour origin, Co
if(pieceType <= 0 || pieceType > Board.numTypes) {
return false;
}
CoordFour vectorTo = CoordFour.sub(origin, target);
CoordFour vectorTo = CoordFour.sub(target, origin);
//FIXME finish this function.
return false;
}
Expand Down
17 changes: 12 additions & 5 deletions src/fileIO/FENExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import engine.GameState;
import engine.GameStateManager;
import engine.Move;
import engine.Timeline;
import engine.Turn;

public class FENExporter {
Expand All @@ -17,7 +18,7 @@ public static void exportString(File saveFile, String export) {
FileWriter myWriter = new FileWriter(saveFile);
myWriter.write(export);
myWriter.close();
System.out.println("Successfully wrote to the file.");
//System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred while saving file.");
e.printStackTrace();
Expand All @@ -26,19 +27,25 @@ public static void exportString(File saveFile, String export) {

public static String GameStateToFEN(GameStateManager game) {
String header = "";
header += game.width + ";" + game.height + ";" + game.tlHandicap + ";" + game.originBoards.length + ";" + game.startminTL + ";";
header += game.width + ";" + game.height + ";" + game.tlHandicap + ";" + game.originsTL.length + ";" + game.startminTL + ";";
if(game.color) {
header += 'w';
}else {
header += 'b';
}
String origins = "";
for( Board b : game.originBoards ) {
origins += BoardToString(b, false, 0);//TODO figure out how to get start time into this better.
for( Timeline t : game.originsTL) {
if(t.colorStart) {
origins += BoardToString(t.wboards.get(0), t.colorStart, t.Tstart);
}else {
origins += BoardToString(t.bboards.get(0), t.colorStart, t.Tstart);
}
origins += '\n';
}
String moves = "";
//if(game.turns != null)
for(Move m: game.preMoves) {
moves += m.rawMoveNotation() + ";";
}
for(Turn t: game.turns) {
for(Move m : t.getMoves()) {
moves += m.rawMoveNotation() + ";";
Expand Down
4 changes: 2 additions & 2 deletions src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class Main extends Application {

public static void main(String[] args) {
runTests();
//runTests();
launch();
}

Expand All @@ -25,7 +25,7 @@ public static void runTests() {
FENParserTest.testFENFileParser();
FENParserTest.testMoveParser();
CoordTester.testAllCoordFourFuncs();
//MoveTester.TestBishopMoves();
MoveTester.TestBishopMoves();
//FENExporterTester.testExporter();
System.out.println("Done.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/BranchTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

public class BranchTester {
public static void testMultiverse() {
//TODO reWrite This
GameState g = getTestGS();

}

public static GameState getTestGS() {
//TODO reWrite This
return null;
return FENParser.FENtoGSNew("res/exampleGame.txt");
}
}
2 changes: 2 additions & 0 deletions src/test/CoordTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static void ArithmaticTest() {
CoordFour sub1 = new CoordFour(4,4,1,0);
sub1.sub(new CoordFour(5,5,1,0));
testCoord(sub1, -1, -1, 0, 0);
testCoord(CoordFour.sub(new CoordFour(4,4,1,0), new CoordFour(2,6,2,-1)), 2, -2, -1, 1);

assert sub1.getNagonal() == 2;
System.out.println(" passed.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/FENParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class FENParserTest {

public static void testMoveParser() {
System.out.println(" Testing Move Parser: ");
System.out.print(" Testing Move Parser: ");
CoordFour x = FENParser.stringtoCoord("(0,0,0,0)");
assert new CoordFour(0,0,0,0).equals(x) : x;
x = FENParser.stringtoCoord("(10,5,10,5)");
assert new CoordFour(10,5,10,5).equals(x) : x;
x = FENParser.stringtoCoord("(-10,-5,-2,-1)");
assert new CoordFour(-10,-5,-2,-1).equals(x) : x;
System.out.println(" Done.");
System.out.println("passed.");
}

public static void testFENFileParser() {
Expand Down
10 changes: 9 additions & 1 deletion src/test/MoveTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import java.util.ArrayList;

import engine.Board;
import engine.CoordFive;
import engine.CoordFour;
import engine.GameState;
import engine.MoveGenerator;
import engine.MoveNotation;
import fileIO.FENParser;

public class MoveTester {
public static void TestBishopMoves() {
//TODO rewrite this.
System.out.print(" Testing Bishop Movement: ");
GameState tester = FENParser.FENtoGSNew("res/BishopMoveTester.FEN5.txt");
assert tester != null;
assert MoveGenerator.getCaptures(Board.piece.WBISHOP.ordinal(), tester, new CoordFive(2,3,5,0,true)).size() == 3;
assert MoveGenerator.getCaptures(Board.piece.WBISHOP.ordinal(), tester, new CoordFive(3,2,5,1,true)).size() == 1;
System.out.println("passed.");
}
}

0 comments on commit dbe908d

Please sign in to comment.