每次运行以下方法时,都会不断出现错误。即使列表不是空的,错误仍然存在。
public Position getBestMove() {
int max = -10000;
int best = -1;
System.out.println("CALLED");
System.out.println(successorEvaluations.size());
// iterate over successors and return the one with the highest eval result
for (int i = 0; i < successorEvaluations.size(); i++) {
if (max < successorEvaluations.get(i).score) {
max = successorEvaluations.get(i).score;
best = i;
}
}
return successorEvaluations.get(best).pos;
}
错误输出:
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at Board.getBestMove(Board.java:151)
最佳答案
best
为-1,这是非法的数组索引。 if
条件不满足。
关于java - 异常ArrayIndexOutOfBoundsException错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40963316/