Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/02/2010, 10:20
stiwi222
 
Fecha de Ingreso: noviembre-2009
Mensajes: 186
Antigüedad: 15 años, 3 meses
Puntos: 2
no se como solucionar los errores

bueno, pues casi he terminado mi 3 en raya:

Código C:
Ver original
  1. #include <stdio.h>
  2. #define fila 2
  3. #define columna 2
  4.  
  5. // "1" es el jugador humano, "2" el ordenador, "0" significa que esta vacia
  6.  
  7. int tablero [fila][columna], turno, jugadas=0;
  8.  
  9. int jugada_maquina() //pone la ficha del ordenador en un lugar cualquiera, intentando que sea la mejor posicion
  10. {
  11.     if (tablero [1][1]!= 0)
  12.  
  13.     {
  14.        tablero [1][1]=2
  15.  
  16.     }
  17.  
  18.     else if (tablero [1][0]!= 0|| tablero [1][2]!= 0|| tablero [0][1]!= 0|| tablero [2][1]!= 0)
  19.  
  20.     {
  21.    
  22.        tablero [1][0]=2
  23.  
  24.     }
  25.    
  26.     else if(tablero[0][0]!= 0 ||tablero [0][2]!= 0|| tablero[2][0]!= 0|| tablero [2][2]!= 0)
  27.  
  28.     {
  29.  
  30.        tablero [2][2]=2
  31.  
  32.     }
  33.  
  34.     return 0;
  35. }
  36.  
  37. //Inicializar el tablero todo blanco
  38.  
  39. void inicia_tablero()
  40. {
  41.     int i, j;
  42.  
  43.     for(i=0; i<3; i++)
  44.         for(j=0; j<3; j++) tablero[i] [j] = 0 ;
  45. }
  46.  
  47.  
  48. int jugada_valida(int f, int d) // comprueba si lo que se quiere hacer es valido o no
  49. {
  50.  
  51.      if(f<=3 && d<=3 && tablero[f][d]== 0)
  52.      return 1; // jugada valida
  53.   else
  54.      return 0; // jugada invalida
  55. }
  56.  
  57. void jugada_usuario(int f, int d)
  58. {
  59.  
  60.     if(jugada_valida(f,d)==1)
  61.       tablero[f][d]=1;
  62. }
  63.  
  64. void imprimir()
  65. {
  66.  
  67.  for(int i=0;i<3;i++)
  68.        
  69.         {
  70.  
  71.   printf("\n");
  72.  
  73.   for(int j=0;j<3;j++)
  74.  
  75.     {
  76.  
  77.     printf("",tablero[i][j]);
  78.  
  79.         }
  80.     }
  81. }
  82.  
  83.  
  84. int ganar_perder_empatar();
  85.  
  86. int resultado, i; // tiene 0 si gana, 1 si pierde
  87.  
  88. int conF1,conC1,conD1=0,conOD1=0;
  89. int conF2,conC2,conD2=0,conOD2=0;
  90.  
  91.  
  92.  
  93.  
  94.   for(i=0;i<3;i++)
  95.  
  96. {
  97.     conF1=conC1=conF2=conC2=0;
  98.    
  99.  
  100.     {
  101.  
  102.         if(tablero[i][j]==1)
  103.           conF1++;
  104.         if(tablero[j][i]==1)
  105.          conC1++;
  106.         if(i==j && tablero[i][j]==1)
  107.           conD1++;
  108.         if(i+j==2 && tablero[i][j]==1)
  109.           conOD1++;
  110.  
  111.  
  112.         if(tablero[i][j]==2)
  113.           conF2++;
  114.         if(tablero[j][i]==2)
  115.          conC2++;
  116.         if(i==j && tablero[i][j]==2)
  117.          conD2++;
  118.         if(i+j==2 && tablero[i][j]==2)
  119.          conOD2++;
  120.    
  121.     }
  122.  
  123. if(conF1==3 || conC1==3 || conD1==3 || conF2==3 || conC2==3 || conD2==3 || conOD1==3 || conOD2==3)
  124.      
  125.  resultado=0;
  126.  
  127. }
  128.  
  129. if(jugadas==9)
  130.  
  131.     return 0;
  132.  
  133. else if (resultado==0 && turno==1)
  134.  
  135.     return 1;
  136.  
  137. else if(resultado==0 && turno==2)
  138.  
  139.     return 2;
  140.  
  141. else
  142.     return -1;
  143.  
  144. }
  145.  
  146.  
  147.  
  148. int main()
  149. {
  150. int f, c;
  151.  
  152. printf("elije quien empieza: 1. tu 2. cpu \n");
  153.    
  154. scanf("%i", &turno);
  155.  
  156.  
  157.  
  158. inicia_tablero();
  159.  
  160. do
  161. {
  162.  
  163. jugadas++;
  164.    
  165. if(turno==1)
  166. {
  167. do
  168. {
  169.  
  170.     printf("ingresa la posicion: ");
  171.     scanf("%i, %i", f, c);
  172.  
  173.      if(jugada_valida(f,c)==0)
  174.     {
  175.        
  176.       printf("ahi no puedes");
  177.  
  178.     }
  179.  
  180. while(jugada_valida(f, c)==0);
  181. }
  182. jugada_usuario(f, c);
  183.  
  184.     jugada_maquina();
  185.  
  186.  
  187.     else if(turno==2){
  188.      printf("\n\n");
  189.     printf("\nJugada de CPU:\n");
  190.      jugada_maquina();
  191.     }
  192.      imprimir();
  193.  
  194.  
  195.  
  196.  
  197.       if(ganar_perder_empatar()==1)
  198.         printf("\n\nGano Jugador\n");
  199.       else{
  200.         if(ganar_perder_empatar()==2)
  201.           printf("\n\nGano la CPU\n");
  202.         else
  203.          if(ganar_perder_empatar()==0)
  204.           printf("\n\nPartida Empatada\n");
  205.       }
  206.  
  207. if(turno==1)
  208.       turno=2;
  209.     else
  210.       turno=1;
  211.  
  212. while(ganar_perder_empatar()==-1);
  213.  printf("\n\nPulsa una tecla para salir...\n");
  214.  getchar();
  215.  return 0;
  216.  
  217. }
lo he compilado y me da estos errores:

codigo.cpp: In function `int jugada_maquina()':
codigo.cpp:16: error: syntax error before `}' token
codigo.cpp:24: error: syntax error before `}' token
codigo.cpp:32: error: syntax error before `}' token
codigo.cpp: At global scope:
codigo.cpp:94: error: syntax error before `for'
codigo.cpp:94: error: syntax error before `;' token
codigo.cpp:94: error: syntax error before `++' token
codigo.cpp: In function `int main()':
codigo.cpp:182: error: syntax error before `(' token
codigo.cpp:187: error: syntax error before `else'
codigo.cpp:220: error: syntax error before `if'
codigo.cpp: In function `int main()':
codigo.cpp:240: error: redefinition of `int main()'
codigo.cpp:149: error: `int main()' previously defined here
codigo.cpp:273: error: syntax error before `(' token
codigo.cpp:278: error: syntax error before `else'
codigo.cpp:310: error: syntax error at end of input

codigo.o - 14 error(s), 0 warning(s)


pero no se cuales son

¿una ultima ayudita?

gracias

Última edición por stiwi222; 20/02/2010 a las 10:26