diff --git a/.DS_Store b/.DS_Store index 50739aa..6c292dc 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/OOP_2B1_Project/.DS_Store b/OOP_2B1_Project/.DS_Store index dc067c9..4e01869 100644 Binary files a/OOP_2B1_Project/.DS_Store and b/OOP_2B1_Project/.DS_Store differ diff --git a/OOP_2B1_Project/src/.DS_Store b/OOP_2B1_Project/src/.DS_Store index 62724e7..93eb05e 100644 Binary files a/OOP_2B1_Project/src/.DS_Store and b/OOP_2B1_Project/src/.DS_Store differ diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index ea13b1f..c058b57 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -86,9 +86,9 @@ public class Board implements Cloneable { setPiece(true,PieceType.Bishop,2,7); setPiece(true,PieceType.Bishop,5,7); setPiece(false,PieceType.King,4,0); - setPiece(true,PieceType.King,4,7); + setPiece(true,PieceType.King,3,7); setPiece(false,PieceType.Queen,3,0); - setPiece(true,PieceType.Queen,3,7); + setPiece(true,PieceType.Queen,4,7); for (int i=0;i<8;i++) { setPiece(false,PieceType.Pawn,i,1); } @@ -103,6 +103,9 @@ public class Board implements Cloneable { pieces.clear(); selectedX = null; selectedY = null; + highlightedPositions.clear(); + boardHistory.clear(); + this.lastMoveSourceSquare = null; } @@ -151,6 +154,7 @@ public class Board implements Cloneable { Piece pieceAtPos = getPieceAt(x, y); if (pieceAtPos != null && pieceAtPos.isWhite() == turnIsWhite) { + this.lastMoveSourceSquare = null; selectedX = x; selectedY = y; @@ -163,6 +167,7 @@ public class Board implements Cloneable { } } else { if (selectedX == x && selectedY == y) { + this.lastMoveSourceSquare = null; selectedX = null; selectedY = null; highlightedPositions.clear(); @@ -312,6 +317,7 @@ public class Board implements Cloneable { turnNumber--; turnIsWhite = !turnIsWhite; kingCheckPos = null; + this.lastMoveSourceSquare = null; } public Board(Board board) { @@ -359,6 +365,8 @@ public class Board implements Cloneable { // Update turn info turnIsWhite = !turnIsWhite; turnNumber++; + + this.lastMoveSourceSquare = new int[] {move.getFromCol(), move.getFromRow()}; // Play move sound if enabled playMoveSound(); @@ -430,8 +438,11 @@ public class Board implements Cloneable { clonedBoard.selectedY = this.selectedY; clonedBoard.turnNumber = this.turnNumber; clonedBoard.turnIsWhite = this.turnIsWhite; - - + if (this.lastMoveSourceSquare != null) { + clonedBoard.lastMoveSourceSquare = new int[]{this.lastMoveSourceSquare[0], this.lastMoveSourceSquare[1]}; + } else { + clonedBoard.lastMoveSourceSquare = null; + } return clonedBoard; } catch (CloneNotSupportedException e) { throw new AssertionError(); // Should never happen @@ -539,5 +550,10 @@ public class Board implements Cloneable { && kingCheckPos[0] == squareX && kingCheckPos[1] == squareY); } + private int[] lastMoveSourceSquare = null; + + public boolean isLastMoveSourceSquare(int x, int y) { + return lastMoveSourceSquare != null && lastMoveSourceSquare[0] == x && lastMoveSourceSquare[1] == y; +} + } - diff --git a/OOP_2B1_Project/src/backend/Game.java b/OOP_2B1_Project/src/backend/Game.java index d4da752..0d8e57c 100644 --- a/OOP_2B1_Project/src/backend/Game.java +++ b/OOP_2B1_Project/src/backend/Game.java @@ -115,5 +115,7 @@ public class Game extends Thread { public boolean isKingCheckSquare(int squareX, int squareY) { return board.isKingCheckSquare(squareX, squareY); } - + public boolean isLastMoveSourceSquare(int x, int y) { + return board.isLastMoveSourceSquare(x, y); +} }