我正在按照这篇文章制作一个 AI 。基本思想是使用位板制作一个非常快速的协议,用于对板进行修改并通过可能的游戏结果进行排列。
但是这篇文章是用 python 写的,我在最初的位板设置之后遇到了麻烦。我去了他们参考的github 自述文件,希望为我的 AI 开发框架,然后担心 alpha-beta 修剪和机器学习。基本上,我通过了 、 和 的方法checkWin
,makeMove
并undoMove
为列的高度、移动、移动的计数以及代表玩家位板的长变量数组建立了所需的字段。
但我目前停留在 generate move 方法上,因为它试图初始化列之外位板顶部的所有值。但是在java中我似乎不能这样做:它只是给了我这个文字类型超出了long类型范围的错误。另外看到动作是int[]
我不知道如何使用moves.push(col)
. 因为这给出了错误 cannot invoke push(int)
。您将在下面找到损坏的listMoves
方法和我当前的代码,如果有人能告诉我一些我可能在我的代码中做错的事情以及或如何修复该listMoves
方法,我将非常感激。干杯!
private int[] listMoves() {
int[] moves;
long TOP = 1000000_1000000_1000000_1000000_1000000_1000000_1000000L;
for(int col = 0; col <= 6; col++) {
if ((TOP & (1L << height[col])) == 0) moves.push(col);
}
return moves;
}
我的代码
public class EConnectFour {
private int[] height = {0, 0, 0, 0, 0, 0, 0};
private int[] moves = new int[42]; // add size
private int counter = 0;
private long[] bitBoard = new long[2];
public static void main(String[] args) {
}
private char[][] getGameState() {
// add code to get current gamestate
return new char[0][0];
}
private boolean isWin(long bitBoard) {
int[] directions = {1, 7, 6, 8};
long bb;
for(int direction : directions) {
bb = bitBoard & (bitBoard >> direction);
if ((bb & (bb >> (2 * direction))) != 0) return true;
}
return false;
}
private void makeMove(int column) {
long move = 1L << height[column]++;
bitBoard[counter & 1] ^= move;
moves[counter++] = column;
}
private void undoMove() {
int column = moves[--counter];
long move = 1L << --height[column];
bitBoard[counter & 1] ^= move;
}
}