Académique Documents
Professionnel Documents
Culture Documents
h>
}
if((tateti[1][0] == 1 && tateti[1][1] == 1 && tateti[1][2] == 1) || (tateti[1]
[0] ==2 && tateti[1][1]== 2 &&tateti[1][2]==2))
{
gano=1;
}
}
if((tateti[0][1] == 1 && tateti[1][1] == 1 &&tateti[2][1] ==1) || (tateti[0][1]
== 2 && tateti[1][1]== 2 &&tateti[2][1]==2))
{
gano=1;
}
return gano;
}
int ValidarDiagonales()
{
int gano;
if((tateti[0][0] == 1 && tateti[1][1] == 1 && tateti[2][2] == 1) || (tateti[0]
[0] == 2 && tateti[1][1] == 2 && tateti[2][2] == 2))
{
gano=1;
}
if((tateti[0][2] == 1 && tateti[1][1] == 1 &&tateti[2][0] == 1) || (tateti[0]
[2] == 2 && tateti[1][1] == 2 &&tateti[2][0] == 2))
{
gano=1;
return gano;
}
int terminoJuego()
{
if ( (ValidarColumnas()== 1) || (ValidarFilas()==1) ||
(ValidarDiagonales()==1))
termino=1;
return termino;
}
//Inicio de aplicacion
int main()
{
int i =0;
//Jugador es 1 o 2
int jugador = 2;
//pos es el entero que ingresa el usuario
int pos=0;
int intentar = 1;
//Inicializa matriz
for(int f = 0; f<3; f++ )
{
for (int c=0; c<3; c++)
{
tateti[f][c]=0;
}
}
//Cambio de turno
if(jugador == 1)
{
jugador = 2;
}
else
{
jugador=1;
}
//Muestra matriz
for(int f = 0; f<3; f++ )
{
for (int c=0; c<3; c++)
{
printf(" %d", tateti[f][c]);
}
printf("\n");
}
//Ingrese posici�n
do
{
printf("Ingrese la posicion jugador %d\n", jugador);
scanf("%d",&pos);
}
while ( !(pos>=1 && pos <=9) );
intentar = 1;
while (intentar == 1)
{
intentar = 0;
intentar = 1;
do
{
printf("Ingrese la posicion jugador %d\n", jugador);
scanf("%d",&pos);
}
while ( !(pos>=1 && pos <=9) );
}
}
i++;
}
while ((terminoJuego()==0) && (i<cantmaxJugadas));
if (terminoJuego())
{
printf("Gano %d", jugador);
}
else
{
printf("Empate");
}
return 0;
}