boolean executeAutoMove(INode state){
  autoMoves.clear();
  boolean found=false;
  do {
    found=false;
    FreeCellNode fcn=(FreeCellNode)state;
    for (int i=0; i < fcn.freeEncoding.length; i++) {
      short card=fcn.freeEncoding[i];
      int suit=((card - 1) % 4);
      int rank=1 + ((card - 1) >> 2);
      boolean isBlack=(suit == FreeCellNode.CLUBS || suit == FreeCellNode.SPADES);
      boolean canMove=false;
      if (isBlack) {
        canMove=(fcn.foundationEncoding[FreeCellNode.DIAMONDS] >= rank - 1) && (fcn.foundationEncoding[FreeCellNode.HEARTS] >= rank - 1);
      }
 else {
        canMove=(fcn.foundationEncoding[FreeCellNode.CLUBS] >= rank - 1) && (fcn.foundationEncoding[FreeCellNode.SPADES] >= rank - 1);
      }
      if (canMove) {
        FreeToFoundationMove fm=new FreeToFoundationMove(card);
        if (fm.isValid(state)) {
          fm.execute(state);
          autoMoves.add(fm);
          found=true;
        }
      }
    }
    for (int c=0; c < fcn.cols.length; c++) {
      if (fcn.cols[c].num == 0) {
        continue;
      }
      short bottomCard=fcn.cols[c].cards[fcn.cols[c].num - 1];
      if (bottomCard == 0) {
        continue;
      }
      int suit=((bottomCard - 1) % 4);
      int rank=1 + ((bottomCard - 1) >> 2);
      boolean isBlack=(suit == FreeCellNode.CLUBS || suit == FreeCellNode.SPADES);
      boolean canMove=false;
      if (isBlack) {
        canMove=(rank <= 2) || ((fcn.foundationEncoding[FreeCellNode.DIAMONDS] >= rank - 1) && (fcn.foundationEncoding[FreeCellNode.HEARTS] >= rank - 1));
      }
 else {
        canMove=(rank <= 2) || ((fcn.foundationEncoding[FreeCellNode.CLUBS] >= rank - 1) && (fcn.foundationEncoding[FreeCellNode.SPADES] >= rank - 1));
      }
      if (canMove) {
        ColumnToFoundationMove cm=new ColumnToFoundationMove(c);
        if (cm.isValid(state)) {
          cm.execute(state);
          autoMoves.add(cm);
          found=true;
        }
      }
    }
  }
 while (found);
  return true;
}

boolean executeAutoMove ( INode state ) { autoMoves . clear ( ) ; boolean found = false ; do { found = false ; FreeCellNode fcn = ( FreeCellNode ) state ; for ( int i = 0 ; i < fcn . freeEncoding . length ; i ++ ) { short card = fcn . freeEncoding [ i ] ; int suit = ( ( card - 1 ) % 4 ) ; int rank = 1 + ( ( card - 1 ) > > 2 ) ; boolean isBlack = ( suit == FreeCellNode . CLUBS || suit == FreeCellNode . SPADES ) ; boolean canMove = false ; if ( isBlack ) { canMove = ( fcn . foundationEncoding [ FreeCellNode . DIAMONDS ] >= rank - 1 ) && ( fcn . foundationEncoding [ FreeCellNode . HEARTS ] >= rank - 1 ) ; } else { canMove = ( fcn . foundationEncoding [ FreeCellNode . CLUBS ] >= rank - 1 ) && ( fcn . foundationEncoding [ FreeCellNode . SPADES ] >= rank - 1 ) ; } if ( canMove ) { FreeToFoundationMove fm = new FreeToFoundationMove ( card ) ; if ( fm . isValid ( state ) ) { fm . execute ( state ) ; autoMoves . add ( fm ) ; found = true ; } } } for ( int c = 0 ; c < fcn . cols . length ; c ++ ) { if ( fcn . cols [ c ] . num == 0 ) { continue ; } short bottomCard = fcn . cols [ c ] . cards [ fcn . cols [ c ] . num - 1 ] ; if ( bottomCard == 0 ) { continue ; } int suit = ( ( bottomCard - 1 ) % 4 ) ; int rank = 1 + ( ( bottomCard - 1 ) > > 2 ) ; boolean isBlack = ( suit == FreeCellNode . CLUBS || suit == FreeCellNode . SPADES ) ; boolean canMove = false ; if ( isBlack ) { canMove = ( rank <= 2 ) || ( ( fcn . foundationEncoding [ FreeCellNode . DIAMONDS ] >= rank - 1 ) && ( fcn . foundationEncoding [ FreeCellNode . HEARTS ] >= rank - 1 ) ) ; } else { canMove = ( rank <= 2 ) || ( ( fcn . foundationEncoding [ FreeCellNode . CLUBS ] >= rank - 1 ) && ( fcn . foundationEncoding [ FreeCellNode . SPADES ] >= rank - 1 ) ) ; } if ( canMove ) { ColumnToFoundationMove cm = new ColumnToFoundationMove ( c ) ; if ( cm . isValid ( state ) ) { cm . execute ( state ) ; autoMoves . add ( cm ) ; found = true ; } } } } while ( found ) ; return true ; }
see if there are any possible automoves .
