Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #ifndef stangry
  5. struct pole
  6. {
  7. int wymiar;
  8. int linia;
  9. int elementy[3][3];
  10. int i;
  11. int player;
  12. };
  13. struct kord
  14. {
  15. int x;
  16. int y;
  17. };
  18. struct puste
  19. {
  20. struct kord x;
  21. struct puste *nast;
  22. };
  23. struct pole odczyt(char* plikk)
  24. {
  25. FILE *plik = fopen(plikk, "r");
  26. struct pole m;
  27. //m.elementy = malloc(16 * sizeof(struct matrix));
  28. fscanf(plik, "%d %d %d %d", &m.wymiar, &m.i, &m.player);
  29. for (int i = 0; i < m.wymiar; i++)
  30. {
  31. for (int j = 0; j < m.wymiar; j++)
  32. {
  33. fscanf(plik, "%d", &m.elementy[i][j]);
  34. }
  35. }
  36. fclose(plik);
  37. //for (int i = 0; i < m.wiersze * m.wiersze; i++)
  38. //free(m.elementy);
  39. return m;
  40. }
  41. struct puste tworz(struct pole m)
  42. {
  43. struct kord pocz={.x=0,.y=0};
  44. struct puste *glowa=dodaj(pocz, NULL);
  45. for (int i = 0; i < m.wymiar; i++)
  46. {
  47. for (int j = 0; j < m.wymiar; j++)
  48. {
  49. if(m.elementy[i][j]==0)
  50. {
  51. struct kord zero={.x=i, .y=j};
  52. dodaj(zero, glowa);
  53. }
  54. }
  55. }
  56. }
  57. struct puste* dodaj (struct kord x, struct puste *glowa)
  58. {
  59. struct puste *ogon = calloc (1, sizeof(struct puste));
  60. (*ogon).x = x;
  61. (*ogon).nast = NULL;
  62. if (glowa)
  63. {
  64. while ((*glowa).nast)
  65. glowa = (*glowa).nast;
  66. (*glowa).nast = ogon;
  67. }
  68. return ogon;
  69. }
  70. void zniszczliste (struct puste *glowa)
  71. {
  72. if ((*glowa).nast)
  73. zniszczliste ((*glowa).nast);
  74. free (glowa);
  75. }
  76.  
  77. struct puste* zniszczelement (struct puste *head, struct puste *wybrane)
  78. {
  79. if (head == wybrane) //pierwszy
  80. {
  81. struct puste *p = head;
  82. if (p)
  83. {
  84. head = (*p).nast;
  85. free (p);
  86. }
  87. return head;
  88. }
  89. else
  90. {
  91. if(wybrane == NULL) //ostatni
  92. {
  93. struct puste* p=head;
  94. while (p->nast->nast)
  95. {
  96. p = p->nast;
  97. }
  98. free(p->nast);
  99. p->nast=NULL;
  100. return head;
  101. }
  102. else
  103. {
  104. struct puste* p=head;
  105. while(p ->nast != wybrane)
  106. p = p->nast;
  107. p->nast = p->nast->nast;
  108. free(wybrane);
  109. return p;
  110. }
  111. }
  112. }
  113. void zwolnij(struct puste* ptr)
  114. {
  115. if(ptr->nast)
  116. zwolnij(ptr->nast);
  117. free(ptr);
  118. }
  119. #define stangry
  120. #endif
  121.  
  122.  
  123.  
  124. #include <stangry.h>
  125. #ifndef ocena
  126.  
  127. int check(struct pole m, int a, struct kord n, int i)
  128. {
  129. if (m.elementy[n.x][n.y] == a && m.elementy[n.x + 1][n.y])
  130. {
  131. if(i==m.linia-1)
  132. return 100000*a;
  133. n.x+=1, i++;
  134. check(m,a,n,i);
  135. }
  136. if (m.elementy[n.x][n.y] == a && m.elementy[n.x][n.y+1] == a)
  137. {
  138. if(i==m.linia-1)
  139. return 100000*a;
  140. n.y+=1, i++;
  141. check(m,a,n,i);
  142. }
  143. if (m.elementy[n.x][n.y] == a&&m.elementy[n.x+1][n.y+1] == a)
  144. {
  145. if(i==m.linia-1)
  146. return 100000*a;
  147. n.x+=1, n.y+=1, i++;
  148. check(m,a,n,i);
  149. }
  150. if (m.elementy[n.x][n.y] == a &&m.elementy[n.x-1][n.y+1] == a)
  151. {
  152. if(i==m.linia-1)
  153. return 100000*a;
  154. n.x+=-1,n.y+=1, i++;
  155. check(m,a,n,i);
  156. }
  157. else
  158. {
  159. return 0;
  160. }
  161. }
  162. #define ocena
  163. #endif
  164.  
  165.  
  166.  
  167. #include <ocena.h>
  168. // wzór na ilość rozwiązan z 3 w linii 4(n-2)(n-1)
  169.  
  170. struct pole tablica(struct pole n);
  171. char znak(int i);
  172.  
  173.  
  174. int game(struct pole m, char* save);
  175.  
  176. int main()
  177. {
  178.  
  179. }
  180.  
  181. struct pole tablica(struct pole m) {
  182. for (int b = 0; b < m.wymiar; b++)
  183. printf(" %4d ", b + 1);
  184. printf("\n");
  185. for (int a = 0; a < m.wymiar; a++)
  186. {
  187. for (int y = 0; y < m.wymiar; y++)
  188. printf(" '%c' |", znak(m.elementy[a][y]));
  189. printf("\t %c \n ", 65 + a);
  190. for (int y = 0; y < m.wymiar; y++)
  191. printf("----+-");
  192. printf("\n");
  193. }
  194. return m;
  195. };
  196.  
  197. char znak(int i)
  198. {
  199. switch (i)
  200. {
  201. case 2:
  202. return 'X';
  203. case 0:
  204. return ' ';
  205. case 1:
  206. return 'O';
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement