use of com.codename1.location.Location in project ChessProject by DylanSantora.
the class ChessBoard method rookMove.
public ArrayList<Location> rookMove(Location loc) {
ArrayList<Location> moveLocs = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
ArrayList<Location> moveLocs90 = rookMove90(loc);
ArrayList<Location> moveLocs180 = rookMove180(loc);
ArrayList<Location> moveLocs270 = rookMove270(loc);
ArrayList<Location> moveLocs360 = rookMove360(loc);
for (Location loc90 : moveLocs90) {
moveLocs.add(loc90);
}
for (Location loc180 : moveLocs180) {
moveLocs.add(loc180);
}
for (Location loc270 : moveLocs270) {
moveLocs.add(loc270);
}
for (Location loc360 : moveLocs360) {
moveLocs.add(loc360);
}
return moveLocs;
}
use of com.codename1.location.Location in project ChessProject by DylanSantora.
the class ChessBoard method isWhiteInCheck.
public Boolean isWhiteInCheck(Location loc) {
ArrayList<Location> possibleLocsDiag = new ArrayList<Location>();
ArrayList<Location> possibleLocsStraight = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
ArrayList<Location> moveLocs90 = rookMove90(loc);
ArrayList<Location> moveLocs180 = rookMove180(loc);
ArrayList<Location> moveLocs270 = rookMove270(loc);
ArrayList<Location> moveLocs360 = rookMove360(loc);
ArrayList<Location> moveLocs45 = bishopMove45(loc);
ArrayList<Location> moveLocs135 = bishopMove135(loc);
ArrayList<Location> moveLocs225 = bishopMove225(loc);
ArrayList<Location> moveLocs315 = bishopMove315(loc);
ArrayList<Location> moveLocsKnight = knightMove(loc);
if (!moveLocs90.isEmpty()) {
possibleLocsStraight.add(moveLocs90.get(moveLocs90.size() - 1));
}
if (!moveLocs180.isEmpty()) {
possibleLocsStraight.add(moveLocs180.get(moveLocs180.size() - 1));
}
if (!moveLocs270.isEmpty()) {
possibleLocsStraight.add(moveLocs270.get(moveLocs270.size() - 1));
}
if (!moveLocs360.isEmpty()) {
possibleLocsStraight.add(moveLocs360.get(moveLocs360.size() - 1));
}
if (!moveLocs45.isEmpty()) {
possibleLocsDiag.add(moveLocs45.get(moveLocs45.size() - 1));
}
if (!moveLocs135.isEmpty()) {
possibleLocsDiag.add(moveLocs135.get(moveLocs135.size() - 1));
}
if (!moveLocs225.isEmpty()) {
possibleLocsDiag.add(moveLocs225.get(moveLocs225.size() - 1));
}
if (!moveLocs315.isEmpty()) {
possibleLocsDiag.add(moveLocs315.get(moveLocs315.size() - 1));
}
if (!possibleLocsStraight.isEmpty())
for (Location possibleLoc : possibleLocsStraight) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (-1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "rook") {
System.out.println("rook checking");
return true;
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "queen") {
System.out.println("queen checking");
return true;
}
}
}
if (!possibleLocsDiag.isEmpty())
for (Location possibleLoc : possibleLocsDiag) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (-1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "pawn") {
if ((possibleR + 1) == loc.getRow() && (possibleC + 1) == loc.getCol()) {
System.out.println("pawn checking");
return true;
}
if ((possibleR + 1) == loc.getRow() && (possibleC - 1) == loc.getCol()) {
System.out.println("pawn checking");
return true;
}
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "bishop") {
System.out.println("bishop checking");
return true;
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "queen") {
System.out.println("queen checking");
return true;
}
}
}
if (!moveLocsKnight.isEmpty()) {
for (Location possibleLoc : moveLocsKnight) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (-1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "knight") {
return true;
}
}
}
}
return false;
}
use of com.codename1.location.Location in project ChessProject by DylanSantora.
the class ChessBoard method isBlackInCheck.
public Boolean isBlackInCheck(Location loc) {
ArrayList<Location> possibleLocsDiag = new ArrayList<Location>();
ArrayList<Location> possibleLocsStraight = new ArrayList<Location>();
ArrayList<Location> moveLocsKnight = knightMove(loc);
int r = loc.getRow();
int c = loc.getCol();
ArrayList<Location> moveLocs90 = rookMove90(loc);
ArrayList<Location> moveLocs180 = rookMove180(loc);
ArrayList<Location> moveLocs270 = rookMove270(loc);
ArrayList<Location> moveLocs360 = rookMove360(loc);
ArrayList<Location> moveLocs45 = bishopMove45(loc);
ArrayList<Location> moveLocs135 = bishopMove135(loc);
ArrayList<Location> moveLocs225 = bishopMove225(loc);
ArrayList<Location> moveLocs315 = bishopMove315(loc);
if (!moveLocs90.isEmpty()) {
possibleLocsStraight.add(moveLocs90.get(moveLocs90.size() - 1));
}
if (!moveLocs180.isEmpty()) {
possibleLocsStraight.add(moveLocs180.get(moveLocs180.size() - 1));
}
if (!moveLocs270.isEmpty()) {
possibleLocsStraight.add(moveLocs270.get(moveLocs270.size() - 1));
}
if (!moveLocs360.isEmpty()) {
possibleLocsStraight.add(moveLocs360.get(moveLocs360.size() - 1));
}
if (!moveLocs45.isEmpty()) {
possibleLocsDiag.add(moveLocs45.get(moveLocs45.size() - 1));
}
if (!moveLocs135.isEmpty()) {
possibleLocsDiag.add(moveLocs135.get(moveLocs135.size() - 1));
}
if (!moveLocs225.isEmpty()) {
possibleLocsDiag.add(moveLocs225.get(moveLocs225.size() - 1));
}
if (!moveLocs315.isEmpty()) {
possibleLocsDiag.add(moveLocs315.get(moveLocs315.size() - 1));
}
if (!possibleLocsStraight.isEmpty())
for (Location possibleLoc : possibleLocsStraight) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "rook") {
System.out.println("rook checking");
return true;
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "queen") {
System.out.println("queen checking");
return true;
}
}
}
if (!possibleLocsDiag.isEmpty())
for (Location possibleLoc : possibleLocsDiag) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "pawn") {
if ((possibleR - 1) == loc.getRow() && (possibleC + 1) == loc.getCol()) {
System.out.println("pawn checking");
return true;
}
if ((possibleR - 1) == loc.getRow() && (possibleC - 1) == loc.getCol()) {
System.out.println("pawn checking");
return true;
}
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "bishop") {
System.out.println("bishop checking");
return true;
}
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "queen") {
System.out.println("queen checking");
return true;
}
}
}
if (!moveLocsKnight.isEmpty()) {
for (Location possibleLoc : moveLocsKnight) {
int possibleR = possibleLoc.getRow();
int possibleC = possibleLoc.getCol();
if (myBoard[possibleR][possibleC].getChessPiece().getMyColor() == (1)) {
if (myBoard[possibleR][possibleC].getChessPiece().getMyPieceType() == "knight") {
return true;
}
}
}
}
return false;
}
use of com.codename1.location.Location in project ChessProject by DylanSantora.
the class ChessBoard method knightMove.
public ArrayList<Location> knightMove(Location loc) {
ArrayList<Location> moveLocs = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
int knightColor = myBoard[r][c].getChessPiece().getMyColor();
if (r < 6 && c < 7) {
if (myBoard[r + 2][c + 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 2, c + 1));
}
if (knightColor == 1) {
if (myBoard[r + 2][c + 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 2, c + 1));
}
}
if (knightColor == -1) {
if (myBoard[r + 2][c + 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 2, c + 1));
}
}
}
if (r < 6 && c > 0) {
if (myBoard[r + 2][c - 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 2, c - 1));
}
if (knightColor == 1) {
if (myBoard[r + 2][c - 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 2, c - 1));
}
}
if (knightColor == -1) {
if (myBoard[r + 2][c - 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 2, c - 1));
}
}
}
if (r > 1 & c > 0) {
if (myBoard[r - 2][c - 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 2, c - 1));
}
if (knightColor == 1) {
if (myBoard[r - 2][c - 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 2, c - 1));
}
}
if (knightColor == -1) {
if (myBoard[r - 2][c - 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 2, c - 1));
}
}
}
if (r > 1 & c < 7) {
if (myBoard[r - 2][c + 1].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 2, c + 1));
}
if (knightColor == 1) {
if (myBoard[r - 2][c + 1].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 2, c + 1));
}
}
if (knightColor == -1) {
if (myBoard[r - 2][c + 1].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 2, c + 1));
}
}
}
if (r < 7 && c < 6) {
if (myBoard[r + 1][c + 2].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 1, c + 2));
}
if (knightColor == 1) {
if (myBoard[r + 1][c + 2].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 1, c + 2));
}
}
if (knightColor == -1) {
if (myBoard[r + 1][c + 2].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 1, c + 2));
}
}
}
if (r < 7 && c > 1) {
if (myBoard[r + 1][c - 2].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r + 1, c - 2));
}
if (knightColor == 1) {
if (myBoard[r + 1][c - 2].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r + 1, c - 2));
}
}
if (knightColor == -1) {
if (myBoard[r + 1][c - 2].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r + 1, c - 2));
}
}
}
if (r > 0 && c < 6) {
if (myBoard[r - 1][c + 2].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 1, c + 2));
}
if (knightColor == 1) {
if (myBoard[r - 1][c + 2].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 1, c + 2));
}
}
if (knightColor == -1) {
if (myBoard[r - 1][c + 2].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 1, c + 2));
}
}
}
if (r > 0 && c > 1) {
if (myBoard[r - 1][c - 2].getChessPiece().getMyColor() == 0) {
moveLocs.add(new Location(r - 1, c - 2));
}
if (knightColor == 1) {
if (myBoard[r - 1][c - 2].getChessPiece().getMyColor() == -1) {
moveLocs.add(new Location(r - 1, c - 2));
}
}
if (knightColor == -1) {
if (myBoard[r - 1][c - 2].getChessPiece().getMyColor() == 1) {
moveLocs.add(new Location(r - 1, c - 2));
}
}
}
return moveLocs;
}
use of com.codename1.location.Location in project ChessProject by DylanSantora.
the class ChessBoard method queenMove.
public ArrayList<Location> queenMove(Location loc) {
ArrayList<Location> moveLocs = new ArrayList<Location>();
int r = loc.getRow();
int c = loc.getCol();
ArrayList<Location> moveLocs90 = rookMove90(loc);
ArrayList<Location> moveLocs180 = rookMove180(loc);
ArrayList<Location> moveLocs270 = rookMove270(loc);
ArrayList<Location> moveLocs360 = rookMove360(loc);
for (Location loc90 : moveLocs90) {
moveLocs.add(loc90);
}
for (Location loc180 : moveLocs180) {
moveLocs.add(loc180);
}
for (Location loc270 : moveLocs270) {
moveLocs.add(loc270);
}
for (Location loc360 : moveLocs360) {
moveLocs.add(loc360);
}
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);
}
return moveLocs;
}
Aggregations