0/0、1/1、2/2、3/3。">
如果一行中有 4 个具有相同的值,我想检查大小为 8x8 的多维数组,然后调用另一个方法。IF as a example the positions 0/0, 0/1, 0/2, 0/3 have the value 1
然后调用方法finish(1)
。"但这应该也适用于对角线,比如
您可以创建一个函数并为数组的每个元素调用它。成功后,它将返回值,调用 finish 函数并结束循环。像这样:
int Check(int[,] a,int x, int y)
{
for(int n =-1;n<2;n++)
{
for(int m =-1;m<2;m++)
{
if(n!= 0 || m!= 0)
{
int previousX = x;
int previousY = y;
int nextX = previousX+n;
int nextY = previousY+m;
int counter = 0;
while((nextX >= 0 && nextX < 8 && nextY >= 0 && nextY < 8)
&& (a[previousX,previousY] ==a[nextX,nextY]))
{
counter++;
previousX += n;
previousY += m;
nextX += n;
nextY += m;
if(counter >= 3)
return a[x,y];
}
}
}
}
return -1; //That means nothing was found
}