//2  player ok

#include"c:\tc30\marathan\c.cpp"

int check_row(int,int,int);
int check_column(int,int,int);

int check(int no,int row,int col,int color)
{
 int other;
 if(no==1)
  other=2;
 else
  other=1;
 int i,j;

 i=row+1;//upper moves(loops down)              only row
 do
 {
  i=i+1;
 }while(arr[i][col]==other&&i<18);
 if(arr[i][col]==no)
 {
  for(j=row+1;j<i;j++)
  {
   arr[j][col]=no;
   draw_circle(j,col,color);
  }
 }

 i=row-1;
 do
 {
  i=i-1;
 }while(arr[i][col]==other&&i>0);
 if(arr[i][col]==no)
 {
  for(j=row-1;j>i;j--)
  {
   arr[j][col]=no;
   draw_circle(j,col,color);
  }
 }
///////////////////column iteration
 i=col+1;
 do
 {
  i=i+1;
 }while(arr[row][i]==other&&i<18);
 if(arr[row][i]==no)
 {
  for(j=col+1;j<i;j++)
  {
   arr[row][j]=no;
   draw_circle(row,j,color);
  }
 }

 i=col-1;
 do
 {
  i=i-1;
 }while(arr[row][i]==other&&i>0);
 if(arr[row][i]==no)
 {
  for(j=col-1;j>i;j--)
  {
   arr[row][j]=no;
   draw_circle(row,j,color);
  }
 }

}

void main()
{
 initialize();
 draw_all();

 int i,j;
 for(i=1;i<19;i++)
  for(j=1;j<19;j++)
   arr[i][j]=0;

 int row,col,temp;
 row=1;
 col=7;

 int cc;

 while(1)
 {
  for(j=0;j<2;j++)//j=0 white-----------1
  {               // j=1 yellow----------2
   display_result();
   cc=14+j;
   do
   {
    setcolor(getbkcolor());
    settextstyle(1,0,1);
    if(j==0)
     outtextxy(480,400,"PLAYER 2");
    else
     outtextxy(480,400,"PLAYER 1");

    setcolor(14+j);
    if(j==0)
     outtextxy(480,400,"PLAYER 1");
    else
     outtextxy(480,400,"PLAYER 2");

    temp=move(row,col);

    row=temp/19;
    col=temp%19;

   }while(arr[row][col]!=0);
   arr[row][col]=1+j;

   draw_circle(row,col,cc);

   //////////j=0 1 to win
   if(j==0)
   {
    check(2,row,col,YELLOW);
    check(1,row,col,WHITE);
   }
   else
   {
    check(1,row,col,WHITE);
    check(2,row,col,YELLOW);
   }
   //check(j+1,row,col);


   /* if(j==0)
    {
     check_row(2,row,col);
     check_row(1,row,col);
     check_column(2,row,col);
     check_column(1,row,col);
    }
    else
    {
    check_row(1,row,col);
    check_row(2,row,col);
    check_column(1,row,col);
    check_column(2,row,col);
    }*/
//   }while(p1r!=0||p2r!=0);
  }
 }


// getch();
// closegraph();

}

/*
check_column included dl occurs

     2121
     1121
     1121
     in row check in 2nd row 2is set to 1
     now in column check it is set to 1 & so on

     multiple checks must as one can lead to other.


     if only once check considered than which one first r or c
*/
	      /*
int check_row(int a,int b,int c)
{
 check(a,b,c,1);
}
int check_column(int a,int b,int c)
{
 check(a,b,c,0);
}               */