Skip to content

Commit ef8a4a2

Browse files
minor speedup
assuming the standard formulation of the 8puzzle problem, there can't be any two tiles with the same value
1 parent f3dd4a6 commit ef8a4a2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

aima-core/src/main/java/aima/core/environment/eightpuzzle/EightPuzzleBoard.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,17 @@ private int getGapPosition() {
206206
}
207207

208208
private int getPositionOf(int val) {
209-
int retVal = -1;
210209
for (int i = 0; i < 9; i++) {
211210
if (state[i] == val) {
212-
retVal = i;
211+
return i
213212
}
214213
}
215-
return retVal;
214+
return -1;
216215
}
217216

218217
private void setValue(int x, int y, int val) {
219218
int absPos = getAbsPosition(x, y);
220219
state[absPos] = val;
221220

222221
}
223-
}
222+
}

0 commit comments

Comments
 (0)