【发布时间】:2014-03-29 22:50:42
【问题描述】:
我正在尝试实现一个将 Minimax 用于点盒游戏的 AI (http://en.wikipedia.org/wiki/Dots_and_Boxes)
这是我目前所拥有的:
public Line makeMove(GameState gs) {
if (gs.getRemainingLines().size() == 1) {
return gs.getRemainingLines().get(0);
}
if (gs.getPlayer() == 1) {
int minscore = -1;
GameState g = gs.clone();
Line lnew = null;
List<Line> l = gs.getRemainingLines();
for (Line l2 : l) {
g.addLine(l2);
if (evaluate(g) > minscore) {
minscore = (evaluate(g));
lnew = l2;
}
}
return lnew;
} else {
int maxscore = 999;
GameState g = gs.clone();
Line lnew = null;
List<Line> l = gs.getRemainingLines();
for (Line l2 : l) {
g.addLine(l2);
if (evaluate(g) < maxscore) {
maxscore = (evaluate(g));
lnew = l2;
}
}
return lnew;
}
}
但是,它不断返回null,我认为我没有正确地实现极小值。谁能给我一些指点。
getRemainingLines() 返回一个仍然可以移动的列表。
evaluate() 为分数返回一个 int。
【问题讨论】:
-
你能追踪你的评估函数吗?
-
你的空指针异常是什么样的?你能包括堆栈跟踪吗?
标签: java artificial-intelligence minimax