Beispiel #1
0
  public boolean queensideClear() {
    boolean[] flags = ChessGameDemo.getFlags();
    int row = square.getRow();
    int column = square.getColumn();
    if ((row == 1) && (flags[0] || flags[4])) {
      return false;
    }
    if ((row == 8) && (flags[2] || flags[5])) {
      return false;
    }
    if (((row == 1) && (column == 5)) || ((row == 8) && (column == 5))) {
      for (int i = 1; i < 4; i++) {
        int r = row;
        int c = column - i;
        int cell = square.getCellFromCoord(r, c);
        Square sq = (Square) board.getComponent(cell);
        if ((sq.getComponentCount() == 1) || (r < 1)) {
          return false;
        } else if (color == 1) {
          if ((board.getBlackCheckList()).contains(sq.getPosition())) {
            return false;
          }
        } else {
          if ((board.getWhiteCheckList()).contains(sq.getPosition())) {
            return false;
          }
        }
      }
      return true;
    }

    return false;
  }
Beispiel #2
0
 private void setListForPawn() {
   moveList.clear();
   if (color == 1) {
     int row = square.getRow();
     int column = square.getColumn();
     int cell1 = square.getCellFromCoord(row + 1, column);
     int cell2 = square.getCellFromCoord(row + 2, column);
     int cell3 = square.getCellFromCoord(row + 1, column + 1);
     int cell4 = square.getCellFromCoord(row + 1, column - 1);
     Square s1 = (Square) board.getComponent(cell1);
     Square s2 = (Square) board.getComponent(cell2);
     Square s3 = (Square) board.getComponent(cell3);
     Square s4 = (Square) board.getComponent(cell4);
     if (s1.getComponentCount() == 0) {
       moveList.add(s1.getPosition());
       squareList.add(s1);
     }
     if (s2.getComponentCount() == 0) {
       moveList.add(s2.getPosition());
       squareList.add(s2);
     }
     if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 0) {
       moveList.add(s3.getPosition());
       squareList.add(s3);
     }
     if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 0) {
       moveList.add(s4.getPosition());
       squareList.add(s4);
     }
   }
   if (color == 0) {
     int row = square.getRow();
     int column = square.getColumn();
     int cell1 = square.getCellFromCoord(row - 1, column);
     int cell2 = square.getCellFromCoord(row - 2, column);
     int cell3 = square.getCellFromCoord(row - 1, column + 1);
     int cell4 = square.getCellFromCoord(row - 1, column - 1);
     Square s1 = (Square) board.getComponent(cell1);
     Square s2 = (Square) board.getComponent(cell2);
     Square s3 = (Square) board.getComponent(cell3);
     Square s4 = (Square) board.getComponent(cell4);
     if (s1.getComponentCount() == 0) {
       moveList.add(s1.getPosition());
       squareList.add(s1);
     }
     if (s2.getComponentCount() == 0) {
       moveList.add(s2.getPosition());
       squareList.add(s2);
     }
     if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 1) {
       moveList.add(s3.getPosition());
       squareList.add(s3);
     }
     if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 1) {
       moveList.add(s4.getPosition());
       squareList.add(s4);
     }
   }
 }
Beispiel #3
0
  public boolean moveValid(Square candidateSquare) {
    if (piece == 0) {
      setListForKing();
    }
    if (piece == 1) {
      setListForQueen();
    }
    if (piece == 2) {
      moveList.clear();
      setListForRook();
    }
    if (piece == 3) {
      setListForKnight();
    }
    if (piece == 4) {
      setListForBishop();
    }

    if (piece == 5) {
      setListForPawn();
    }

    if (moveList.contains(candidateSquare.getPosition())) {
      return true;
    }
    return false;
  }
Beispiel #4
0
 public String getLetter() {
   switch (piece) {
     case 0:
       return "K";
     case 1:
       return "Q";
     case 2:
       return "R";
     case 3:
       return "N";
     case 4:
       return "B";
     default:
       return ((square.getPosition()).substring(0, 1));
   }
 }