Search in sources :

Example 11 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method promotion.

public Location promotion() {
    for (int c = 0; c < 8; c++) {
        if (myBoard[0][c].getChessPiece().getMyPieceType() == ("pawn") && myBoard[0][c].getChessPiece().getMyColor() == 1) {
            myBoard[0][c].setChessPiece(new Queen(1));
            Location promLoc = new Location(0, c);
            return promLoc;
        }
        if (myBoard[7][c].getChessPiece().getMyPieceType() == ("pawn") && myBoard[7][c].getChessPiece().getMyColor() == -1) {
            myBoard[7][c].setChessPiece(new Queen(-1));
            Location promLoc = new Location(7, c);
            return promLoc;
        }
    }
    return new Location(4, 4);
}
Also used : Location(location.Location)

Example 12 with Location

use of 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 13 with Location

use of 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 14 with Location

use of 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 15 with Location

use of 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)

Aggregations

Location (location.Location)17 ArrayList (java.util.ArrayList)16 Location (com.codename1.location.Location)5 IOException (java.io.IOException)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Geofence (com.codename1.location.Geofence)1 GeofenceListener (com.codename1.location.GeofenceListener)1 LocationListener (com.codename1.location.LocationListener)1 BrowserComponent (com.codename1.ui.BrowserComponent)1 JSRef (com.codename1.ui.BrowserComponent.JSRef)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 ActionListener (com.codename1.ui.events.ActionListener)1 Point (com.codename1.ui.geom.Point)1 SuccessCallback (com.codename1.util.SuccessCallback)1 Date (java.util.Date)1