NoNameCracksInc

C tic-tac-toe

Oct 10th, 2016
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4.  
  5. typedef struct
  6. {
  7.     int starting_user;
  8.     bool firststep;
  9.     bool rnd;
  10. }play_data;
  11.  
  12. typedef struct
  13. {
  14.     int *array;
  15.     int size;
  16.     int used;
  17. }Array;
  18.  
  19. void init(Array *a,int initsize)
  20. {
  21.     a->array=(int*)malloc(sizeof(int)*initsize);
  22.     a->used=0;
  23.     a->size=initsize;
  24. }
  25.  
  26. void insert(Array *a,int value)
  27. {
  28.     if(a->size==a->used)
  29.     {
  30.         a->size *= 2;
  31.         a->array = realloc(a->array,sizeof(int)*a->size);
  32.     }
  33.     a->array[a->used++]=value;
  34. }
  35.  
  36. int main(int argc, char* argv[])
  37. {
  38.     play_data pd;
  39.     Array plg;
  40.     char *play[10];
  41.  
  42.     decide_player(&pd,argv[1]);
  43.   init(&plg,9);
  44.  
  45.     if(pd.starting_user==1&&pd.firststep != true){useraction();pd.firststep=true;}
  46.  
  47.    while(true)
  48.    {
  49.       insert(&plg,useraction());
  50.       insert(&plg,robotaction(&plg));
  51.    }
  52.  
  53.   return 0;
  54. }
  55.  
  56. int useraction()
  57. {
  58.     int num;
  59.   scanf("%i",num);
  60.   return num;
  61. }
  62.  
  63. int robotaction(Array *a)
  64. {
  65.     for(int c=0;c<=3;c++)
  66.     {
  67.         printf("%i",c);
  68.     }
  69.     return 0;
  70. }
  71.  
  72. int random()
  73. {
  74.     srand(time(NULL));
  75.     int r = ( rand() % 9 ) + 1;
  76.     return r;
  77. }
  78.  
  79.  
  80. void decide_player(play_data *pd, char *arg)
  81. {
  82.     pd->starting_user = (strcmp(arg,"h1")==0) ? 1 : 2;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment