Ejemplo n.º 1
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;
  }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
  }