modified highlights and move to not eat pieces of the same color
This commit is contained in:
parent
1d59c578db
commit
70b945dbfa
|
|
@ -153,11 +153,15 @@ public class Board {
|
||||||
}
|
}
|
||||||
else { // we know we already have a piece so we move it to another position
|
else { // we know we already have a piece so we move it to another position
|
||||||
if( this.positionOccupied(x, y) == true) {
|
if( this.positionOccupied(x, y) == true) {
|
||||||
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
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) {//moves the piece only if the position selected is not occupied by a piece of the same color
|
||||||
|
int indexPiece = this.whatPiece(this.x, this.y);
|
||||||
|
pieces.get(indexPiece).setX(x);
|
||||||
|
pieces.get(indexPiece).setY(y);
|
||||||
}
|
}
|
||||||
int indexPiece = this.whatPiece(this.x, this.y);
|
|
||||||
pieces.get(indexPiece).setX(x);
|
|
||||||
pieces.get(indexPiece).setY(y);
|
|
||||||
// we now reset our parameters
|
// we now reset our parameters
|
||||||
this.x=-1;
|
this.x=-1;
|
||||||
this.y=-1;
|
this.y=-1;
|
||||||
|
|
@ -350,11 +354,11 @@ public class Board {
|
||||||
if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case
|
if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y))) {//eat the piece in diagonal, if existing
|
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {//highlight the piece in diagonal, if existing
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((y == this.y-2) && (this.y == 6) && (x == this.x)) {//move by two if not moved
|
if((y == this.y-2) && (this.y == 6) && (x == this.x) && (positionOccupied(this.x,this.y-1))==false) {//move by two if not moved and if no piece in front
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -364,27 +368,47 @@ public class Board {
|
||||||
if((x == this.x) && (positionOccupied(x,y)==false)) {
|
if((x == this.x) && (positionOccupied(x,y)==false)) {
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y))) {
|
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((y == this.y+2) && (this.y == 1) && (x == this.x)) {
|
if((y == this.y+2) && (this.y == 1) && (x == this.x) && (positionOccupied(this.x,this.y+1) == false)) {
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pieces.get(indexPieceSelect).getType() == PieceType.King) { //highlight for Kings
|
if (pieces.get(indexPieceSelect).getType() == PieceType.King) { //highlight for Kings THIS IS NOT OPTIMISED BC OF WHATPIECE (SAME FOR ALL FOLLOWING PIECES)
|
||||||
if((Math.abs(x-this.x) <= 1) && (Math.abs(y-this.y) <= 1)) { //consider all cases at distance one from the king
|
if(positionOccupied(x,y) == false) {
|
||||||
if ((Math.abs(x-this.x) != 0) || (Math.abs(y-this.y) != 0)) { //check if we are not considering the place where the king is
|
if((Math.abs(x-this.x) <= 1) && (Math.abs(y-this.y) <= 1)) { //consider all cases at distance one from the king
|
||||||
highlight = true;
|
if ((Math.abs(x-this.x) != 0) || (Math.abs(y-this.y) != 0)) { //check if we are not considering the place where the king is
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()){
|
||||||
|
if((Math.abs(x-this.x) <= 1) && (Math.abs(y-this.y) <= 1)) { //consider all cases at distance one from the king
|
||||||
|
if ((Math.abs(x-this.x) != 0) || (Math.abs(y-this.y) != 0)) { //check if we are not considering the place where the king is
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pieces.get(indexPieceSelect).getType() == PieceType.Knight) { //highlight for knights
|
if (pieces.get(indexPieceSelect).getType() == PieceType.Knight) { //highlight for knights
|
||||||
if (((Math.abs(x-this.x) == 1) && (Math.abs(y-this.y) == 2)) || ((Math.abs(x-this.x) == 2) && (Math.abs(y-this.y) == 1))) {//consider all positions at 2 by 1 from the knight
|
if(positionOccupied(x,y) == false) {
|
||||||
highlight = true;
|
if (((Math.abs(x-this.x) == 1) && (Math.abs(y-this.y) == 2)) || ((Math.abs(x-this.x) == 2) && (Math.abs(y-this.y) == 1))) {//consider all positions at 2 by 1 from the knight
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()){
|
||||||
|
if (((Math.abs(x-this.x) == 1) && (Math.abs(y-this.y) == 2)) || ((Math.abs(x-this.x) == 2) && (Math.abs(y-this.y) == 1))) {//consider all positions at 2 by 1 from the knight
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -392,7 +416,14 @@ public class Board {
|
||||||
int numHighlight = highlightBishop().get(0).size();
|
int numHighlight = highlightBishop().get(0).size();
|
||||||
for(int i = 0; i < numHighlight; i++) {
|
for(int i = 0; i < numHighlight; i++) {
|
||||||
if ((x == highlightBishop().get(0).get(i)) && (y == highlightBishop().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
if ((x == highlightBishop().get(0).get(i)) && (y == highlightBishop().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
||||||
highlight = true;
|
if(positionOccupied(x,y) == false) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +432,14 @@ public class Board {
|
||||||
int numHighlight = highlightQueen().get(0).size();
|
int numHighlight = highlightQueen().get(0).size();
|
||||||
for(int i = 0; i < numHighlight; i++) {
|
for(int i = 0; i < numHighlight; i++) {
|
||||||
if ((x == highlightQueen().get(0).get(i)) && (y == highlightQueen().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
if ((x == highlightQueen().get(0).get(i)) && (y == highlightQueen().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
||||||
highlight = true;
|
if(positionOccupied(x,y) == false) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +448,14 @@ public class Board {
|
||||||
int numHighlight = highlightRook().get(0).size();
|
int numHighlight = highlightRook().get(0).size();
|
||||||
for(int i = 0; i < numHighlight; i++) {
|
for(int i = 0; i < numHighlight; i++) {
|
||||||
if ((x == highlightRook().get(0).get(i)) && (y == highlightRook().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
if ((x == highlightRook().get(0).get(i)) && (y == highlightRook().get(1).get(i))) {//check if the considered x and y are in the list of positions that should be highlighted
|
||||||
highlight = true;
|
if(positionOccupied(x,y) == false) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue