private static void showTheCasesForTheFirstTimeAuxi(
      Position current, Piece p) { // les cases où la piece a le droit de se deplacer

    if (p.getType().equals("Pion") && p.getCouleur().equals("noir")) {
      System.out.println(current.getColonne());
      System.out.println(current.getLigne());
      Position a1 = createFinishPosition(current.getColonne(), current.getLigne() - 1);
      Position a2 = createFinishPosition(current.getColonne(), current.getLigne() - 2);
      if (getCasesToModify()[a1.getLigne()][a1.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a1);
      }
      if (getCasesToModify()[a2.getLigne()][a2.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a2);
      }
    }
    if (p.getType().equals("Pion") && p.getCouleur().equals("blanc")) {
      Position a1 = createFinishPosition(current.getColonne(), current.getLigne() + 1);
      Position a2 = createFinishPosition(current.getColonne(), current.getLigne() + 2);
      if (getCasesToModify()[a1.getLigne()][a1.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a1);
      }
      if (getCasesToModify()[a2.getLigne()][a2.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a2);
      }
    }
  }
Exemple #2
0
  private void change(final Coordinate coord1, final Coordinate coord2) {
    final Piece piece = pieces[coord1.getY()][coord1.getX()];
    final Piece piece2 = pieces[coord2.getY()][coord2.getX()];

    if (piece.getType() != piece2.getType()) {
      throw new IllegalArgumentException(
          "Versuche " + piece.getType() + " mit " + piece2.getType() + " zu tauschen.");
    }
    pieces[coord1.getY()][coord1.getX()] = pieces[coord2.getY()][coord2.getX()];
    pieces[coord2.getY()][coord2.getX()] = piece;
  }
Exemple #3
0
 private void arrange() {
   int y = 0;
   for (final Piece[] row : pieces) {
     int x = 0;
     for (final Piece piece : row) {
       if (piece.getType() == PieceType.CORNER) {
         rotateCorner(x, y, piece);
       } else if (piece.getType() == PieceType.BORDER) {
         rotateBorder(x, y, piece);
       }
       x++;
     }
     y++;
   }
 }
Exemple #4
0
  /** Determines whether the king can be captured by the player with the move. */
  public boolean isKingLeftInCheck() {
    MoveLogic attacksKingLogic = new MoveAttacksKingLogic();

    HashSet<Move> attackingMoves;
    PieceColor colorToMove = this.getColorToMove();
    int kx = -1; // If search succeeds, these should be set to "real" values
    int ky = -1;

    squareloop:
    for (int j = 0; j < Chess.BOARD_SIZE; j++) {
      for (int i = 0; i < Chess.BOARD_SIZE; i++) {
        Piece pieceHere = this.getPieceAt(new Square(i, j));
        if (pieceHere.getType() == PieceType.KING && pieceHere.getColor() == colorToMove.invert()) {
          kx = i;
          ky = j;
          break squareloop;
        }
      }
    }

    assert ((kx != -1) || (ky != -1))
        : "Unexpected search failure, inconsistent state.  King not found.";
    Square kingSquare = new Square(kx, ky);

    attackingMoves = possibleMovesWhichEndAt(kingSquare);

    for (Move move : attackingMoves) {
      if (attacksKingLogic.isLegal(this, move)) {
        return true;
      }
    }
    return false;
  }
Exemple #5
0
 private void rotate() {
   final Coordinate c = randomNormal();
   final Piece piece = pieces[c.getY()][c.getX()];
   if (piece.getType() == PieceType.NORMAL) {
     piece.rotate((int) GaUtil.random(1, 3));
   }
 }
Exemple #6
0
 public ArrayList<Piece> getPiecesOfTypes(PieceTypes.Color color, PieceTypes.Type type) {
   ArrayList<Piece> ret = new ArrayList<Piece>();
   for (Piece p : pieces) {
     if (p.getColor() == color && p.getType() == type) {
       ret.add(p);
     }
   }
   return ret;
 }
Exemple #7
0
  /**
   * Return information about given square.
   *
   * @param loc Square location as a SAN string.
   * @return The type of the piece or null.
   */
  public Type typeAt(String loc) {
    try {
      Piece piece = board.pieceAt(new Coord(loc));
      return (piece == null) ? null : piece.getType();
    } catch (Exception pass) {
    }

    return null;
  }
Exemple #8
0
 private void cross(final Piece piece, final Coordinate coordinate) {
   switch (piece.getType()) {
     case NORMAL:
       change(coordinate, randomNormal());
       break;
     case BORDER:
       change(coordinate, randomBorder());
       break;
     case CORNER:
       change(coordinate, randomCorner());
       break;
   }
 }
Exemple #9
0
  public static Board from(final List<Piece> pieces, final int boardSize) {

    final Deque<Piece> corners = new ArrayDeque<Piece>();
    final Deque<Piece> borders = new ArrayDeque<Piece>();
    final Deque<Piece> normal = new ArrayDeque<Piece>();

    for (final Piece piece : pieces) {
      switch (piece.getType()) {
        case NORMAL:
          normal.add(piece);
          break;
        case BORDER:
          borders.add(piece);
          break;
        case CORNER:
          corners.add(piece);
          break;
      }
    }

    return new Board(create(boardSize, corners, borders, normal), boardSize, 0).copy();
  }
  public static void showTheCases(Position current, Piece p) {
    if (p.getType().equals("Pion") && p.getCouleur().equals("noir")) {
      System.out.println(current.getColonne());
      System.out.println(current.getLigne());
      Position a1 = createFinishPosition(current.getColonne(), current.getLigne() - 1);

      if (getCasesToModify()[a1.getLigne()][a1.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a1);
      }
      priseEnDiagonale(current, p, -1, 1);
      priseEnDiagonale(current, p, -1, -1);
    }
    if (p.getType().equals("Pion") && p.getCouleur().equals("blanc")) {
      Position a1 = createFinishPosition(current.getColonne(), current.getLigne() + 1);

      if (getCasesToModify()[a1.getLigne()][a1.getColonne()].contains("img")) {
        System.out.println("Case Inocuuppe");
        modifyContent(current, a1);
      }
      // Busy Case
      System.out.println("Busy Case");
      priseEnDiagonale(current, p, 1, -1);
      priseEnDiagonale(current, p, 1, 1);
    }
    if ((p.getType().equals("Roi") && p.getCouleur().equals("noir"))
        || (p.getType().equals("Roi") && p.getCouleur().equals("blanc"))) {
      Position a1 = createFinishPosition(current.getColonne(), current.getLigne() - 1); // avancer
      Position a2 = createFinishPosition(current.getColonne() - 1, current.getLigne());
      Position a3 = createFinishPosition(current.getColonne(), current.getLigne() + 1); // reculer
      Position a4 = createFinishPosition(current.getColonne() + 1, current.getLigne());
      Position a5 = createFinishPosition(current.getColonne() + 1, current.getLigne() - 1);
      Position a6 = createFinishPosition(current.getColonne() - 1, current.getLigne() - 1);
      Position a7 = createFinishPosition(current.getColonne() + 1, current.getLigne() + 1);
      Position a8 = createFinishPosition(current.getColonne() - 1, current.getLigne() + 1);

      if (((a1.getLigne() < Echequier.sizeBoard) && (a1.getLigne() > -1))
          && ((a1.getColonne() < Echequier.sizeBoard) && (a1.getColonne() > -1))) {
        if (getCasesToModify()[a1.getLigne()][a1.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a1);
        }
      }
      if (((a2.getLigne() < Echequier.sizeBoard) && (a2.getLigne() > -1))
          && ((a2.getColonne() < Echequier.sizeBoard) && (a2.getColonne() > -1))) {
        if (getCasesToModify()[a2.getLigne()][a2.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a2);
        }
      }
      if (((a3.getLigne() < Echequier.sizeBoard) && (a3.getLigne() > -1))
          && ((a3.getColonne() < Echequier.sizeBoard) && (a3.getColonne() > -1))) {
        if (getCasesToModify()[a3.getLigne()][a3.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a3);
        }
      }
      if (((a4.getLigne() < Echequier.sizeBoard) && (a4.getLigne() > -1))
          && ((a4.getColonne() < Echequier.sizeBoard) && (a4.getColonne() > -1))) {
        if (getCasesToModify()[a4.getLigne()][a4.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a4);
        }
      }
      if (((a5.getLigne() < Echequier.sizeBoard) && (a5.getLigne() > -1))
          && ((a5.getColonne() < Echequier.sizeBoard) && (a5.getColonne() > -1))) {
        if (getCasesToModify()[a5.getLigne()][a5.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a5);
        }
      }
      if (((a6.getLigne() < Echequier.sizeBoard) && (a6.getLigne() > -1))
          && ((a6.getColonne() < Echequier.sizeBoard) && (a6.getColonne() > -1))) {
        if (getCasesToModify()[a6.getLigne()][a6.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a6);
        }
      }
      if (((a7.getLigne() < Echequier.sizeBoard) && (a7.getLigne() > -1))
          && ((a7.getColonne() < Echequier.sizeBoard) && (a7.getColonne() > -1))) {
        if (getCasesToModify()[a7.getLigne()][a7.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a7);
        }
      }
      if (((a8.getLigne() < Echequier.sizeBoard) && (a8.getLigne() > -1))
          && ((a1.getColonne() < Echequier.sizeBoard) && (a8.getColonne() > -1))) {
        if (getCasesToModify()[a8.getLigne()][a8.getColonne()].contains("img")) {
          System.out.println("Case Inocuuppe");
          modifyContent(current, a8);
        }
      }
    }
    if ((p.getType().equals("Tour") && p.getCouleur().equals("noir"))
        || (p.getType().equals("Tour") && p.getCouleur().equals("blanc"))) {
      moveTourHorizontally(p, current, +1);
      moveTourVertically(p, current, +1);
      moveTourHorizontally(p, current, -1);
      moveTourVertically(p, current, -1);
    }
    if ((p.getType().equals("Dame") && p.getCouleur().equals("noir"))
        || (p.getType().equals("Dame") && p.getCouleur().equals("blanc"))) {
      moveTourHorizontally(p, current, +1);
      moveTourVertically(p, current, +1);
      moveTourHorizontally(p, current, -1);
      moveTourVertically(p, current, -1);
      moveFouDiagonally(p, current, 1, 1);
      moveFouDiagonally(p, current, -1, -1);
      moveFouDiagonally(p, current, 1, -1);
      moveFouDiagonally(p, current, -1, 1);
    }
    if ((p.getType().equals("Fous") && p.getCouleur().equals("noir"))
        || (p.getType().equals("Fous") && p.getCouleur().equals("blanc"))) {
      moveFouDiagonally(p, current, 1, 1);
      moveFouDiagonally(p, current, -1, -1);
      moveFouDiagonally(p, current, 1, -1);
      moveFouDiagonally(p, current, -1, 1);
    }
    if ((p.getType().equals("Cavalier") && p.getCouleur().equals("noir"))
        || (p.getType().equals("Cavalier") && p.getCouleur().equals("blanc"))) {
      moveCavalierHorizontally(p, current, 2);
      moveCavalierHorizontally(p, current, -2);
      moveCavalierVertically(p, current, 2);
      moveCavalierVertically(p, current, -2);
    }
  }