Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5. #include <conio.h>
  6.  
  7.  
  8.  
  9.  
  10.  
  11. void wyczysc (char plansza[3][3])
  12. {
  13.     int i,j;
  14.     for (i=0;i<3;i++)
  15.         for (j=0;j<3;j++)
  16.             plansza[i][j]=' ';
  17.  
  18. }
  19.  
  20.  
  21.  
  22. void wypisz (char plansza[3][3])
  23. {
  24.     system("cls"); // czyśc ekran. Są szybsze sposoby czyszczenia, ale ten jest w miare uniwersalny
  25.  
  26.     printf("[%c][%c][%c]\n",plansza[0][0], plansza[0][1], plansza[0][2]);
  27.     //printf("\n");
  28.     printf("[%c][%c][%c]\n",plansza[1][0], plansza[1][1], plansza[1][2]);
  29.    //printf("\n");
  30.     printf("[%c][%c][%c]\n",plansza[2][0], plansza[2][1], plansza[2][2]);
  31. }
  32.  
  33. int pelna(char plansza[3][3])
  34. {
  35. int i, j;
  36.     for (i=0;i<3;i++)
  37.         for (j=0;j<3;j++)
  38.             if (plansza[i][j] == ' ')
  39.                 return 0;
  40.     return 1;
  41.  
  42. }
  43. void ruch_gracza(char plansza[3][3])
  44. {
  45.     unsigned int i=3, j;
  46.     wypisz(plansza);
  47.     printf("Podaj wiersz i kolumne w ktorej chcesz wstawic krzyzyk\n");
  48.     while ((i>2)||(j>2) || (plansza[i][j]!=' '))
  49.         scanf("%u %u", &i, &j);
  50.     plansza[i][j]='x';
  51. }
  52. /*Funkcja sprawdz sprawdzi:
  53. czy na planszy nie ma trzech takich samych znaków lezacych
  54. w jednej linii (wtedy którys z graczy wygrał),
  55. czy plansza jest juz pełna (wtedy jest remis)*/
  56. char sprawdz(char plansza[3][3])
  57. {
  58. int i;
  59. for (i=0;i<3;i++)
  60. {
  61.     if ( (plansza[i][0]!=' ')
  62.         && (plansza[i][0]==plansza[i][1])
  63.         && (plansza[i][0]==plansza[i][2]))
  64.         return plansza[i][0];
  65.     if ( (plansza[0][i]!=' ')
  66.         &&(plansza[0][i]==plansza[1][i])
  67.         &&(plansza[0][i]==plansza[2][i]) )
  68. return plansza [0][i];
  69.  
  70. } // for
  71.  
  72. if ((plansza[0][0]!=' ')
  73.     && (plansza[0][0]==plansza[1][1])
  74.     && (plansza[0][0]==plansza[2][2]))
  75.     return plansza[0][0];
  76.  
  77. if ((plansza[2][0]!=' ')
  78. &&(plansza[2][0]==plansza[1][1])
  79. &&(plansza[2][0]==plansza[0][2]))
  80. return plansza[2][0];
  81.  
  82.  
  83. if (pelna(plansza)==1)
  84.     return 1;
  85. return 0;
  86.  
  87. } //sprawdz
  88.  
  89. int uzupelnij (char plansza[3][3], char c)
  90. {
  91. int i, j;
  92. for (i=0;i<3;i++)
  93. {
  94.     for (j=0;j<3;j++)
  95.     {
  96.         if ((plansza[i][j]==c) && (plansza[i][(j+1)%3]==c)
  97.             && (plansza[i][(j+2)]%3==' '))
  98.             {
  99.                 plansza[i][(j+2)%3]='o';
  100.                 return 1;
  101.             } // if
  102.         if ((plansza[j][i]==c)&&(plansza[(j+1)%3][i]==c)
  103.             &&(plansza[(j+2)%3][i]==' '))
  104.             {
  105.                 plansza[(j+2)%3][i]='o';
  106.                 return 1;
  107.             } //if
  108.     }// for
  109.         if ((plansza[i][2-i]==c)
  110.         &&(plansza[(i+1)%3][2-(i+1)%3]==c)
  111.         &&(plansza[(i+2)%3][2-(i+2)%3]==' ')){
  112.         plansza[(i+2)%3][2-(i+2)%3]='o';
  113.         return 1;
  114.         }//if
  115.         }//for
  116.  
  117.  
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement