Connect 4:Drop功能仅适用于两行


const int N = 200;
const string usr1 = "o", usr2 = "x";
void updateBoard(string a[N][N], int c, int n, string xo) {
int col = c - 1;
int row = n - 1;
for (int i = row; i >= 0; i--) {
if ((a[i][col] == usr1) || (a[i][col] == usr2)) {
a[i - 1][col] = xo;
}
if ((a[i][col] == " ")) {
a[i][col] = xo;
}
i = 0;
}
}

我不知道怎么了,它停在第二行,当我试图降到第三行时,它重写了第二行的值。。。发生这种情况:

| x |
| x |

想要这个:

| x |
| o |
| x |

我找到了答案。。。以下是固定功能:

bool updateBoard(string board[N][N], int col, int n, string xo) {
for (int i = n - 1; i >= 0; i--) {
if (board[i][col - 1] == "-") {
board[i][col - 1] = xo;
return true;
}
}
return false;
}

最新更新