AYUDA URGENTE EN EJERCICIO DE TRES EN LINEA//PUPILO EN APUROS

Iniciado por nelxiton, 25 Junio 2012, 22:04 PM

0 Miembros y 1 Visitante están viendo este tema.

nelxiton

HOLA, TENGO UN PROBLEMA CON RESOLVER ESTE EJERCICIO ...

TRATA SOBRE EL JUEGO TRES EN LINEA...

ME FALTA HALLAR SI GANO DE FORMA VERTICAL Y DE FORMA DIAGONAL IZQUIERDA Y DERECHA

ESPERO QUE ALGUIEN ME PUEDA AYUDAR CON ESTE PROBLEMA LE ESTARIA MUY AGRADECIDO..   :huh:


Código (cpp) [Seleccionar]
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
//declaro matriz
int matriz[3][3];

using namespace System;


//declaro funcion
int verifica_horizontal();

int main(array<System::String ^> ^args)
{

Random r;

//Inicio matriz - por filas
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
matriz[i][j]=0;

//Genero matriz aleatoria
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
matriz[i][j]=r.Next(0,2);

//Mostrar matriz original - por filas
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
printf("%4d",matriz[i][j]);

printf("\n");
}

printf("\n");
printf("\n");
//Mostrar matriz - por filas
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if( matriz[i][j] == 0)
{
printf("O");
}
if( matriz[i][j] == 1)
{
printf("X");
}
}
printf("\n");
}

//Invoco funciones
//int horizontal = verifica_horizontal();

if (verifica_horizontal() == 1)
printf("\n\n\t GANA HORIZONTAL");
else
printf("\n\n\t NO HAY GAANDOR HORIZONTAL");


_getch();
    return 0;
}

//Implemento funcion
int verifica_horizontal()
{
int gana=0;
int contador;

for(int i=0;i<3;i++)
{
contador=0;
for(int j=0;j<3;j++)
{
if(matriz[i][j]==1)
contador++;
}
if( contador == 3 )
{
gana=1;
break;
}
}

return gana;
}