Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main()
  6. {
  7. int usernum, compnum, matchtotal, startplayer, z, takematch, maxcomp, maxhumen, randcomp;
  8. takematch = 0, compnum =1;
  9.  
  10. printf("how many matches do you want to play (10-100)? \n");
  11.  
  12. scanf("%d", &matchtotal);
  13. if (matchtotal < 10)
  14. {
  15. matchtotal = 10;
  16. }
  17. else if (matchtotal > 100)
  18. {
  19. matchtotal = 100;
  20. }
  21.  
  22. printf("Who will move in the first turn? (1-Computer, 2-Man): \n");
  23.  
  24. scanf("%d" , &startplayer);
  25.  
  26. if (startplayer != 2)
  27. {
  28. /*Any else input other than 2 means comp starts */
  29. startplayer = 1;
  30. }
  31.  
  32. while (matchtotal > 0)
  33. {
  34.  
  35. if (startplayer == 2)
  36. {
  37. while (matchtotal > 0)
  38. {
  39. printf("there are %d matches on the table \n", matchtotal);
  40.  
  41. if (takematch == 0)
  42. {
  43. maxcomp = 2 * compnum;
  44. }
  45. else
  46. {
  47. maxcomp = 2 * randcomp;
  48. }
  49.  
  50. printf("possbile move is[1..%d] matches..... \n", maxcomp);
  51.  
  52. printf("how many do u wish to take?");
  53.  
  54. scanf("%d", &takematch);
  55.  
  56. if (takematch < 1 || takematch > maxcomp)
  57. {
  58. printf("Illegal please retry \n");
  59. }
  60.  
  61. while (takematch < 1 || takematch > maxcomp)
  62. {
  63. printf("possbile move is[1..%d] matches..... \n", maxcomp);
  64.  
  65. printf("how many do u wish to take?");
  66.  
  67. scanf("%d", &takematch);
  68.  
  69. if (takematch < 1 || takematch > maxcomp)
  70. {
  71. printf("Illegal please retry \n");
  72. }
  73. }
  74.  
  75. matchtotal = matchtotal - takematch;
  76. if (matchtotal <= 0)
  77. {
  78. printf("Computer wins!");
  79. matchtotal = 0;
  80. }
  81.  
  82. maxhumen = 2 * takematch;
  83. printf("there are %d matches on the table \n", matchtotal);
  84. printf("possbile move is[1..%d] matches..... \n", maxhumen);
  85.  
  86. randcomp = rand() % maxhumen + 1;
  87.  
  88. if (maxhumen >= matchtotal)
  89. {
  90. printf("computer wins! \n");
  91. matchtotal = 0;
  92. }
  93. else
  94. {
  95. printf("computer takes %d\n", randcomp);
  96. matchtotal = matchtotal - randcomp;
  97. if (matchtotal <= 0)
  98. {
  99. printf("Humen wins! \n");
  100. }
  101.  
  102. }
  103.  
  104.  
  105. }
  106.  
  107. }
  108.  
  109. if (startplayer == 1)
  110. {
  111. printf("there are %d matches on the table \n", matchtotal);
  112.  
  113. if (takematch == 0)
  114. {
  115. maxhumen = 2 * compnum;
  116. }
  117. else
  118. {
  119. maxhumen = 2 * takematch;
  120. }
  121.  
  122.  
  123. printf("possbile move is[1..%d] matches..... \n", maxhumen);
  124.  
  125. randcomp = rand() % maxhumen + 1;
  126.  
  127. if (maxhumen >= matchtotal)
  128. {
  129. printf("humen wins! \n");
  130. matchtotal = 0;
  131. }
  132. else
  133. {
  134. printf("computer takes %d\n", randcomp);
  135. matchtotal = matchtotal - randcomp;
  136. if (matchtotal <= 0)
  137. {
  138. printf("computer wins! \n");
  139. }
  140.  
  141. }
  142.  
  143.  
  144. maxcomp = 2 * randcomp;
  145.  
  146. printf("there are %d matches on the table \n", matchtotal);
  147.  
  148. printf("possbile move is[1..%d] matches..... \n", maxcomp);
  149.  
  150. printf("how many do u wish to take?");
  151.  
  152. scanf("%d", &takematch);
  153.  
  154. if (takematch < 1 || takematch > maxcomp)
  155. {
  156. printf("Illegal please retry \n");
  157. }
  158.  
  159. while (takematch < 1 || takematch > maxcomp)
  160. {
  161. printf("possbile move is[1..%d] matches..... \n", maxcomp);
  162.  
  163. printf("how many do u wish to take?");
  164.  
  165. scanf("%d", &takematch);
  166.  
  167. if (takematch < 1 || takematch > maxcomp)
  168. {
  169. printf("Illegal please retry \n");
  170. }
  171. }
  172.  
  173. matchtotal = matchtotal - takematch;
  174. if (matchtotal <= 0)
  175. {
  176. printf("humen wins!");
  177. matchtotal = 0;
  178. }
  179. }
  180.  
  181. }
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement