Added debugging system to print the board state in the console
This commit is contained in:
parent
7fc922bde5
commit
14f4379ebf
|
|
@ -9,6 +9,7 @@ public class Main {
|
|||
// testing
|
||||
Board testBoard = new Board(8, 8);
|
||||
testBoard.populateBoard();
|
||||
System.out.println("Initial board:");
|
||||
System.out.println(testBoard.toString());
|
||||
System.out.println(testBoard.getWidth() + "*" + testBoard.getHeight());
|
||||
|
||||
|
|
@ -16,32 +17,5 @@ public class Main {
|
|||
MyInterface mjf = new MyInterface();
|
||||
mjf.setVisible(true);
|
||||
|
||||
//test critical game functions (quick verification)
|
||||
System.out.println("\nTesting core functionality:");
|
||||
|
||||
//test piece movement
|
||||
System.out.println("White pawn at (4,6) moves:");
|
||||
Piece pawn = testBoard.getBoardMatrix()[6][4];
|
||||
System.out.println(testBoard.getValidMoves(pawn, true));
|
||||
|
||||
//test turn management
|
||||
System.out.println("\nCurrent turn: " + (testBoard.isTurnWhite() ? "White" : "Black"));
|
||||
|
||||
//test save/load functionality
|
||||
String[] savedGame = testBoard.toFileRep();
|
||||
System.out.println("\nSaved game turn: " + savedGame[8]);
|
||||
|
||||
//test move execution
|
||||
System.out.println("\nMaking a sample move (e2-e4):");
|
||||
testBoard.userTouch(4, 6); //select pawn
|
||||
testBoard.userTouch(4, 4); //move pawn
|
||||
System.out.println("Board after move:");
|
||||
System.out.println(testBoard.toString());
|
||||
|
||||
//test undo functionality
|
||||
System.out.println("\nUndoing last move:");
|
||||
testBoard.undoLastMove();
|
||||
System.out.println("Board after undo:");
|
||||
System.out.println(testBoard.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -61,6 +61,12 @@ public class Board {
|
|||
//places a piece on the board at the specified location
|
||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||
board[y][x] = new Piece(x, y, type, isWhite);
|
||||
|
||||
if (debugMode) { //for debugging moves shown in console
|
||||
System.out.println("A piece was added:");
|
||||
System.out.println(this.toString());
|
||||
System.out.println("Next turn: " + (isTurnWhite() ? "White" : "Black"));
|
||||
}
|
||||
}
|
||||
|
||||
public void populateBoard() {
|
||||
|
|
@ -129,6 +135,8 @@ public class Board {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean debugMode = true; //showing debugging info
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
if (selectedPiece == null) {
|
||||
|
|
@ -156,6 +164,12 @@ public class Board {
|
|||
selectedPiece = null;
|
||||
highlightedPositions.clear();
|
||||
}
|
||||
|
||||
if (debugMode) { //for debugging moves shown in console
|
||||
System.out.println("Move executed:");
|
||||
System.out.println(this.toString());
|
||||
System.out.println("Next turn: " + (isTurnWhite() ? "White" : "Black"));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) { //if the specified position is the currently selected piece's position
|
||||
|
|
@ -412,6 +426,12 @@ public class Board {
|
|||
board[cy][cx] = new Piece(cx, cy, last.capturedPiece.getType(), last.capturedPiece.isWhite());
|
||||
}
|
||||
}
|
||||
|
||||
if (debugMode) { //for debugging moves shown in console
|
||||
System.out.println("Undo the last move executed:");
|
||||
System.out.println(this.toString());
|
||||
System.out.println("Next turn: " + (isTurnWhite() ? "White" : "Black"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue