File upload

réparation

Merge branch 'master' of
https://gitarero.ecam.fr/aurele.wittke/OOP_1A5_Project
This commit is contained in:
edwin 2025-05-16 09:52:21 +02:00
commit f6ebb63aaa
5 changed files with 181 additions and 5 deletions

10
composition echec/test1 Normal file
View File

@ -0,0 +1,10 @@
BR,BN,BB,BQ,BK,BB,BN,BR,
BP,BP,BP, ,BP,BP,BP,BP,
, , , , , , , ,
, , ,BP,WP, , , ,
, , , , , , , ,
, , , , , , , ,
WP,WP,WP,WP, ,WP,WP,WP,
WR,WN,WB,WQ,WK,WB,WN,WR,
3
1331

10
composition echec/test2 Normal file
View File

@ -0,0 +1,10 @@
BR,BN,BB,BQ,BK,BB,BN,BR,
BP,BP,BP, ,BP, ,BP,BP,
, , , , ,WP, , ,
, , ,BP, , , , ,
, , , , , , , ,
, , , , , , , ,
WP,WP,WP,WP, ,WP,WP,WP,
WR,WN,WB,WQ,WK,WB,WN,WR,
6
0440

9
composition echec/test3 Normal file
View File

@ -0,0 +1,9 @@
BR,BN,BB,BQ,BK,BB,BN,BR,
BP,BP, ,BP, ,BP, ,BP,
, ,BP, ,BP, ,BP, ,
, , , , , , , ,
, , , ,WP, , , ,
, , , , ,WP,WP, ,
WP,WP,WP,WP, , , ,WP,
WR,WN,WB,WQ,WK,WB,WN,WR,
6

View File

@ -13,10 +13,17 @@ public class Board {
private int turnNumber; private int turnNumber;
private boolean lastTurnPawnTwo;//for en passant private boolean lastTurnPawnTwo;//for en passant
private int xTwo; private int xTwo;
private int yTwo; private int yTwo;
private boolean enPassant; private boolean enPassant;
private ArrayList<String> previousBoard; private boolean kingWMoved = false;
private boolean kingBMoved = false;
private boolean rookLWMoved = false;
private boolean rookRWMoved = false;
private boolean rookLBMoved = false;
private boolean rookRBMoved = false;
private boolean castling = false;
private boolean castlingDone = false;
private ArrayList<String> previousBoard;
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
this.colNum = colNum; this.colNum = colNum;
@ -100,6 +107,15 @@ public class Board {
public void cleanBoard() { public void cleanBoard() {
turnNumber = 0; turnNumber = 0;
pieces.clear(); pieces.clear();
enPassant = false;
kingWMoved = false;
kingBMoved = false;
rookLWMoved = false;
rookRWMoved = false;
rookLBMoved = false;
rookRBMoved = false;
castling = false;
castlingDone = false;
} }
public String toString() { public String toString() {
@ -185,12 +201,65 @@ public class Board {
if (pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) {//check if we do not move to a position occupied by a piece of the same color if (pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) {//check if we do not move to a position occupied by a piece of the same color
this.pieces.remove(whatPiece(x,y)); //if there is a piece at the position we want to move we remove it from the array list this.pieces.remove(whatPiece(x,y)); //if there is a piece at the position we want to move we remove it from the array list
} }
else {//castling
if (castling == true) {
if (pieces.get(whatPiece(x,y)).getX()==7 || pieces.get(whatPiece(this.x,this.y)).getX()==7) {//that means we are dealing with the right rooks for castling
if (pieces.get(whatPiece(this.x,this.y)).isWhite()==true){
kingWMoved = true;
System.out.print("W");
}
else {
kingBMoved = true;
System.out.print("B");
}
pieces.get(whatPiece(7,y)).setX(5);
pieces.get(whatPiece(4,y)).setX(6);
this.x=-1;
this.y=-1;
this.turnNumber +=1;
castlingDone=true;
}
else {//that means we are dealing with the right rooks for castling
if (pieces.get(whatPiece(x,y)).isWhite()==true){
kingWMoved = true;
}
else {
kingBMoved = true;
}
pieces.get(whatPiece(0,y)).setX(3);
pieces.get(whatPiece(4,y)).setX(2);
this.x=-1;
this.y=-1;
this.turnNumber +=1;
castlingDone=true;
}
}
}
} }
if(((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite())) && (highlights)) {//moves the piece only if the position selected is not occupied by a piece of the same color if(((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite())) && (highlights) && castlingDone==false) {//moves the piece only if the position selected is not occupied by a piece of the same color
if (enPassant) { if (enPassant) {
this.pieces.remove(whatPiece(xTwo,yTwo)); this.pieces.remove(whatPiece(xTwo,yTwo));
enPassant = false; enPassant = false;
} }
if (pieces.get(whatPiece(this.x, this.y)).getX() == 0 && pieces.get(whatPiece(this.x, this.y)).getY() == 7) {
rookLWMoved = true;
}
if (pieces.get(whatPiece(this.x, this.y)).getX() == 7 && pieces.get(whatPiece(this.x, this.y)).getY() == 7) {
rookRWMoved = true;
}
if (pieces.get(whatPiece(this.x, this.y)).getX() == 0 && pieces.get(whatPiece(this.x, this.y)).getY() == 0) {
rookLBMoved = true;
}
if (pieces.get(whatPiece(this.x, this.y)).getX() == 7 && pieces.get(whatPiece(this.x, this.y)).getY() == 0) {
rookRBMoved = true;
}
if (pieces.get(whatPiece(this.x, this.y)).getX() == 4 && pieces.get(whatPiece(this.x, this.y)).getY() == 7) {
kingWMoved = true;
}
if (pieces.get(whatPiece(this.x, this.y)).getX() == 4 && pieces.get(whatPiece(this.x, this.y)).getY() == 0) {
kingBMoved = true;
}
int indexPiece = this.whatPiece(this.x, this.y); int indexPiece = this.whatPiece(this.x, this.y);
@ -212,9 +281,11 @@ public class Board {
// we now reset our parameters // we now reset our parameters
this.x=-1; this.x=-1;
this.y=-1; this.y=-1;
castlingDone=false;
// we add 1 to the number of turned played // we add 1 to the number of turned played
} }
} }
} }
public boolean isSelected(int x, int y) { public boolean isSelected(int x, int y) {
@ -527,6 +598,55 @@ public class Board {
} }
} }
} }
//check if the castling is possible, if yes highlight the rook(s)
int nbOccupied = 0;
boolean occupiedLeftLine = true;
boolean occupiedRightLine = true;
for(int i = 3; i > 0; i--) {
if (positionOccupied(i,pieces.get(indexPieceSelect).getY()) == true) {
nbOccupied = nbOccupied + 1;
}
if (nbOccupied == 0) {
occupiedLeftLine=false;
}
}
if (occupiedLeftLine == false) {//check if the castling is possible with the rooks on the left
if (kingWMoved == false && rookLWMoved == false && x==0 && y==7 && pieces.get(whatPiece(0,7)).isWhite() == pieces.get(indexPieceSelect).isWhite()) {
highlight = true;
castling = true;
}
if (kingBMoved == false && rookLBMoved == false && x==0 && y==0 && pieces.get(whatPiece(0,0)).isWhite() == pieces.get(indexPieceSelect).isWhite()) {
highlight = true;
castling = true;
// }
//else {
//castling = false;
}
}
nbOccupied = 0;
for(int i = 5; i < 7; i++) {
if (positionOccupied(i,pieces.get(indexPieceSelect).getY()) == true) {
nbOccupied = nbOccupied + 1;
}
if (nbOccupied == 0) {
occupiedRightLine=false;
}
}
if (occupiedRightLine == false) {//check if the castling is possible with the rooks on the right
if (kingWMoved == false && rookRWMoved == false && x==7 && y==7 && pieces.get(whatPiece(7,7)).isWhite() == pieces.get(indexPieceSelect).isWhite()) {
highlight = true;
castling = true;
}
if (kingBMoved == false && rookRBMoved == false && x==7 && y==0 && pieces.get(whatPiece(7,0)).isWhite() == pieces.get(indexPieceSelect).isWhite()) {
highlight = true;
castling = true;
}
// else {
// castling = false;
//}
}
nbOccupied = 0;
} }
} }
@ -588,6 +708,33 @@ public class Board {
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) { if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
highlight = true; highlight = true;
} }
//check if the castling is possible, if yes highlight the king
if (pieces.get(indexPieceSelect).isWhite() == true) {//check if castling is possible for the white
if (kingWMoved == false && rookLWMoved == false && x==4 && y==7 && pieces.get(indexPieceSelect).getX()==0 && pieces.get(indexPieceSelect).getY()==7) {
highlight = true;
castling = true;
}
if (kingWMoved == false && rookRWMoved == false && x==4 && y==7 && pieces.get(indexPieceSelect).getX()==7 && pieces.get(indexPieceSelect).getY()==7) {
highlight = true;
castling = true;
}
else {
castling = false;
}
}
if (pieces.get(indexPieceSelect).isWhite() == false) {//check if castling is possible for the black
if (kingBMoved == false && rookLBMoved == false && x==4 && y==0 && pieces.get(indexPieceSelect).getX()==0 && pieces.get(indexPieceSelect).getY()==0) {
highlight = true;
castling = true;
}
if (kingBMoved == false && rookRBMoved == false && x==4 && y==0 && pieces.get(indexPieceSelect).getX()==7 && pieces.get(indexPieceSelect).getY()==0) {
highlight = true;
castling = true;
}
else {
castling = false;
}
}
} }
} }
} }

View File

@ -98,7 +98,7 @@ public class Game extends Thread {
public boolean isHighlighted(int x, int y) { public boolean isHighlighted(int x, int y) {
return board.isHighlighted(x, y); return board.isHighlighted(x, y);
} }
public void undoLastMove() { public void undoLastMove() {
board.undoLastMove(); board.undoLastMove();
} }