所以提供一些背景信息。我正在创建一个可以自行解决的小扫雷问题。我首先从一个非常基本的算法开始,它将执行该算法,当它看到“-”字符时,它将对该位置进行猜测。是的,我知道这很可怕,但我很快就会推进它。
但这是我的问题。
输入
public int[] aiMove()
{
int[] move = new int[2];
for(int a = 0; a<board.length-1; a++)
{
for(int b = 0; b<board.length-1; b++)
{
System.out.println(a +" and "+ b);
System.out.println(a+"<"+(board.length-1));
System.out.println(b+"<"+(board.length-1));
if(board[a][b]=='-')
{
move[0]=a;
move[1]=b;
return move;
}
else
{
System.out.println("No Moves left");
}
}
}
return move;
}
出于某种原因,它不想增加 a 和 b 值。
它陷入了无限循环,因此我快速检查了代码中的那些打印语句。
这就是返回的内容。
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
0 and 0
0<7
0<7
最佳答案
每次调用此方法时都会经历以下过程:
if(board[a][b]=='-')
{
move[0]=a;
move[1]=b;
return move;
和 aiMove
必须从另一个方法重复调用。
关于java - 循环不递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34354889/