Piezas.cpp
/**
 * Returns which Piece has won, if there is a winner, Invalid if the game
 * is not over, or Blank if the board is filled and no one has won ("tie").
 * For a game to be over, all locations on the board must be filled with X's 
 * and O's (i.e. no remaining Blank spaces). The winner is which player has
 * the most adjacent pieces in a single line. Lines can go either vertically
 * or horizontally. If both X's and O's have the same max number of pieces in a
 * line, it is a tie.
 **/
Returns which Piece has won, if there is a winner, Invalid if the game
is not over, or Blank if the board is filled and no one has won ("tie").
For a game to be over, all locations on the board must be filled with X's
and O's . The winner is which player has
the most adjacent pieces in a single line. Lines can go either vertically
or horizontally. If both X's and O's have the same max number of pieces in a
line, it is a tie.
Returns which Piece has won if there is a winner Invalid if the game is not over or Blank if the board is filled and no one has won ( " tie " ) . For a game to be over all locations on the board must be filled with X ' s and O ' s . The winner is which player has the most adjacent pieces in a single line . Lines can go either vertically or horizontally . If both X ' s and O ' s have the same max number of pieces in a line it is a tie .
Piece Piezas::gameState()
{
	int x_longest = 0;
	int o_longest=0;
	int x_score=0;
	int o_score=0;
	for(int i=0; i< BOARD_ROWS; i++)
	{
		for( int j =0; j < BOARD_COLS; j++)
		{
			if(board[i][j] == Blank)
				return Invalid;
		}
	}
for(int i = 0; i<3; ++i)
{
	for(int j =0; j < BOARD_COLS; ++j)
	{
		if(board[i][j] == X)
			x_longest =1;
		else if(board[i][j] == O)
			o_longest =1;
	}
}
for(int i = 0; i<3; ++i)
{
	for(int j =0; j < BOARD_COLS; ++j)
	{
		if(board[i][j] == pieceAt(i,j+1)|| board[i][j] == pieceAt(i,j-1)|| board[i][j] == pieceAt(i+1,j)|| board[i][j] == pieceAt(i-1,j) )
		{
		if(board[i][j] == X)
			x_longest =2;
		else if(board[i][j] == O)
			o_longest =2;
	}
	}
}
for(int j = 0; j <4; ++j)
{
	if(board[0][j] == board[1][j]&& board[0][j] == board[2][j])
	{
		if (board[0][j] ==X) 
			x_longest =3;
		else 
			o_longest =3;
	}
}
for(int i = 0; i <3; ++i)
{
	if((board[i][0] == board[i][1]&& board[i][0] == board[i][2]) ||( board[i][1] == board[i][2] && board[i][1]== board[i][3]))
	{
		if (board[i][0] ==X) 
			x_longest =3;
		else 
			o_longest =3;
	}
}
for(int i = 0; i <3; ++i)
{
	if(board[i][0] == board[i][1]&&board[i][0] == board[i][2]&&board[i][0] == board[i][3])
	{
		if (board[i][0] ==X) 
			x_longest =4;
		else 
			o_longest =4;
	}
}
if(x_longest == o_longest)
	return Blank;
else if(x_longest > o_longest)
	return X;
	else
	return O;
	}
