Dev - C++ - Urgente!! Recorrer matrices

 
Vista:

Urgente!! Recorrer matrices

Publicado por Gaby (1 intervención) el 15/02/2014 22:36:35
Lo siento amigo no sabía como poner el código y lo había escrito pero aquí te lo mando como me dijiste, ya le hice las modificaciones que me acabas de decir pero no me busca bien los números repetido en horizontal y no sé si las condiciones que puse están bien, le puse que sea dif de cero por que en algunas ocasiones me contaba una fila cero que no sabía de dónde salía...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define MAXFIL 9
#define MAXCOL 9
 
 
int buscarCaramelosVertical (int matriz[MAXFIL][MAXCOL],int puntosN1);
int buscarCaramelosHorizontal (int matriz[MAXFIL][MAXCOL],int puntosN1);
 
 
 
int buscarCaramelosVertical (int matriz[MAXFIL][MAXCOL],int puntosN1){
	printf("\n\n------------------>> BUSQUEDA VERTICAL:\n\n");
	int contador=1;
	int i,j;
 
	for (j=0;j<MAXCOL;j++){
		for (i=0;i<MAXFIL-1;i++){
		        if (matriz[i][j]==matriz[i+1][j]){
		        	contador++;
		        }
 
				else if (matriz[i][j]!=matriz[i+1][j]){
						contador=1;
				}
 
				if (contador==3 && i<MAXFIL-2 && i!=0 && (matriz[i+1][j]==matriz[i+2][j])){
					printf("\n\n ENCONTRO 4 CARAMELOS EN LA COLUMNA: %d  DESDE LA FILA %d A LA FILA %d \n",j+1,i,i+3);
					puntosN1=puntosN1+7;
					matriz[i][j]=1+(rand()%5);
            		matriz[i+1][j]=1+(rand()%5);
            		matriz[i+2][j]=1+(rand()%5);
            		matriz[i+3][j]=1+(rand()%5);
 
		        }
 
		        else if (contador==3 && i<MAXFIL-1 && i!=0 && (matriz[i][j]==matriz[i+1][j]) ){
                	printf("\n\n ENCONTRO 3 CARAMELOS EN LA COLUMNA: %d  DESDE LA FILA %d A LA FILA %d \n",j+1,i,i+2);
                	puntosN1=puntosN1+5;
                	matriz[i][j]=1+(rand()%5);
            		matriz[i+1][j]=1+(rand()%5);
            		matriz[i+2][j]=1+(rand()%5);
 
				}
 
 
		}
	}
	return puntosN1;
}
 
 
int buscarCaramelosHorizontal (int matriz[MAXFIL][MAXCOL],int puntosN1){
	printf("\n\n------------------>>BUSQUEDA HORIZONTAL:\n\n");
	int contador=1;
	int i,j;
	for(i=0;i<MAXFIL;i++){
		for(j=0;j<MAXCOL-1;j++){
 
			if (matriz[i][j]==matriz[i][j+1])
            contador=contador+1;
 
 
			if (matriz[i][j]!=matriz[i][j+1])
            contador=1;
 
 
            if (contador==3 && j<MAXCOL-2 && j!=0 && (matriz[i][j+1]==matriz[i][j+2])){
 
            	printf("\n\n ENCONTRO 4 CARAMELOS DESDE LA COLUMNA: %d  HASTA LA COLUMNA %d EN LA FILA %d \n",j,j+3,i+1);
            	puntosN1=puntosN1+7;
            	matriz[i][j]=1+(rand()%5);
            	matriz[i][j+1]=1+(rand()%5);
            	matriz[i][j+2]=1+(rand()%5);
            	matriz[i][j+3]=1+(rand()%5);
 
            }
 
            else if (contador==3 && j<MAXCOL-1 && j!=0){
	           	printf("\n\n ENCONTRO 3 CARAMELOS DESDE LA COLUMNA: %d  HASTA LA COLUMNA %d EN LA FILA %d \n",j,j+2,i+1);
                puntosN1=puntosN1+5;
				matriz[i][j]=1+(rand()%5);
            	matriz[i][j+1]=1+(rand()%5);
            	matriz[i][j+2]=1+(rand()%5);
 
            }
		}
	}
 
return puntosN1;
}
 
 
 
 
int main(){
	system ("COLOR A" );
	printf("\n\n==================|| INICIANDO JUEGO ||==================\n\n");
	printf(":::::::::::::::::::::::DIVIERTASE:::::::::::::::::::::::\n\n");
	system("pause");
	system("cls");
	int finalJuego=0;
	int turnoN1=0;
	while (finalJuego!=1){
		printf("\n\n\t\t.....|| Cargando Colores ||....\n\n\n\n");
		int i,j;
		srand(time(NULL));
		int matriz[MAXFIL][MAXCOL];
		for(i=0;i<MAXFIL;i++){
			for(j=0;j<MAXCOL;j++){
				matriz[i][j]=1+(rand()%5);
			}
		}
		tablero (matriz);
		while(turnoN1!=40){
			int puntosN1=0;
			int pto;
			while (turnoN1!=40){
					printf("\n\n=============================================================================\n\n\n");
					printf("\n\n\t\t.....|| BUSQUEDA DE COLORES ||....\n\n\n\n");
 
					pto=puntosN1;
					puntosN1=buscarCaramelosVertical (matriz,puntosN1)+buscarCaramelosHorizontal(matriz,puntosN1);
					puntosN1=puntosN1-pto;
 
					 if(pto!=puntosN1){
 
						printf("\n\n------------------->>Usted posee %d puntos \n\n",puntosN1);
						turnoN1++;
						printf("------------------->>Usted se encuentra en el TURNO %d \n\n",turnoN1);
 
						printf("\n\n==============================================================================\n\n\n");
 
						printf("\n\n\t\t.....|| BAJANDO COLORES ||....\n\n\n\n");
						tablero (matriz);
					}
 
 
					else {
						printf("\n\n=============================================================================\n\n\n");
						printf("::::::::::::::::::::::::::::NO HAY COMBINACIONES::::::::::::::::::::::::::::\n\n");
						turnoN1++;
						printf("------------------->>Usted se encuentra en el TURNO %d \n\n",turnoN1);
						printf("\n\n\n::::::::::::::::::::::::::::REVOLVIENDO COLORES::::::::::::::::::::::::::::\n\n");
						printf("\n\n=============================================================================\n\n\n");
						for(i=0;i<MAXFIL;i++){
							for(j=0;j<MAXCOL;j++){
								matriz[i][j]=1+(rand()%5);
							}
						}
						tablero (matriz);
 
					}
 
			}
 
 
 
 
		}
 
 
	}
return 0;
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder