Пример #1
0
 public boolean validTake(Point start, Point end) {
   Piece piece = b.get(start);
   Piece ending = b.get(end);
   if (ending != null
       && piece.validCapture(start, end)
       && checkIfPathIsClear(start, end)
       && piece.getColor() != ending.getColor()) {
     return true;
   }
   return false;
 }
Пример #2
0
 public boolean movePiece(Point startLocation, Point endLocation) {
   Piece piece = b.get(startLocation);
   if (piece.pieceMovement(startLocation, endLocation)
       && checkIfPathIsClear(startLocation, endLocation)) {
     b.put(endLocation, b.get(startLocation));
     b.remove(startLocation);
     piece.setHasNotMoved(false);
     return true;
   }
   return false;
 }
Пример #3
0
  public ArrayList<Point> validMove(Point p) {
    ArrayList<Point> validMoves = new ArrayList<Point>();
    Piece piece = b.get(p);

    for (int i = 1; i <= 8; i++) {
      for (int j = 1; j <= 8; j++) {
        Piece p2 = b.get(new Point(i, j));
        if ((p2 == null && piece.pieceMovement(p, new Point(i, j))
                || (validTake(p, new Point(i, j))))
            && !isKingInCheck()
            && checkIfPathIsClear(p, new Point(i, j))) {
          validMoves.add(new Point(i, j));
          //	System.out.println(p + " " + i + " " + j );
        }
      }
    }
    return validMoves;
  }
Пример #4
0
 public boolean takePiece(Point startLocation, Point endLocation) {
   Piece piece = b.get(startLocation);
   Piece ending = b.get(endLocation);
   if (piece.validCapture(startLocation, endLocation)
       && checkIfPathIsClear(startLocation, endLocation)
       && piece.getColor() != ending.getColor()) {
     b.remove(endLocation);
     b.put(endLocation, b.get(startLocation));
     b.remove(startLocation);
     piece.setHasNotMoved(false);
     return true;
   }
   return false;
 }
Пример #5
0
  public boolean castling(Point k1, Point k2, Point r1, Point r2) {
    Piece k = b.get(k1);
    Piece r = b.get(r1);

    if (checkIfPathIsClear(k1, r1) && k.pieceMovement(k1, k2) && r.pieceMovement(r1, r2)) {
      b.put(k2, b.get(k1));
      b.put(r2, b.get(r1));
      b.remove(k1);
      b.remove(r1);
      k.setHasNotMoved(false);
      r.setHasNotMoved(false);
      return true;
    }
    return false;
  }