100% encontró este documento útil (1 voto)
610 vistas4 páginas

Tateti

Este documento describe un programa para jugar al juego del tateti (tres en raya). Define una matriz para representar el tablero y funciones para validar si hay ganador por filas, columnas o diagonales. El programa inicializa el tablero, alterna turnos entre jugadores e ingresa sus jugadas. Verifica después de cada jugada si hay un ganador o si se llenó el tablero sin ganador.

Cargado por

Cariito Biscaro
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd
100% encontró este documento útil (1 voto)
610 vistas4 páginas

Tateti

Este documento describe un programa para jugar al juego del tateti (tres en raya). Define una matriz para representar el tablero y funciones para validar si hay ganador por filas, columnas o diagonales. El programa inicializa el tablero, alterna turnos entre jugadores e ingresa sus jugadas. Verifica después de cada jugada si hay un ganador o si se llenó el tablero sin ganador.

Cargado por

Cariito Biscaro
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como TXT, PDF, TXT o lee en línea desde Scribd

#include <stdio.

h>

const int cantmaxJugadas= 9;


int tateti[3][3];

//Funcion de termino juego


int ValidarFilas()
{
int gano;
if((tateti[0][0] == 1 && tateti[0][1] == 1 && tateti[0][2] == 1) || (tateti[0]
[0] == 2 && tateti[0][1] == 2 && tateti[0][2] == 2))
{
gano=1;

}
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[2][0] == 1 && tateti[2][1] == 1 && tateti[2][2] == 1) || (tateti[2]


[0] ==2 && tateti[2][1]== 2 &&tateti[2][3]==2))
{
gano=1;
}
return gano;
}
int ValidarColumnas()
{
int gano;
if((tateti[0][0] ==1 && tateti[1][0]== 1 &&tateti[2][0]==1) || (tateti[0][0]
==2 && tateti[1][0]== 2 &&tateti[2][0]==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;

if((tateti[0][2] == 1 && tateti[1][2] == 1 &&tateti[2][2] == 1) || (tateti[0]


[2] ==2 && tateti[1][2] == 2 &&tateti[2][2] == 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()
{

int termino =0;

//Las funciones validar devuelven 1 si es true o 0 si es false;

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;

}
}

//Fin inicializa matriz


do
{

//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;

//Unicaci�n de la posici�n en el tablero

while (intentar == 1)
{

intentar = 0;

if (pos == 1 & tateti[0][0] == 0)


{
tateti[0][0] = jugador;
}
else if (pos == 2 & tateti[0][1] == 0)
{
tateti[0][1] = jugador;
}
else if (pos == 3 & tateti[0][2] == 0)
{
tateti[0][2] = jugador;
}
else if (pos == 4 & tateti[1][0] == 0)
{
tateti[1][0] = jugador;
}
else if (pos == 5 & tateti[1][1] == 0)
{
tateti[1][1] = jugador;
}
else if (pos == 6 & tateti[1][2] == 0)
{
tateti[1][2] = jugador;
}
else if (pos == 7 & tateti[2][0] == 0)
{
tateti[2][0] = jugador;
}
else if (pos == 8 & tateti[2][1] == 0)
{
tateti[2][1] = jugador;
}
else if (pos == 9 & tateti[2][2] == 0)
{
tateti[2][2] = jugador;
}
else
{

//Si ingreso en un lugar ya tomado, vuelve a ingresar

printf("Vuelva a intentar \n");

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));

//Ver quien gan�

if (terminoJuego())
{
printf("Gano %d", jugador);
}
else
{
printf("Empate");
}

return 0;
}

También podría gustarte