Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.35 KB | None | 0 0
  1. #include "Functions.h"
  2.  
  3. int main()
  4. {
  5.  
  6. int remaining_lines,max_r,max_c;
  7. int grid[50][50];
  8.  
  9. init(&max_r, &max_c, &remaining_lines);
  10.  
  11. for(int i=0;i<max_r;i++)
  12. for(int j=0;j<max_c;j++)
  13. {
  14. grid[i][j]=0;
  15. }
  16.  
  17. for(int i=0;i<12||i==12;i++)
  18. { one.turn=1;
  19. while(one.turn==1)
  20. {
  21. printf("it's %s 's turn\n", one.name);
  22. grid_move(grid,&max_r,&max_c,&remaining_lines);
  23. printf("\n\n player 1 score :%d\t\t player 2 score :%d\nplayer 1 remaining moves:%d\t\t player 2 remaining moves:%d\nremaining lines : %d\n\n",one.score,two.score,one.remainingmoves,two.remainingmoves,remaining_lines);
  24. one.turn--;
  25.  
  26. }
  27.  
  28. two.turn=1;
  29. while(two.turn==1)
  30. {
  31. printf("\n it's %s 's turn\n", two.name);
  32. grid_move(grid,&max_r,&max_c,&remaining_lines);
  33. printf("\n\n player 1 score :%d\t\t player 2 score :%d\nplayer 1 remaining moves:%d\t\t player 2 remaining moves:%d\nremaining lines : %d\n\n",one.score,two.score,one.remainingmoves,two.remainingmoves,remaining_lines);
  34. printf("%d",two.turn);
  35. two.turn--;
  36.  
  37. }
  38.  
  39. }
  40.  
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. #include "functions.h"
  49.  
  50.  
  51.  
  52. void init (int *max_r,int *max_c,int *remaining_lines)
  53. {
  54.  
  55. int menu;
  56.  
  57. printf("\t\t\t\t\t\tDots and Boxes\n\n\n\n\n");
  58. printf("\t\t\t\t 1-start game\n\n\t\t\t\t2-load game\n\n\t\t\t\t3-top 10 player\n\n\t\t\t\t 4-exit \n\n");
  59.  
  60. scanf("%d",&menu);getchar();
  61. while(menu!=1&&menu!=2&&menu!=3&&menu!=4)
  62. {printf("please try again typing your choice correctly\a\n");
  63. scanf("%d",&menu);getchar();
  64. }
  65.  
  66. if(menu==1)
  67. {
  68.  
  69. int mode1,mode2;
  70.  
  71. printf("choose \n1-one player \t\t2-two player\n");
  72. scanf("%d",&mode2);getchar();
  73. while(mode2!=1&&mode2!=2)
  74. {printf("please try again typing your choice correctly\a\n");
  75. scanf("%d",&mode2);getchar();
  76. }
  77. if(mode2==2)
  78. {
  79. printf("player 1 name: \n");
  80. scanf("\n");getchar();
  81. fgets(one.name,100,stdin);
  82. *one.name=strtok(one.name,"\n");
  83. printf("player 2 name: \n");
  84. fgets(two.name,100,stdin);
  85. *two.name=strtok(two.name,"\n");
  86. }
  87. //mode2 is 1 is missing
  88.  
  89. printf("choose \n1-beginner \t\t 2-expert : ");
  90. scanf("%d",&mode1);getchar();
  91.  
  92. while(mode1!=1&&mode1!=2)
  93. {printf("please try again typing your choice correctly\a\n");
  94. scanf("%d",&mode1);getchar();
  95. }
  96. if(mode1==1)
  97. {
  98. *max_r=9;//max rows with spaces
  99. *max_c=19;//max columns with spaces
  100. one.remainingmoves=beglines/2;
  101. two.remainingmoves=beglines/2;
  102. *remaining_lines=beglines;
  103. }
  104.  
  105.  
  106. else if(mode1==2)
  107. {
  108. *max_r=21;//max rows with spaces
  109. *max_c=46;//max columns with spaces
  110. one.remainingmoves=explines/2;
  111. two.remainingmoves=explines/2;
  112. *remaining_lines=explines;
  113. }
  114.  
  115. }
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. #include "Functions.h"
  124.  
  125.  
  126. void grid_move(int grid[50][50],int *max_r,int *max_c,int *remaining_lines)
  127. {
  128. int tem,win1,win2;
  129. int count=0;
  130. int valid=0;
  131. int get_move[move_size];
  132.  
  133. for(int i=0;i<(*max_r);i++)
  134. for(int j=0;j<(*max_c);j++)
  135. {
  136.  
  137. if(i%4==0&&j%9==0)
  138. grid[i][j]=3; //3 for dots
  139. }
  140.  
  141. printf("1-redo 2-move\n");
  142. scanf("%d",&rm);getchar();
  143. while(rm!=1&&rm!=2)
  144. {printf("please try again typing your choice correctly\a\n");
  145. scanf("%d",&rm);getchar();
  146. }
  147. if(rm==1)
  148. {
  149. if((*remaining_lines)==60)
  150. printf("redo can not be done");
  151. else
  152. redo( get_move);
  153. }
  154.  
  155.  
  156. if(rm==2)
  157. {
  158. while (count<4)
  159. { count=0;
  160. for(int i=0;i<move_size;i++)
  161. {
  162. scanf("%d",&get_move[i]);getchar();
  163. if(get_move[i]>(*max_r)/4+1||get_move[i]<1)
  164. { count--;
  165. printf("please try again\n\a");
  166. break;
  167. }
  168. else
  169. count++;
  170. }
  171. if(get_move[0]==get_move[1]&&get_move[3]==get_move[2])
  172. {count--; printf("please try again\n\a"); }
  173.  
  174. else if(get_move[0]!=get_move[1]&&get_move[3]!=get_move[2])
  175. {count--; printf("please try again\n"); }
  176.  
  177. else if(abs(get_move[0]-get_move[1])>1||abs(get_move[2]-get_move[3])>1)
  178. {count--; printf("please try again\n"); }
  179. }
  180.  
  181. }
  182.  
  183.  
  184. if(rm!=1){
  185. for(int i=0;i<move_size;i++)
  186. {
  187. big[c]=get_move[i];
  188. c++;
  189.  
  190. }
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197. for(int i=0;i<move_size;i++)
  198. {
  199. if(i<1||i==1)
  200. get_move[i]=(get_move[i]-1)*4;
  201. if(i>1)
  202. get_move[i]=(get_move[i]-1)*9;
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209. if(get_move[0]==get_move[1])
  210. {
  211. if(get_move[3]<get_move[2])
  212. {
  213. tem=get_move[3];
  214. get_move[3]=get_move[2];
  215. get_move[2]=tem;
  216. }
  217. for(int i=get_move[2]+1;i<get_move[3];i++)
  218. {if(rm==2)
  219. grid[get_move[1]][i]=1;
  220. if(rm==1)
  221. grid[get_move[1]][i]=0;
  222. // 1 for horizontal
  223. } // 1 for horizontal
  224.  
  225. int constant =get_move[0];
  226. int start=get_move[2];
  227. int end=get_move[3];
  228.  
  229. horizontal_win(constant,start,end,grid);
  230. }
  231.  
  232.  
  233. if(get_move[2]==get_move[3])
  234. {
  235. if(get_move[1]<get_move[0])
  236. {
  237. tem=get_move[1];
  238. get_move[1]=get_move[0];
  239. get_move[0]=tem;
  240. }
  241. for(int i=get_move[0]+1;i<get_move[1];i++)
  242. {if(rm==2)
  243. grid[i][get_move[2]]=2;
  244. if(rm==1)
  245. grid[i][get_move[2]]=0;
  246. // 2 for vertical
  247. } // 2 for vertical
  248.  
  249. int constant =get_move[2];
  250. int start=get_move[0];
  251. int end=get_move[1];
  252.  
  253. // putting numbers in the boxes :)
  254.  
  255. vertical_win(constant,start,end,grid);
  256. }
  257.  
  258.  
  259.  
  260. // int c=1;
  261. for(int i=0;i<(*max_r);i++)
  262. {
  263. { for(int j=0;j<(*max_c);j++)
  264. switch (grid[i][j])
  265. {
  266. case 1:printf("%c",196);
  267. break;
  268. case 2: printf("%c",179);
  269. break;
  270. case 3:printf("%c",254);
  271. break;
  272. case 4:printf("1");
  273. break;
  274. case 5:printf("2");
  275. break;
  276. default: printf(" ");
  277. break;
  278. }printf("\n");
  279. }}
  280.  
  281. if (one.turn>0)
  282. one.remainingmoves--;
  283. if (two.turn>0)
  284. two.remainingmoves--;
  285.  
  286. // current.remainingmoves--;
  287. (*remaining_lines)--;
  288.  
  289.  
  290. }
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. #include "Functions.h"
  299.  
  300. int horizontal_win(int constant ,int start,int end ,int grid[50][50])
  301.  
  302. {
  303. int counter1=0;
  304. int counter2=0;
  305. if(grid[constant-1][start]==2)
  306. counter1++;
  307. if(grid[constant-4][start+1]==1)
  308. counter1++;
  309. if(grid[constant-1][end]==2)
  310. counter1++;
  311. if(counter1==3)
  312. {
  313. if (one.turn>1||one.turn==1)
  314. {grid[constant-2][start+4]=4;
  315. one.turn++;one.score++;}
  316. else if (two.turn>1||two.turn==1)
  317. {grid[constant-2][start+4]=5;
  318. two.turn++;two.score++;}
  319. }
  320.  
  321.  
  322.  
  323. if(grid[constant+1][start]==2)
  324. {counter2++;}
  325. if(grid[constant+4][start+1]==1)
  326. {counter2++;}
  327. if(grid[constant+1][end]==2)
  328. {counter2++;}
  329.  
  330. if(counter2==3)
  331. {
  332.  
  333. if (one.turn>1||one.turn==1)
  334. {grid[constant+2][start+4]=4;
  335. one.turn++;one.score++;}
  336. else if (two.turn>1||two.turn==1)
  337. {grid[constant+2][start+4]=5;
  338. two.turn++;two.score++;}
  339. }
  340.  
  341. }
  342.  
  343.  
  344. void redo( int get_move[move_size])
  345. {
  346. for(int i=0;i<move_size;i++)
  347. {
  348. get_move[3-i]=big[c-1];
  349.  
  350. c--;
  351.  
  352. }
  353. }
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. #include "Functions.h"
  369. int vertical_win(int constant ,int start,int end ,int grid[50][50])
  370. {
  371.  
  372.  
  373. int counter1=0;
  374. int counter2=0;
  375. if(grid[start][constant-1]==1)
  376. counter1++;
  377. if(grid[start+1][constant-9]==2)
  378. counter1++;
  379. if(grid[end][constant-1]==1)
  380. counter1++;
  381. if(counter1==3)
  382. {
  383. if (one.turn>1||one.turn==1)
  384. {grid[start+2][constant-4]=4;
  385. one.turn++;one.score++;}
  386. else if (two.turn>1||two.turn==1)
  387. {grid[start+2][constant-4]=5;
  388. two.turn++;two.score++;}
  389.  
  390. }
  391.  
  392. if(grid[start][constant+1]==1)
  393. {counter2++;}
  394. if(grid[start+1][constant+9]==2)
  395. {counter2++;}
  396. if(grid[end][constant+1]==1)
  397. {counter2++;}
  398.  
  399. if(counter2==3)
  400. {
  401. if (one.turn>1||one.turn==1)
  402. {grid[start+2][constant+4]=4;
  403. one.turn++;one.score++;}
  404. else if (two.turn>1||two.turn==1)
  405. {
  406. grid[start+2][constant+4]=5;
  407. two.turn++;two.score++;}
  408.  
  409. }
  410. }
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420. #ifndef FUNCTIONS_H_INCLUDED
  421. #define FUNCTIONS_H_INCLUDED
  422.  
  423. #include <stdio.h>
  424. #include <stdlib.h>
  425. #include <string.h>
  426.  
  427. #define explines 60
  428. #define beglines 12
  429. #define MAXBIG 100
  430. # define move_size 4
  431. #define total moves 12
  432. typedef struct
  433. {
  434. char name[100];
  435. int remainingmoves;
  436. int score;
  437. int turn;
  438. }player;
  439.  
  440. player one;
  441. player two;
  442.  
  443. extern int big[200];extern int c;extern int rm;
  444.  
  445.  
  446.  
  447. void redo( int get_move[move_size]);
  448. void grid_move(int grid[50][50],int *max_r,int *max_c,int *remaining_lines);
  449. int vertical_win(int constant ,int start,int end ,int grid[50][50]);
  450. int horizontal_win(int constant ,int start,int end ,int grid[50][50]);
  451. void init (int *max_r,int *max_c,int *remaining_lines);
  452. #endif // FUNCTIONS_H_INCLUDED
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461. #include <stdio.h>
  462. #include <stdlib.h>
  463.  
  464. int c=0;
  465. int big[200];
  466. int rm=0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement