【发布时间】:2014-07-21 20:41:56
【问题描述】:
我创建了井字游戏。我使用 minmax 算法。
当棋盘为3x3 时,我只计算游戏的所有可能移动直到结束,-1 表示失败,0 表示平局,1 表示胜利。
当涉及到 5x5 时,它无法完成(对于许多选项(如 24^24),所以我创建了评估方法,它给出:10^0 用于内联一个 CIRCLE,10^1 用于内联 2 个 CIRCLE,. .., 10^4 for 5 CIRCLES inline,但没用。
有人有更好的评估方法吗?
例子:
O|X|X| | |
----------
|O| | | |
----------
X|O| | | |
----------
| | | | |
----------
| | | | |
Evaluation -10, 2 circles across once and inline once (+200), 2 crosses inline(-100), and -1 three times and + 1 three times for single cross and circle.
这是我现在的评价方法:
public void setEvaluationForBigBoards() {
int evaluation = 0;
int howManyInLine = board.length;
for(; howManyInLine > 0; howManyInLine--) {
evaluation += countInlines(player.getStamp(), howManyInLine);
evaluation -= countInlines(player.getOppositeStamp(), howManyInLine);
}
this.evaluation = evaluation;
}
public int countInlines(int sign, int howManyInLine) {
int points = (int) Math.pow(10, howManyInLine - 1);
int postiveCounter = 0;
for(int i = 0; i < board.length; i++) {
for(int j = 0; j < board[i].length; j++) {
//czy od tego miejsca jest cos po przekatnej w prawo w dol, w lewo w dol, w dol, w prawo
if(toRigth(i, j, sign, howManyInLine))
postiveCounter++;
if(howManyInLine > 1) {
if(toDown(i, j, sign, howManyInLine))
postiveCounter++;
if(toRightDiagonal(i, j, sign, howManyInLine))
postiveCounter++;
if(toLeftDiagonal(i, j, sign, howManyInLine))
postiveCounter++;
}
}
}
return points * postiveCounter;
}
【问题讨论】:
-
你应该添加检查这个“线”是否真的可以形成一个胜利线。否则,有没有用。结果,对于给定的情况,您只能在对角线上计算“o”(其余不能形成 5 行)
标签: java evaluation tic-tac-toe heuristics