Examples of Piece


Examples of echiquier.pieces.Piece

   * @param Position
   *            pf: position finale
   */
  @SuppressWarnings("unchecked")
  public DeplacementEtat deplacer(Position pi, Position pf) {
    Piece pieceF = getPieceAt(pf);
    Piece pieceI = getPieceAt(pi);

    System.out
        .println("Déplacement du " + pieceI.getClass().getSimpleName()
            + " " + pieceI.getCouleur());

    // si une piece est mangée on la met dans une liste
    if (pieceF != null) {
      if (pieceF.getCouleur() == Couleur.BLANC)
        piecesBlanches.add(pieceF);
      else
        piecesNoires.add(pieceF);
    }
   
    //On effectue la permutation en reine s'il s'agit d'un pion en bout de course
    if (pieceI.getClass().getSimpleName().equals("Pion")) {
      if(pf.getY() == 0 && pieceI.getCouleur() == Couleur.NOIR) {
        pieceI = new Reine(Couleur.NOIR);
      }
      if(pf.getY() == 7 && pieceI.getCouleur() == Couleur.BLANC) {
        pieceI = new Reine(Couleur.BLANC);
      }
    }
   
    plateau.put(pf, pieceI);
View Full Code Here

Examples of echiquier.pieces.Piece

   */
  void displayEchiquier(Echiquier eq) {

    for (Entry<Position, Piece> e : eq.getPlateau().entrySet()) {

      Piece p = e.getValue();

      addPiece(p, e.getKey().getX(), e.getKey().getY());

    }
  }
View Full Code Here

Examples of general.Piece

        if (isSrcSelected()) {
          if (showLegalMoves) {
            //paint own piece's background
            paintSquare(getSelectedSrc(), blue);
            //paint legal moves background
            Piece piece = board.notationToPiece(getSelectedSrc());
            //get all movements that are allowed for the selected piece
            ArrayList<ArrayList<Integer>> legalMoves = move.possiblePieceMoves(piece, false);
            ArrayList<Integer> x = legalMoves.get(0); //list of row numbers
            ArrayList<Integer> y = legalMoves.get(1); //list of column numbers
            ListIterator<Integer> xList = x.listIterator()//row iterator
View Full Code Here

Examples of general.Piece

     * @param src
     * @param dest
     */
    public void movePiece(Board board, Move move, Player player, String src, String dest) {
      //get piece to move
      Piece p = board.notationToPiece(src);
      //array coordinates for new destination
    Index newLoc = board.notationToIndex(dest);
    //remove captured piece from the board
    board.removePiece(newLoc.getX(), newLoc.getY());
    p.setRow(newLoc.getX()); //change piece row
    p.setCol(newLoc.getY()); //change piece column
    //place source and destination square to history of moves
    if (player.getSide()==0) { //if white
      //add white piece move to history
      move.getHistoryOfMoves().addWhiteMove(src, dest);
    } else if (player.getSide()==1) { //if black
View Full Code Here

Examples of general.Piece

    public boolean isDestSqValid(String srcSq, String destSq, Move move, Board board, Player player) {
      //check source square notation for validity
      if (!move.checkSqValidity(destSq)) {
        return false;
      }
    Piece piece = board.notationToPiece(srcSq);
    //get all movements that are allowed for the selected piece
    ArrayList<ArrayList<Integer>> legalMoves = move.possiblePieceMoves(piece, false);
    //array coordinates for new destination
    Index newLoc = board.notationToIndex(destSq);
    //find out if destination location is included in the legal moves list
View Full Code Here

Examples of general.Piece

    ArrayList<ArrayList<Piece>> pieces = getPiecesPossibleToCapture(side, false);
    ArrayList<Piece> ownPieces = pieces.get(0);
    ArrayList<Piece> enemyPieces = pieces.get(1);
    ListIterator<Piece> ownList = ownPieces.listIterator();
    ListIterator<Piece> enemyList = enemyPieces.listIterator();
    Piece ownPiece, enemyPiece;
    while (ownList.hasNext() && enemyList.hasNext()) {
      ownPiece = ownList.next();
      enemyPiece = enemyList.next();
      System.out.print(board.coordinatesToNotation(ownPiece.getRow(), ownPiece.getCol()));
      System.out.print(", ");
      System.out.println(board.coordinatesToNotation(enemyPiece.getRow(), enemyPiece.getCol()));
   
  }
View Full Code Here

Examples of general.Piece

    ArrayList<ArrayList<Piece>> pieces = getPiecesPossibleToCapture(side, false);
    ArrayList<Piece> ownPieces = pieces.get(0);
    ArrayList<Piece> enemyPieces = pieces.get(1);
    ListIterator<Piece> ownList = ownPieces.listIterator();
    ListIterator<Piece> enemyList = enemyPieces.listIterator();
    Piece ownPiece, enemyPiece;
    int highestValue = 0, tempValue = 0;
    while (ownList.hasNext() && enemyList.hasNext()) {
      ownPiece = ownList.next();
      enemyPiece = enemyList.next();
      tempValue = enemyPiece.getValue();
View Full Code Here

Examples of general.Piece

   * @param list
   * @param length
   */
  public void sortPieceArray(Piece[] list, int length) {
      int outOfOrder, location;
      Piece temp;
      //from second until the end of the array
      for(outOfOrder = 1; outOfOrder < length; outOfOrder++) {
        //if out of order, move to the right place
          if(list[outOfOrder].getValue() < list[outOfOrder - 1].getValue()) {
              temp = list[outOfOrder];
              location = outOfOrder;
              do { //move down the array until correct place is found
                  list[location] = list[location-1];
                  location--;
              }
              while (location > 0 && list[location-1].getValue() > temp.getValue());
              list[location] = temp;
          }
      }
  }
View Full Code Here

Examples of general.Piece

   * @param side
   */
  public void printHighestValuePieceAbleToCapture(int side) {
    Piece[] p = highestValuePieceAbleToCapture(side);
    try {
      Piece ownP = p[0];
      Piece enemyP = p[1];
      System.out.print(board.coordinatesToNotation(ownP.getRow(), ownP.getCol()));
      System.out.print(", ");
      System.out.println(board.coordinatesToNotation(enemyP.getRow(), enemyP.getCol()));
    } catch(NullPointerException e){
      //System.out.println("NullPointerException");
    }
  }
View Full Code Here

Examples of general.Piece

   */
  public void defense(Player player) {
    //get an array containing enemy piece and the highest value piece it can capture
    Piece[] highestValPiece = highestValuePieceAbleToCapture(player.getEnemySide());
    //get the highest value piece that enemy can capture
    Piece pieceInDanger = highestValPiece[1];
    //find possible squares where piece can move
    ArrayList<ArrayList<Integer>> possibleMoves = move.possiblePieceMoves(pieceInDanger, false);
    ArrayList<Integer> possibleMovesX = possibleMoves.get(0); //get x coordinates
    ArrayList<Integer> possibleMovesY = possibleMoves.get(1); //get y coordinates
    //find possible squares enemy pieces can move
    ArrayList<ArrayList<Integer>> possibleEnemyMoves = getAllSquaresPossibleToMove(player.getEnemySide());
    ArrayList<Integer> possibleEnemyMovesX = possibleEnemyMoves.get(0); //get x coordinates
    ArrayList<Integer> possibleEnemyMovesY = possibleEnemyMoves.get(1); //get y coordinates
    //find a square own piece can move safely
    /*
     * compare possible own piece movements to enemy piece movements to find
     * a safe square.
     */
    ListIterator<Integer> pmxList, pmyList; //iterators for possible own piece moves
    pmxList = possibleMovesX.listIterator()//row iterator
    pmyList = possibleMovesY.listIterator()//column iterator
    //convert arraylist of enemy x movement coordinates into an array
    int[] pexArray = new int[possibleEnemyMovesX.size()];
      for (int i=0; i < pexArray.length; i++) {
        pexArray[i] = possibleEnemyMovesX.get(i).intValue();
      }
      //convert arraylist of enemy y movement coordinates into an array
    int[] peyArray = new int[possibleEnemyMovesY.size()];
      for (int i=0; i < peyArray.length; i++) {
        peyArray[i] = possibleEnemyMovesY.get(i).intValue();
      }
    int pmx=0, pmy=0, pex, pey;
    boolean match = true;
    //check possible own piece moves until safe square is found or possible moves run out
    while (pmxList.hasNext() && pmyList.hasNext() && match) {
      match = false; //reset to false
      //get next own piece move
      pmx = pmxList.next();
      pmy = pmyList.next();
      enemy: for (int i=0; i<pexArray.length; i++) {
        //get enemy piece move
        pex = pexArray[i];
        pey = peyArray[i];
        //compare
        //if match found no need to check other enemy moves
        if (pmx==pex && pmy==pey) {
          match = true;
          break enemy;
        }
      }
    }
    //if none of the enemy moves match -> move own piece to that square
    if (!match) {
      move.doMove(player, board.coordinatesToNotation(pieceInDanger.getRow(),
          pieceInDanger.getCol()), board.coordinatesToNotation(pmx, pmy));
    } else if (match) {
      /*
       * if the piece can't be safed by moving it to a safe square
       * try to trade a less valuable piece.
       *
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.