我创建了一个连接四,试图实现删除功能,添加到特定列的最低行。这是董事会的初始化
Board::Board()
{
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
place[i][j] = EMP; // EMP is a const char = '-'
cout << "Initalized.\n";
}
由于某种原因,这段代码一直运行到 i = 1,然后将 place[1][col] 设置为 * 但是当我去显示这个时,它会在数组底部显示 *,所以 place[7][科尔]。
同样 this->place 和 place in the cout 在开始时永远不会给我应该的'-'输出。
int Board::add(int player, int col)
{
char piece;
col--; // Dealing with array starting at 0, not 1
(player==1) ? piece = P1: piece = P2; // Character defining players piece
int i;
for (i = 7; i >= 0; i--)
{
cout << "this - " << this->place[i][col] << endl;
cout << "place - " << place[i][col] << endl;
if(place[i][col] == EMP)
{
cout << "Empty looks like " << place[i][col] << "\ti: " << i << endl;
place[i][col] = piece;
system("pause");
return i;
}else
{
cout << "not EMP - " << place[i][col] << endl;
system("pause");
}
}
return 0;
}