Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef stangry
- struct pole
- {
- int wymiar;
- int linia;
- int elementy[3][3];
- int i;
- int player;
- };
- struct kord
- {
- int x;
- int y;
- };
- struct puste
- {
- struct kord x;
- struct puste *nast;
- };
- struct pole odczyt(char* plikk)
- {
- FILE *plik = fopen(plikk, "r");
- struct pole m;
- //m.elementy = malloc(16 * sizeof(struct matrix));
- fscanf(plik, "%d %d %d %d", &m.wymiar, &m.i, &m.player);
- for (int i = 0; i < m.wymiar; i++)
- {
- for (int j = 0; j < m.wymiar; j++)
- {
- fscanf(plik, "%d", &m.elementy[i][j]);
- }
- }
- fclose(plik);
- //for (int i = 0; i < m.wiersze * m.wiersze; i++)
- //free(m.elementy);
- return m;
- }
- struct puste tworz(struct pole m)
- {
- struct kord pocz={.x=0,.y=0};
- struct puste *glowa=dodaj(pocz, NULL);
- for (int i = 0; i < m.wymiar; i++)
- {
- for (int j = 0; j < m.wymiar; j++)
- {
- if(m.elementy[i][j]==0)
- {
- struct kord zero={.x=i, .y=j};
- dodaj(zero, glowa);
- }
- }
- }
- }
- struct puste* dodaj (struct kord x, struct puste *glowa)
- {
- struct puste *ogon = calloc (1, sizeof(struct puste));
- (*ogon).x = x;
- (*ogon).nast = NULL;
- if (glowa)
- {
- while ((*glowa).nast)
- glowa = (*glowa).nast;
- (*glowa).nast = ogon;
- }
- return ogon;
- }
- void zniszczliste (struct puste *glowa)
- {
- if ((*glowa).nast)
- zniszczliste ((*glowa).nast);
- free (glowa);
- }
- struct puste* zniszczelement (struct puste *head, struct puste *wybrane)
- {
- if (head == wybrane) //pierwszy
- {
- struct puste *p = head;
- if (p)
- {
- head = (*p).nast;
- free (p);
- }
- return head;
- }
- else
- {
- if(wybrane == NULL) //ostatni
- {
- struct puste* p=head;
- while (p->nast->nast)
- {
- p = p->nast;
- }
- free(p->nast);
- p->nast=NULL;
- return head;
- }
- else
- {
- struct puste* p=head;
- while(p ->nast != wybrane)
- p = p->nast;
- p->nast = p->nast->nast;
- free(wybrane);
- return p;
- }
- }
- }
- void zwolnij(struct puste* ptr)
- {
- if(ptr->nast)
- zwolnij(ptr->nast);
- free(ptr);
- }
- #define stangry
- #endif
- #include <stangry.h>
- #ifndef ocena
- int check(struct pole m, int a, struct kord n, int i)
- {
- if (m.elementy[n.x][n.y] == a && m.elementy[n.x + 1][n.y])
- {
- if(i==m.linia-1)
- return 100000*a;
- n.x+=1, i++;
- check(m,a,n,i);
- }
- if (m.elementy[n.x][n.y] == a && m.elementy[n.x][n.y+1] == a)
- {
- if(i==m.linia-1)
- return 100000*a;
- n.y+=1, i++;
- check(m,a,n,i);
- }
- if (m.elementy[n.x][n.y] == a&&m.elementy[n.x+1][n.y+1] == a)
- {
- if(i==m.linia-1)
- return 100000*a;
- n.x+=1, n.y+=1, i++;
- check(m,a,n,i);
- }
- if (m.elementy[n.x][n.y] == a &&m.elementy[n.x-1][n.y+1] == a)
- {
- if(i==m.linia-1)
- return 100000*a;
- n.x+=-1,n.y+=1, i++;
- check(m,a,n,i);
- }
- else
- {
- return 0;
- }
- }
- #define ocena
- #endif
- #include <ocena.h>
- // wzór na ilość rozwiązan z 3 w linii 4(n-2)(n-1)
- struct pole tablica(struct pole n);
- char znak(int i);
- int game(struct pole m, char* save);
- int main()
- {
- }
- struct pole tablica(struct pole m) {
- for (int b = 0; b < m.wymiar; b++)
- printf(" %4d ", b + 1);
- printf("\n");
- for (int a = 0; a < m.wymiar; a++)
- {
- for (int y = 0; y < m.wymiar; y++)
- printf(" '%c' |", znak(m.elementy[a][y]));
- printf("\t %c \n ", 65 + a);
- for (int y = 0; y < m.wymiar; y++)
- printf("----+-");
- printf("\n");
- }
- return m;
- };
- char znak(int i)
- {
- switch (i)
- {
- case 2:
- return 'X';
- case 0:
- return ' ';
- case 1:
- return 'O';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement