Ayuda con problema de juego de gato
Publicado por Victor Manuel (1 intervención) el 03/12/2020 06:23:13
Hola! Necesito ayuda ya que requiero hacer un juego de gato de 1vs1 y 1vs la computadora. El 1vs1 ya lo tengo pero tengo un poco de problemas con el que es contra la computadora. Gracias!
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
#include <stdio.h>
#include <stdlib.h>
#define MAX_ALEATORIO 10
main()
{
char matriz[3][3], a[9];
int y=0, x=0;
int fila=0, col=0, ganador=0, turno=1, op=0;
printf("¡Vamos a Jugar gato!\n");
for(y=0; y<3; y++)//ciclo que imprimirá el tablero de nuestro juego de gato//
{
for(x=0; x<3; x++)
{
matriz[y][x]=' ';
printf("[%c]", matriz[y][x]);
}
printf("\n");
}
printf("\n Seleccione modo para jugar gato!\n");
printf(" * * * ¡Juego gato! * * * \n");
printf("1.- Jugador vs Jugador\n");
printf("2.- Un solo Jugador \n");
printf("Selecciona una opcion:\n");
scanf("%d", &op);
switch(op)
{
case 1: //opción en la que hace entrar el programa para jugar jugador vs jugador//
{
do{
if(turno%2==1){
do{
printf("\nJugador 1: \n");
printf("\nProporcione las coordenadas donde quiere tirar\n");
printf("Digite el número de la fila: ");
scanf("%d", &fila);
printf("Digite el número de la casilla: ");
scanf("%d", &col);
if(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2){
printf("\n Coordenadas no válidas, pruebe otra vez.\n");
}
}while(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2);
matriz[fila][col]='x';
for(y=0; y<3; y++){
for(x=0; x<3; x++){
printf("[%c]", matriz[y][x]);
}
printf("\n");
}
turno++;
} else if(turno%2==0){
do{
printf("\nJugador 2: \n");
printf("\n Proporcione las coordenadas donde quiere tirar\n");
printf("Digite el número de la fila: ");
scanf("%d", &fila);
printf("Digite el número de la casilla: ");
scanf("%d", &col);
if(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2){
printf("\n Coordenadas no válidas, pruebe otra vez.\n");
}
} while(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2);
matriz[fila][col]='o';
for(y=0; y<3; y++){
for(x=0; x<3; x++){
printf("[%c]", matriz[y][x]);
}
printf("\n");
}
turno++;
}
if(matriz[0][0] == 'x' && matriz[0][0] == matriz[0][1] && matriz[0][0] == matriz[0][2]|| matriz[1][0] == 'x' && matriz[1][0] == matriz[1][1] && matriz[1][0] == matriz[1][2]|| matriz[2][0] == 'x' && matriz[2][0] == matriz[2][1] && matriz[2][0] == matriz[2][2]|| matriz[0][0] == 'x' && matriz[0][0] == matriz[1][0] && matriz[0][0] == matriz[2][0]|| matriz[0][1] == 'x' && matriz[0][1] == matriz[1][1] && matriz[0][1] == matriz[2][1]|| matriz[0][2] == 'x' && matriz[0][2] == matriz[1][2] && matriz[0][2] == matriz[2][2]|| matriz[0][0]=='x' && matriz[0][0]==matriz[1][1] && matriz[0][0]==matriz[2][2]|| matriz[0][2] == 'x' && matriz[0][2] == matriz[1][1] && matriz[0][2] == matriz[2][0])
{
ganador=1;
printf("\n Felicidades! Gano el jugador 1.\n");
}
if(matriz[0][0] == 'o' && matriz[0][0] == matriz[0][1] && matriz[0][0] == matriz[0][2]
|| matriz[1][0] == 'o' && matriz[1][0] == matriz[1][1] && matriz[1][0] == matriz[1][2]
|| matriz[2][0] == 'o' && matriz[2][0] == matriz[2][1] && matriz[2][0] == matriz[2][2]|| matriz[0][0] == 'o' && matriz[0][0] == matriz[1][0] && matriz[0][0] == matriz[2][0]|| matriz[0][1] == 'o' && matriz[0][1] == matriz[1][1] && matriz[0][1] == matriz[2][1]|| matriz[0][2] == 'o' && matriz[0][2] == matriz[1][2] && matriz[0][2] == matriz[2][2]|| matriz[0][0] == 'o' && matriz[0][0] == matriz[1][1] && matriz[0][0] == matriz[2][2]|| matriz[0][2] == 'o' && matriz[0][2] == matriz[1][1] && matriz[0][2] == matriz[2][0]){
ganador=1;
printf("\n Felicidades! Gano el jugador 2.\n");
}
} while(ganador != 1);
}
case 2:
do{
if(turno%2==1){
do{
printf("\nJugador 1: \n");
printf("\nProporcione las coordenadas donde quiere tirar\n");
printf("Digite el número de la fila: ");
scanf("%d", &fila);
printf("Digite el número de la casilla: ");
scanf("%d", &col);
if(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2){
printf("\n Coordenadas no válidas, pruebe otra vez.\n");
}
}while(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2);
matriz[fila][col]='x';
for(y=0; y<3; y++){
for(x=0; x<3; x++){
printf("[%c]", matriz[y][x]);
}
printf("\n");
}
turno++;
}
else if(turno%2==0){
do{
printf("\PC: \n");
for (x=0;x<3;x++) a[x]= rand()%MAX_ALEATORIO;
for (x=0;x<3;x++)
{
printf("%d\n",a[x]);
}
while(matriz[fila][col] == 'x' || matriz[fila][col] == 'o' || fila > 2 || col > 2);
matriz[fila][col]='o';
for(y=0; y<3; y++){
for(x=0; x<3; x++){
printf("[%c]", matriz[y][x]);
}
printf("\n");
turno++;
}
if(matriz[0][0] == 'x' && matriz[0][0] == matriz[0][1] && matriz[0][0] == matriz[0][2]|| matriz[1][0] == 'x' && matriz[1][0] == matriz[1][1] && matriz[1][0] == matriz[1][2]|| matriz[2][0] == 'x' && matriz[2][0] == matriz[2][1] && matriz[2][0] == matriz[2][2]|| matriz[0][0] == 'x' && matriz[0][0] == matriz[1][0] && matriz[0][0] == matriz[2][0]|| matriz[0][1] == 'x' && matriz[0][1] == matriz[1][1] && matriz[0][1] == matriz[2][1]|| matriz[0][2] == 'x' && matriz[0][2] == matriz[1][2] && matriz[0][2] == matriz[2][2]|| matriz[0][0]=='x' && matriz[0][0]==matriz[1][1] && matriz[0][0]==matriz[2][2]|| matriz[0][2] == 'x' && matriz[0][2] == matriz[1][1] && matriz[0][2] == matriz[2][0])
{
ganador=1;
printf("\n Felicidades! Gano el jugador 1.\n");
}
if(matriz[0][0] == 'o' && matriz[0][0] == matriz[0][1] && matriz[0][0] == matriz[0][2]
|| matriz[1][0] == 'o' && matriz[1][0] == matriz[1][1] && matriz[1][0] == matriz[1][2]
|| matriz[2][0] == 'o' && matriz[2][0] == matriz[2][1] && matriz[2][0] == matriz[2][2]|| matriz[0][0] == 'o' && matriz[0][0] == matriz[1][0] && matriz[0][0] == matriz[2][0]|| matriz[0][1] == 'o' && matriz[0][1] == matriz[1][1] && matriz[0][1] == matriz[2][1]|| matriz[0][2] == 'o' && matriz[0][2] == matriz[1][2] && matriz[0][2] == matriz[2][2]|| matriz[0][0] == 'o' && matriz[0][0] == matriz[1][1] && matriz[0][0] == matriz[2][2]|| matriz[0][2] == 'o' && matriz[0][2] == matriz[1][1] && matriz[0][2] == matriz[2][0]){
ganador=1;
printf("\n Yo gane!\n");
}
} while(ganador != 1);
}
break;
}
}
Valora esta pregunta
0