Undo auto player

play black then white
This commit is contained in:
edwin 2025-05-22 09:37:19 +02:00
parent 49878e9bd2
commit 3e0f23aafd
1 changed files with 10 additions and 5 deletions

View File

@ -248,10 +248,12 @@ public class Board {
public void userTouch(int x, int y) { public void userTouch(int x, int y) {
boolean positionOccupied = this.positionOccupied(x, y) ; // verify if the square is occupied boolean positionOccupied = this.positionOccupied(x, y) ; // verify if the square is occupied
if ((this.x == -1 ) && (positionOccupied == true)){ // set coordinates of the piece to play if ((this.x == -1 ) && (positionOccupied == true)){ // set coordinates of the piece to play
boolean isWhitePiece = pieces.get(this.whatPiece(x, y)).isWhite();
if(isWhitePiece == this.isTurnWhite()) {
this.x = x; this.x = x;
this.y = y; this.y = y;
}
} }
else { else {
if((this.x == x) && (this.y == y)) { // reset since square is already selected if((this.x == x) && (this.y == y)) { // reset since square is already selected
@ -338,7 +340,12 @@ public class Board {
this.turnNumber +=1; this.turnNumber +=1;
} }
int j = 0;
for (int i=0; i<8;i++) {
if (this.positionOccupied(x, y)==true) {
}
}
// we now reset our parameters // we now reset our parameters
this.x=-1; this.x=-1;
this.y=-1; this.y=-1;
@ -1283,9 +1290,6 @@ public class Board {
pieceToMove = piece; pieceToMove = piece;
} }
} }
if (pieceToMove == null) {
return;
}
Piece pieceTargeted = null; Piece pieceTargeted = null;
for (int i=0; i < this.pieces.size(); i++) { for (int i=0; i < this.pieces.size(); i++) {
Piece piece = this.pieces.get(i); Piece piece = this.pieces.get(i);
@ -1301,6 +1305,7 @@ public class Board {
this.turnNumber = this.turnNumber + 1; this.turnNumber = this.turnNumber + 1;
this.x = -1; this.x = -1;
this.y = -1; this.y = -1;
previousBoard.add(this.toString());
} }
} }