#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
char board[4][4]={{'-','-','-','-'},{'-','-','-','-'}};
const int row=4;
const int col=4;
char b;
void printboard(char[][col]){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
}
bool boardIsFull(char b[][col]){
for (int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(b[i][j]=='-')
return false;
return true;
}
bool occupied(char b[][col], int indx1,int indx2){
if(b[indx1][indx2]=='-')
return false;
return true;
}
void printremianindex(char b[][col]){
for ( int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(b[i][j]=='-')
cout<<"("<<i<<","<<j<<")";
cout<<endl;
}
bool win(char b[][col]){
char c;
int winlen=4;
for( int i=0;i<row;i++){
c=b[i][0];
if(c=='-')
continue;
int seq=1;
for( int j=1; j<col ;j++){
if(b[i][j]!=c)
break;
seq++;
}
if(seq==winlen){
cout<<"win!!"<<endl;
return true;
}
int i=0;
int j=0;
b[i][j];
c=b[0][0];
if(c=='-')
continue;
i++;
j++;
return false;
}
}
int main() {
char board[row][col];
int r1,r2,c1,c2;
char x;
cout<<"main board:"<<endl;
//char board[4][4]={{'-','-','-','-'},{'-','-','-','-'}};
cout<<board;
printboard(board);
for(int i=0;i<4;i++){
cout<<" "<<endl;
for(int j=0;j<4;j++){
cout<<" ";
cout<<board[i][j];
}
}
//char board[4][4]={{'-','-','-','-'},{'-','-','-','-'}};
//cout<<board;
cout<<"-------------------------------------------"<<endl;
cout<<"enter your sing:"<<endl;
cout<<"-------------------------------------------"<<endl;
while(!boardIsFull(board)){
cout<<"empty place:"<<endl;
printremianindex(board);
cout<<"choose number (row and col):(player1)";
cin>>r1;
cin>>c1;
while(occupied(board ,r1 ,c1)){
cout<<"choose number (row and col):(player1)";
cin>>r1;
cin>>c1;
}
board[r1][c1]='x';
cout<<"------------------------------------------"<<endl;
printremianindex(board);
cout<<"------------------------------------------"<<endl;
if(win(board)||boardIsFull(board)){
return 0;
}
while(!boardIsFull(board)){
cout<<"empty place:"<<endl;
printremianindex(board);
cout<<"choose number (row and col):(player2)";
cin>>r2>>c2;
while(occupied(board ,r2 ,c2)){
cout<<"choose number (row and col):";
cin>>r2>>c2;
}
board[r2][c2]='o';
cout<<"------------------------------------------"<<endl;
printremianindex(board);
cout<<"------------------------------------------"<<endl;
if(win(board)){
return 0;
}
}
}
}
//cout<<"no win";
//return 0;
//}