#include <iostream>
using namespace std;
int tablet[20][20]={0};
int five(){
for (int i=0;i<20;i++){
for (int j=0;j<20;j++){
if((tablet[i][j]==1&&tablet[i+1][j]==1&&tablet[i+2][j]==1&&tablet[i+3][j]==1&&tablet[i+4][j]==1)||\
(tablet[i][j+1]==1&&tablet[i][j+2]==1&&tablet[i][j+3]==1&&tablet[i][j+4]==1&&tablet[i][j]==1)||\
(tablet[i+4][j+4]==1&&tablet[i+3][j+3]==1&&tablet[i+2][j+2]==1&&tablet[i+1][j+1]==1&&tablet[i][j]==1)){
return 1;
}else if((tablet[i][j]==2&&tablet[i+1][j]==2&&tablet[i+2][j]==2&&tablet[i+3][j]==2&&tablet[i+4][j]==2)||\
(tablet[i][j+1]==2&&tablet[i][j+2]==2&&tablet[i][j+3]==2&&tablet[i][j+4]==2&&tablet[i][j]==2)||\
(tablet[i+4][j+4]==2&&tablet[i+3][j+3]==2&&tablet[i+2][j+2]==2&&tablet[i+1][j+1]==2&&tablet[i][j]==2)){
return 2;
}else{
return 0;
}
}
}
}
void out(){
for (int i=0;i<20;i++){
for (int j=0;j<20;j++){
cout<<tablet[j][i]<<" ";
}
cout<<endl;
}
}
int main() {
cout<<"Welcome to gobang, rules: each time it is your turn to play chess, enter two \
integers x and y (a space in between) to represent x and y coordinates, 0 0 in the upper\
left corner and 19 19 in the lower right corner. In the chessboard, black is 1, white\
is 2, and empty is 0."<<endl;
int a=0;
while (1){
int x,y;
if (a%2==0){
cout<<"black's turn."<<endl;
cin>>x>>y;
if (x<20&&y<20&&tablet[y][x]==0){
tablet[y][x]=1;
}else{
cout<<"Maybe it's out of bounds and it's overwriting another piece. Please retype"<<endl;
continue;
}
}else{
cout<<"white's turn."<<endl;
cin>>x>>y;
if (x<20&&y<20&&tablet[y][x]==0){
tablet[y][x]=2;
}else{
cout<<"Maybe it's out of bounds and it's overwriting another piece. Please retype"<<endl;
continue;
}
}
a++;
out();
int five_=five();
if (five_!=0){
break;
}
}
if (five()==1){
cout<<"black wins!!!";
}else{
cout<<"white wins!!!";
}
return 0;
}
为什么这个五子棋代码会错误?(连成5个了但是并不会结束,(主要问题大概也许是在five()函数里面对吧))