Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define LICZBA_KOLUMN 8
  5. #define LICZBA_WIERSZY 8
  6. char plansza[LICZBA_KOLUMN][LICZBA_WIERSZY+1];
  7. int ostatniWiersz[8];
  8. void zainicjujPlansze()
  9. {
  10. for(int i = 0; i < LICZBA_KOLUMN; i++)
  11. {
  12. for(int j = 0; j < LICZBA_WIERSZY; j++)
  13. {
  14. plansza[i][j] = '-';
  15. }
  16. }
  17. char literka = 'a';
  18. for(int i = 0; i < LICZBA_KOLUMN;i++)
  19. {
  20. plansza[i][LICZBA_WIERSZY] = literka++;
  21. }
  22. for(int i = 0; i < LICZBA_KOLUMN;i++)
  23. {
  24. ostatniWiersz[i] = 8;
  25. }
  26. }
  27. void wyswietlPlansze()
  28. {
  29. for(int j = 0; j < LICZBA_WIERSZY+1; j++)
  30. {
  31. for(int i = 0; i < LICZBA_KOLUMN; i++)
  32. {
  33. printf("%c",plansza[i][j]);
  34. }
  35. puts("");
  36. }
  37. }
  38. int wygranaPionowo()
  39. {
  40. for(int i = 0; i < LICZBA_KOLUMN;i++)
  41. {
  42. for(int j = 0; j < LICZBA_WIERSZY-4;j++)
  43. {
  44. if(plansza[i][j] == '1' && plansza[i][j+1] == '1' && plansza[i][j+2] == '1'
  45. && plansza[i][j+3] == '1' && plansza[i][j+4] == '1')
  46. {
  47. return 1;
  48. }
  49. if(plansza[i][j] == '2' && plansza[i][j+1] == '2' && plansza[i][j+2] == '2'
  50. && plansza[i][j+3] == '2' && plansza[i][j+4] == '2')
  51. {
  52. return 1;
  53. }
  54. }
  55. }
  56.  
  57. return 0;
  58. }
  59. int wygranaPoziomo()
  60. {
  61. for(int j = 0; j < LICZBA_WIERSZY;j++)
  62. {
  63. for(int i = 0; i < LICZBA_KOLUMN-4;i++)
  64. {
  65. if(plansza[i][j] == '1' && plansza[i+1][j] == '1' && plansza[i+2][j] == '1'
  66. && plansza[i+3][j] == '1' && plansza[i+4][j] == '1')
  67. {
  68. return 1;
  69. }
  70. if(plansza[i][j] == '2' && plansza[i+1][j] == '2' && plansza[i+2][j] == '2'
  71. && plansza[i+3][j] == '2' && plansza[i+4][j] == '2')
  72. {
  73. return 1;
  74. }
  75. }
  76. }
  77. return 0;
  78. }
  79. int wygranaSkosnie()
  80. {
  81. for(int i = 0; i < LICZBA_KOLUMN-4;i++)
  82. {
  83. for(int j = 0; j < LICZBA_WIERSZY-4;j++)
  84. {
  85.  
  86. if(plansza[i][j] == '1' && plansza[i+1][j+1] == '1' && plansza[i+2][j+2] == '1'
  87. && plansza[i+3][j+3] == '1' && plansza[i+4][j+4] == '1')
  88. {
  89. return 1;
  90. }
  91. if(plansza[i][j] == '2' && plansza[i+1][j+1] == '2' && plansza[i+2][j+2] == '2'
  92. && plansza[i+3][j+3] == '2' && plansza[i+4][j+4] == '2')
  93. {
  94. return 1;
  95. }
  96. }
  97. }
  98. for(int i = LICZBA_KOLUMN-1; i > 3;i--)
  99. {
  100. for(int j = 0; j < LICZBA_WIERSZY-4;j++)
  101. {
  102.  
  103. if(plansza[i][j] == '1' && plansza[i-1][j+1] == '1' && plansza[i-2][j+2] == '1'
  104. && plansza[i-3][j+3] == '1' && plansza[i-4][j+4] == '1')
  105. {
  106. return 1;
  107. }
  108. if(plansza[i][j] == '2' && plansza[i-1][j+1] == '2' && plansza[i-2][j+2] == '2'
  109. && plansza[i-3][j+3] == '2' && plansza[i-4][j+4] == '2')
  110. {
  111. return 1;
  112. }
  113. }
  114. }
  115. return 0;
  116. }
  117. int wczytajDane()
  118. {
  119. char wejscie;
  120. char temp[2];
  121. int kolumna;
  122. int flag =0;
  123. do
  124. {
  125. flag = scanf("%s",temp);
  126. if(flag == EOF)
  127. exit(0);
  128. if((int)strlen(temp)!=1)
  129. {
  130. continue;
  131. }
  132. wejscie = temp[0];
  133. if(wejscie == '=')
  134. exit(0);
  135. kolumna = wejscie - 97;
  136. }while(kolumna < 0 || kolumna > 7 || ostatniWiersz[kolumna] == 0);
  137. return kolumna;
  138. }
  139. void uaktualnijPlansze(int kolumna, int czyTuraPierwszego)
  140. {
  141. ostatniWiersz[kolumna]--;
  142. if(czyTuraPierwszego)
  143. {
  144.  
  145. plansza[kolumna][ostatniWiersz[kolumna]] = '1';
  146. }
  147. else
  148. {
  149. plansza[kolumna][ostatniWiersz[kolumna]] = '2';
  150. }
  151.  
  152. }
  153. int main()
  154. {
  155. zainicjujPlansze();
  156. int kolumna;
  157. int czyTuraPierwszego = 1;
  158. while(1)
  159. {
  160. wyswietlPlansze();
  161. kolumna = wczytajDane();
  162. uaktualnijPlansze(kolumna,czyTuraPierwszego);
  163. czyTuraPierwszego = !czyTuraPierwszego;
  164. if(wygranaPionowo() || wygranaPoziomo() || wygranaSkosnie())
  165. {
  166. wyswietlPlansze();
  167. break;
  168. }
  169.  
  170. }
  171. return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement