Esempio n. 1
0
 /**
  * Returns a list with the valid Plies of this <code>Rook</code>, as specified in the overview.
  *
  * @return A <code>List</code> of valid <code>Plies</code> for this <code>Rook</code>; if the
  *     <code>Rook</code> is not currently in a <code>Board</code>, the <code>List</code> will be
  *     empty.
  */
 public List<Ply> getPlies() {
   checkRep();
   Board board = getBoard();
   // Create list of valid cells to move to
   List<int[]> validCells = new LinkedList<int[]>();
   List<Ply> validPlies = new ArrayList<Ply>();
   if (board.contains(this)) {
     int[] pos = board.getPosition(this);
     int[] temp = new int[2];
     // Get positions where rook can move (horizontally or vertically)
     for (int i = 0; i < 4; i++) {
       // 0 = north; 1 = east; 2 = south; 3 = west
       temp = oneCellNext(pos, i);
       while (board.isUsable(temp)
           && (board.isEmpty(temp)
               || ((board.getPiece(temp).isWhite() && !isWhite())
                   || (!board.getPiece(temp).isWhite() && isWhite())))) {
         validCells.add(temp.clone());
         if (!board.isEmpty(temp)
             && ((board.getPiece(temp).isWhite() && !isWhite())
                 || (!board.getPiece(temp).isWhite() && isWhite()))) break;
         temp = oneCellNext(temp, i);
       }
     }
     // Create list of valid moves
     for (int[] validCell : validCells) validPlies.add(new Move(pos, validCell));
   }
   checkRep();
   return validPlies;
 }