Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 1.25 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  //Compares how much the blocks on two boards differ by
  2.   //Use to determine how much distance there is between one board configuration and
  3.   //the goal configuration
  4.   //addition from ashley.
  5.   public int compareBoards (board a) {
  6.     board currBoard = new board (this.blockList);
  7.     board goalBoard = new board (a.blockList);
  8.     int totalDist = 0;
  9.     if(!goalBoard.blockList.isEmpty()) {
  10.       Iterator<Block> iter = goalBoard.blockList.iterator();
  11.       while(iter.hasNext()) {
  12.         totalDist = totalDist + currBoard.compareBoardsHelper(iter.next());
  13.       }
  14.     }
  15.    
  16.     return totalDist;
  17.   }
  18.  
  19.   public int compareBoardsHelper (Block goal) {
  20.     int totalDist = 0;
  21.     int index = 0;
  22.     int minDist = 10000;
  23.     if (!this.blockList.isEmpty()) {
  24.       Iterator<Block> iter = this.blockList.iterator();
  25.       while(iter.hasNext()) {
  26.         Block n = iter.next();
  27.         if (goal.isSameSize(n)) {
  28.           if (goal.compareBlocks(n) < minDist) {
  29.             minDist = goal.compareBlocks(n);
  30.             index = this.blockList.indexOf(n);
  31.           }
  32.           this.blockList.remove(index);
  33.           totalDist = totalDist + minDist;
  34.         } else {
  35.           //do nothing
  36.         }
  37.       }
  38.     }
  39.     return totalDist;
  40.   }