Search in sources :

Example 16 with Location

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;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 17 with Location

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;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 18 with Location

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;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 19 with Location

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;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 20 with Location

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;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Aggregations

ArrayList (java.util.ArrayList)18 Location (location.Location)17 Location (com.codename1.location.Location)5 IOException (java.io.IOException)5 Point (com.codename1.ui.geom.Point)4 Component (com.codename1.ui.Component)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ConnectionRequest (com.codename1.io.ConnectionRequest)2 BrowserComponent (com.codename1.ui.BrowserComponent)2 ActionListener (com.codename1.ui.events.ActionListener)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Paint (com.codename1.charts.compat.Paint)1 Point (com.codename1.charts.models.Point)1 XYSeries (com.codename1.charts.models.XYSeries)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 BindTarget (com.codename1.cloud.BindTarget)1 CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)1 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 FileSystemStorage (com.codename1.io.FileSystemStorage)1