
Untitled
By: a guest on
Aug 7th, 2012 | syntax:
None | size: 1.25 KB | hits: 9 | expires: Never
//Compares how much the blocks on two boards differ by
//Use to determine how much distance there is between one board configuration and
//the goal configuration
//addition from ashley.
public int compareBoards (board a) {
board currBoard = new board (this.blockList);
board goalBoard = new board (a.blockList);
int totalDist = 0;
if(!goalBoard.blockList.isEmpty()) {
Iterator<Block> iter = goalBoard.blockList.iterator();
while(iter.hasNext()) {
totalDist = totalDist + currBoard.compareBoardsHelper(iter.next());
}
}
return totalDist;
}
public int compareBoardsHelper (Block goal) {
int totalDist = 0;
int index = 0;
int minDist = 10000;
if (!this.blockList.isEmpty()) {
Iterator<Block> iter = this.blockList.iterator();
while(iter.hasNext()) {
Block n = iter.next();
if (goal.isSameSize(n)) {
if (goal.compareBlocks(n) < minDist) {
minDist = goal.compareBlocks(n);
index = this.blockList.indexOf(n);
}
this.blockList.remove(index);
totalDist = totalDist + minDist;
} else {
//do nothing
}
}
}
return totalDist;
}