C# 方法冻结整个程序

Jas*_*per -1 c# methods freeze

我已经用 C# 为我正在开发的一个小型 Forms 程序编写了以下方法,但每当我尝试运行此方法时,整个程序都会冻结。

没有错误,我尝试for (int n = 0; n<8; n++)这样做while(true),但这似乎没有改变任何事情......

有任何想法吗?提前致谢!

public bool legalMove(int y, int x)
    {
        // Check if the cell is occupied
        if (grid[x, y] != 0)
            return false;

        // Check if there's an opponents circle somewhere around it
        for (int i = -1; i<=1; i++)
            for (int j = -1; i<=1; j++)
            {
                if (i == 0 && j == 0)
                    continue;

                int row = x + i;
                int col = y + j;

                if (row >= 0 && row < 8 && col >= 0 && col < 8 && grid[col,row] == -turn)
                {
                    // Now we know that there's an opponents circle somewhere around this space, we now check if it can be captured
                    while(true)
                    {
                        row += i;
                        col += j;

                        if (row < 0 || row > 7 || col < 0 || col > 7 || grid[row, col] == 0)
                            return false; // Outside of the board or an empty space
                        else if (grid[row, col] == turn)
                            return true; // No empty spaces between our cell and another cell of ours 
                    }
                }
            }
        return false; // No cell found around ours
    }
Run Code Online (Sandbox Code Playgroud)

Dia*_*cus 6

问题是这样的:for (int j = -1; i<=1; j++)。应该j<=1代替i<=1.