use of location.Location in project ChessProject by DylanSantora.
the class ChessBoard method bishopMove225.
public ArrayList<Location> bishopMove225(Location loc) {
ArrayList<Location> moveLocs225 = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
int tempR = r + 1;
int tempC = c - 1;
int bishopColor = myBoard[r][c].getChessPiece().getMyColor();
Boolean blocked225 = false;
while (blocked225 == false) {
if ((tempR < 8) && (tempR > -1)) {
if ((tempC < 8) && (tempC > -1)) {
if ((myBoard[tempR][tempC].getChessPiece().getMyColor() == bishopColor) && (!blocked225)) {
blocked225 = true;
break;
} else if ((myBoard[tempR][tempC].getChessPiece().getMyColor() == (0)) && (!blocked225)) {
System.out.println("color is 0 (225)");
moveLocs225.add(new Location(tempR, tempC));
} else if ((myBoard[tempR][tempC].getChessPiece().getMyColor() - bishopColor) == -2 || (myBoard[tempR][tempC].getChessPiece().getMyColor() - bishopColor) == 2 && (!blocked225)) {
System.out.println("-2 || +2");
blocked225 = true;
moveLocs225.add(new Location(tempR, tempC));
}
}
}
if (!blocked225) {
tempR++;
tempC--;
}
if (blocked225) {
break;
}
if (!((tempR < 8) && (tempR > -1)) || !(tempC < 8) && (tempC > -1)) {
blocked225 = true;
}
}
return moveLocs225;
}
use of location.Location in project ChessProject by DylanSantora.
the class ChessBoard method rookMove180.
public ArrayList<Location> rookMove180(Location loc) {
ArrayList<Location> moveLocs180 = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
int tempR = r + 1;
int rookColor = myBoard[r][c].getChessPiece().getMyColor();
Boolean blocked180 = false;
while (blocked180 == false) {
if ((tempR < 8) && (tempR > -1)) {
if ((myBoard[tempR][c].getChessPiece().getMyColor() == rookColor) && (!blocked180)) {
blocked180 = true;
break;
} else if ((myBoard[tempR][c].getChessPiece().getMyColor() == (0)) && (!blocked180)) {
moveLocs180.add(new Location(tempR, c));
} else if ((myBoard[tempR][c].getChessPiece().getMyColor() - rookColor) == -2 || (myBoard[tempR][c].getChessPiece().getMyColor() - rookColor) == 2 && (!blocked180)) {
System.out.println("-2 || +2");
blocked180 = true;
moveLocs180.add(new Location(tempR, c));
}
}
if (!blocked180) {
tempR++;
}
if (blocked180) {
break;
}
if (!((tempR < 8) && (tempR > -1))) {
blocked180 = true;
}
}
return moveLocs180;
}
use of location.Location in project ChessProject by DylanSantora.
the class ChessBoard method bishopMove.
public ArrayList<Location> bishopMove(Location loc) {
System.out.println("in bishopMove()");
ArrayList<Location> moveLocs = new ArrayList<Location>();
Location locTracker = loc;
ChessPiece bishop = loc.getChessPiece();
int r = loc.getRow();
int c = loc.getCol();
ArrayList<Location> moveLocs45 = bishopMove45(loc);
ArrayList<Location> moveLocs135 = bishopMove135(loc);
ArrayList<Location> moveLocs225 = bishopMove225(loc);
ArrayList<Location> moveLocs315 = bishopMove315(loc);
for (Location loc45 : moveLocs45) {
moveLocs.add(loc45);
}
for (Location loc135 : moveLocs135) {
moveLocs.add(loc135);
}
for (Location loc225 : moveLocs225) {
moveLocs.add(loc225);
}
for (Location loc315 : moveLocs315) {
moveLocs.add(loc315);
}
System.out.println("out of bishopMove()");
return moveLocs;
}
use of location.Location in project ChessProject by DylanSantora.
the class ChessBoard method rookMove360.
public ArrayList<Location> rookMove360(Location loc) {
ArrayList<Location> moveLocs360 = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
int tempR = r - 1;
int rookColor = myBoard[r][c].getChessPiece().getMyColor();
Boolean blocked360 = false;
while (blocked360 == false) {
if ((tempR < 8) && (tempR > -1)) {
if ((myBoard[tempR][c].getChessPiece().getMyColor() == rookColor) && (!blocked360)) {
blocked360 = true;
break;
} else if ((myBoard[tempR][c].getChessPiece().getMyColor() == (0)) && (!blocked360)) {
moveLocs360.add(new Location(tempR, c));
} else if ((myBoard[tempR][c].getChessPiece().getMyColor() - rookColor) == -2 || (myBoard[tempR][c].getChessPiece().getMyColor() - rookColor) == 2 && (!blocked360)) {
System.out.println("-2 || +2");
blocked360 = true;
moveLocs360.add(new Location(tempR, c));
}
}
if (!blocked360) {
tempR--;
}
if (blocked360) {
break;
}
if (!((tempR < 8) && (tempR > -1))) {
blocked360 = true;
}
}
return moveLocs360;
}
use of location.Location in project ChessProject by DylanSantora.
the class ChessBoard method kingMove.
public ArrayList<Location> kingMove(Location loc) {
System.out.println("in kingMove()");
ArrayList<Location> moveLocs = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
int kingColor = myBoard[r][c].getChessPiece().getMyColor();
if (kingColor == 1) {
if (canCastleWhiteRight()) {
moveLocs.add(new Location(7, 6));
whiteKingHasMoved = true;
}
if (canCastleWhiteLeft()) {
moveLocs.add(new Location(7, 2));
whiteKingHasMoved = true;
}
} else if (kingColor == -1) {
if (canCastleBlackRight()) {
moveLocs.add(new Location(0, 6));
blackKingHasMoved = true;
}
if (canCastleBlackLeft()) {
moveLocs.add(new Location(0, 2));
blackKingHasMoved = true;
}
}
if (r > 0) {
if (myBoard[r - 1][c].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 1, c));
}
if (kingColor == 1) {
if (myBoard[r - 1][c].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 1, c));
}
}
if (kingColor == -1) {
if (myBoard[r - 1][c].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 1, c));
}
}
}
if (r < 7) {
if (myBoard[r + 1][c].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 1, c));
}
if (kingColor == 1) {
if (myBoard[r + 1][c].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 1, c));
}
}
if (kingColor == -1) {
if (myBoard[r + 1][c].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 1, c));
}
}
}
if (c < 7) {
if (myBoard[r][c + 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r, c + 1));
}
if (kingColor == 1) {
if (myBoard[r][c + 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r, c + 1));
}
}
if (kingColor == -1) {
if (myBoard[r][c + 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r, c + 1));
}
}
}
if (c > 0) {
if (myBoard[r][c - 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r, c - 1));
}
if (kingColor == 1) {
if (myBoard[r][c - 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r, c - 1));
}
}
if (kingColor == -1) {
if (myBoard[r][c - 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r, c - 1));
}
}
}
if (c > 0 && r > 0) {
if (myBoard[r - 1][c - 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 1, c - 1));
}
if (kingColor == 1) {
if (myBoard[r - 1][c - 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 1, c - 1));
}
}
if (kingColor == -1) {
if (myBoard[r - 1][c - 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 1, c - 1));
}
}
}
if (c > 0 && r < 7) {
if (myBoard[r + 1][c - 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 1, c - 1));
}
if (kingColor == 1) {
if (myBoard[r + 1][c - 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 1, c - 1));
}
}
if (kingColor == -1) {
if (myBoard[r + 1][c - 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 1, c - 1));
}
}
}
if (c < 7 && r < 7) {
if (myBoard[r + 1][c + 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 1, c + 1));
}
if (kingColor == 1) {
if (myBoard[r + 1][c + 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 1, c + 1));
}
}
if (kingColor == -1) {
if (myBoard[r + 1][c + 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 1, c + 1));
}
}
}
if (c < 7 && r > 0) {
if (myBoard[r - 1][c + 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 1, c + 1));
}
if (kingColor == 1) {
if (myBoard[r - 1][c + 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 1, c + 1));
}
}
if (kingColor == -1) {
if (myBoard[r - 1][c + 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 1, c + 1));
}
}
}
System.out.println("out of kingMove()");
return moveLocs;
}
Aggregations