Piece Piezas :: gameState ( ) { int x_longest = 0 ; int o_longest = 0 ; int x_score = 0 ; int o_score = 0 ; for ( int i = 0 ; i < BOARD_ROWS ; i ++ ) { for ( int j = 0 ; j < BOARD_COLS ; j ++ ) { if ( board [ i ] [ j ] == Blank ) return Invalid ; } } for ( int i = 0 ; i < 3 ; ++ i ) { for ( int j = 0 ; j < BOARD_COLS ; ++ j ) { if ( board [ i ] [ j ] == X ) x_longest = 1 ; else if ( board [ i ] [ j ] == O ) o_longest = 1 ; } } for ( int i = 0 ; i < 3 ; ++ i ) { for ( int j = 0 ; j < BOARD_COLS ; ++ j ) { if ( board [ i ] [ j ] == pieceAt ( i , j + 1 ) || board [ i ] [ j ] == pieceAt ( i , j - 1 ) || board [ i ] [ j ] == pieceAt ( i + 1 , j ) || board [ i ] [ j ] == pieceAt ( i - 1 , j ) ) { if ( board [ i ] [ j ] == X ) x_longest = 2 ; else if ( board [ i ] [ j ] == O ) o_longest = 2 ; } } } for ( int j = 0 ; j < 4 ; ++ j ) { if ( board [ 0 ] [ j ] == board [ 1 ] [ j ] && board [ 0 ] [ j ] == board [ 2 ] [ j ] ) { if ( board [ 0 ] [ j ] == X ) x_longest = 3 ; else o_longest = 3 ; } } for ( int i = 0 ; i < 3 ; ++ i ) { if ( ( board [ i ] [ 0 ] == board [ i ] [ 1 ] && board [ i ] [ 0 ] == board [ i ] [ 2 ] ) || ( board [ i ] [ 1 ] == board [ i ] [ 2 ] && board [ i ] [ 1 ] == board [ i ] [ 3 ] ) ) { if ( board [ i ] [ 0 ] == X ) x_longest = 3 ; else o_longest = 3 ; } } for ( int i = 0 ; i < 3 ; ++ i ) { if ( board [ i ] [ 0 ] == board [ i ] [ 1 ] && board [ i ] [ 0 ] == board [ i ] [ 2 ] && board [ i ] [ 0 ] == board [ i ] [ 3 ] ) { if ( board [ i ] [ 0 ] == X ) x_longest = 4 ; else o_longest = 4 ; } } if ( x_longest == o_longest ) return Blank ; else if ( x_longest > o_longest ) return X ; else return O ; }
Returns which Piece has won, if there is a winner, Invalid if the game
 is not over, or Blank if the board is filled and no one has won ("tie").
Returns which Piece has won if there is a winner Invalid if the game is not over or Blank if the board is filled and no one has won ( " tie " ) .
/*
	   for(int i =0; i < BOARD_ROWS; i++)
	   {
	   for(int j =0; j < BOARD_COLS; ++j)
	   {

	   int num=j;
	   while(num-1 >0 )
	   {
	   if( pieceAt(i,num-1) == pieceAt(i,j))
	   {
	   if(pieceAt(i,j) == X)
	   ++x_score;
	   else
	   ++o_score;
	   }

	   num--;
	   }

	   num=j;
	   while(num+1 <4 )
	   {
	   if (pieceAt(i,num+1) == pieceAt(i,j))
	   {
	   if(pieceAt(i,j) == X)
	   ++x_score;
	   else
	   ++o_score;
	   }

	   num++;
	   }

	   if(x_score > x_longest)
	   x_longest = x_score;
	   if(o_score > o_longest)
	   o_longest = o_score;
	   x_score = 0;
	   o_score=0;
	   }
	   }




	   for(int i =0; i < BOARD_ROWS; i++)
	   {
	   for(int j =0; j < BOARD_COLS; ++j)
	   {

	   int num=i;
	   while(num-1 >0 )
	   {
	   if( pieceAt(num-1,j) == pieceAt(i,j))
	   {
	   if(pieceAt(i,j) == X)
	   ++x_score;
	   else
	   ++o_score;
	   }

	   num--;
	   }

	   num=i;
	   while(num+1 <3 )
	   {
	   if (pieceAt(num+1,j) == pieceAt(i,j))
	   {
	   if(pieceAt(i,j) == X)
	++x_score;
	   else
		   ++o_score;
}

num++;
}

if(x_score > x_longest)
	x_longest = x_score;
if(o_score > o_longest)
	o_longest = o_score;
	x_score=0;
	o_score=0;
	}
}

*/ //for length1 //for length2 //for length3 //for length4 