Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //This function uses a bubble counter1 to arrange the number2 numbers highest to lowest
  5. int arrange ( int arraydim [] ){
  6. int counter2, counter1;
  7. int change = arraydim [0];
  8. for (counter1 = 0; counter1 < 4; ++counter1 ){
  9. for (counter2 =0; counter2 < (4 - counter1); ++counter2){
  10. if (arraydim [counter2] > arraydim [counter2 + 1] ){
  11. change = arraydim [counter2 + 1];
  12. arraydim [counter2 +1] = arraydim [counter2];
  13. arraydim [counter2] = change;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. int Threeofakind ( int number1, int number2 [], int * const checkthreekinds)
  20. {
  21. int counter1, counter2, duplicateCounter1 = 0;
  22. //Uses a nested loop to check every element of the arraydim against the others to find if there are 3 of the same number
  23. for ( counter2 = 0; counter2 < number1; counter2++ ){
  24. if ( duplicateCounter1 >= 3 )
  25. { break; }
  26. duplicateCounter1 = 0;
  27.  
  28. for ( counter1 = 0; counter1 < number1; counter1++ ){
  29. if ( number2 [counter1] == number2 [counter2] )
  30. { duplicateCounter1++;}
  31.  
  32.  
  33. }
  34. }
  35.  
  36. if ( duplicateCounter1 >= 3 ){
  37. duplicateCounter1 = ((((number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
  38. //Here is the check I mentioned earlier which stops the function scoring twice.
  39. *checkthreekinds= 1;
  40.  
  41. }else{
  42. duplicateCounter1 = 0;
  43.  
  44. }return duplicateCounter1;
  45. }
  46.  
  47.  
  48. int fullHouse ( int number2 [], int * const Checkfullhouse ){
  49. int ret;
  50. //Due to the size of the number2 arraydim there are only 2 conditions where a full house can score, this checks for both of those
  51. if ( number2 [0] == number2 [1] && number2 [0] == number2 [2] && number2 [3] == number2 [4] ){
  52. ret = 40;
  53. *Checkfullhouse =1;
  54. }else if ( number2 [0] == number2 [1] && number2 [2] == number2 [3] && number2 [3] == number2 [4]){
  55. ret = 40;
  56. *Checkfullhouse =1;
  57. }else{
  58. ret = 0;
  59. }return ret;
  60. }
  61. int LongStraight ( int number2 [], int * const CheckLongStraight){
  62. int ret;
  63. //There is only one way to score a long staright, this checks for that, the number2s are ordered so its easy to check.
  64. if ( number2 [1] == ( number2 [0] + 1) && number2 [2] == ( number2 [1] +1) && number2 [3] == ( number2 [2] + 1) && number2 [4] == ( number2 [3] + 1 )){
  65. ret = 35;
  66. *CheckLongStraight= 1;
  67. }else{
  68. ret = 0;
  69. }return ret;
  70. }
  71.  
  72. int ShortStraight ( int number2 [], int * const CheckShortStraight){
  73. int ret, counter1, add1 = 0;
  74. //Uses if statements to check all the times a short straight can be achieved.
  75. //It may have been easier to uses loops for this, however I couldn't figure it out.
  76. if ( (number2 [1] == ( number2 [0] +1 )) || ( number2 [2] == ( number2 [0] +1))){
  77. add1++;
  78.  
  79. }if ( (number2 [2] == ( number2 [0] + 2 )) && (number2 [1] == ( number2 [0] +1 ))){
  80. add1++;
  81.  
  82. }if ( (number2 [3] == ( number2 [0] + 3 )) && ( number2 [2] == ( number2 [0] +2))){
  83. add1++;
  84.  
  85. }if (add1 == 3){
  86. *CheckShortStraight= 1;
  87. return 25;
  88. }else if (add1 < 3 ){
  89. add1 = 0;
  90. }if (( number2 [2] == ( number2 [1] + 1 )) && ( number2 [3] == ( number2 [2] + 1 )) && ( number2 [4] == ( number2 [3] + 1 ))){
  91. *CheckShortStraight= 1;
  92.  
  93. return 25;
  94. }else{
  95. return 0;
  96. }
  97. }
  98.  
  99. int FiveOfAKind ( int number2 [], int * const CheckFivesKind ){
  100. int ret;
  101. //There is only one time 5 of a kind can be scored, this checks for that
  102. if ( (number2 [0] == number2 [1]) && (number2 [0] == number2 [2]) && (number2 [0] == number2 [3]) && (number2 [0] == number2 [4]) ){
  103. ret = 50;
  104. *CheckFivesKind = 1;
  105. }else{
  106. ret = 0;
  107. } return ret;
  108. }
  109.  
  110. int FourOfAKind ( int number2 [], int * const CheckFoursKind )
  111. {
  112. int counter1, counter2, duplicateCounter1 = 0;
  113. /*Uses a nested for loop exactly the same way as the 3 of a kind function,
  114. just with the requirement to return a non-zero interger when 4 of the same numbers
  115. are counted rather than 3*/
  116. for ( counter2 = 0; counter2 < 5; counter2++ ){
  117. if ( duplicateCounter1 >= 4 )
  118. { break; }
  119. duplicateCounter1 = 0;
  120.  
  121. for ( counter1 = 0; counter1 < 5; counter1++ ){
  122. if ( number2 [counter1] == number2 [counter2] )
  123. { duplicateCounter1++;}
  124.  
  125.  
  126.  
  127. }
  128. }
  129.  
  130. if ( duplicateCounter1 >= 4 ){
  131. duplicateCounter1 = ((((number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
  132. *CheckFoursKind = 1;
  133.  
  134. }else{
  135. duplicateCounter1 = 0;
  136.  
  137. }return duplicateCounter1;
  138. }
  139.  
  140.  
  141. int Chance ( int number2 [], int * const CheckChance ){
  142. int ret;
  143.  
  144. *CheckChance = 1;
  145. ret = (((( number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
  146. return ret;
  147. }
  148.  
  149. int twos ( int number2 [], int * const Check, int num ){
  150. int ret, counter1,add1;
  151. /*This function scores all of the catagories from 1 to 6, hence the
  152. check in nonspecific and can be refering to any of the checks from
  153. those 6 catagories, the rest of this one is pretty self explanitory*/
  154. for ( counter1 = 0; counter1 < 5; counter1++ ){
  155. if ( number2 [counter1] == num ){
  156. add1++;
  157. }
  158. }if (add1 >= 1 ){
  159. *Check = 1;
  160. }else {
  161. num = 0;
  162. }ret = ( num *add1);
  163. return ret;
  164. }
  165.  
  166.  
  167.  
  168. int main( void )
  169. {
  170. int counter1, counter2, checkthreeskinds =0, add =0, Checkfullhouse = 0, CheckLongStraight =0, CheckShortStraight = 0, CheckFives = 0, CheckFours = 0, CheckChance = 0, CheckOnes = 0,
  171. CheckTwos = 0, CheckThrees2 = 0, CheckFours2 =0, CheckFives2 =0, CheckSixes = 0 ;
  172. int inputNumbers[13][ 5 ] = { '\0' };
  173.  
  174. for ( counter2 = 0; counter2 < 13; counter2++){
  175. for ( counter1 = 0; counter1 < 5; counter1++ ){
  176. scanf( "%d", &inputNumbers[ counter2 ][ counter1 ] );
  177. }
  178. }for ( counter1 = 0; counter1 < 13; counter1++){
  179. for ( counter2 = 0; counter2 < 5; counter2++ ){
  180. if ( inputNumbers [counter1] [counter2] < 1 || inputNumbers [counter1] [counter2] > 6 ){
  181. printf ( "Dice set %d, die %d is %d, which is not a six sided dice value, please change this and re-run.\n If the value of incorrect die is 0 it may be that you have not entered enough values or you have enter a letter or symbol.\n Please make sure to enter 13 sets of 5 numbers 1 to 6.\n ", ( counter1 + 1 ), ( counter2 + 1 ), inputNumbers [counter1] [counter2] );
  182. return 0;
  183. }
  184. }
  185. }for (counter2 = 0; counter2 < 13; counter2++ ){
  186.  
  187. arrange( inputNumbers [counter2] );
  188.  
  189. }
  190. for (counter2 = 0; counter2 < 13; counter2++ ){
  191. counter1 = 0;
  192. switch ( counter1 ){
  193.  
  194. case (0):
  195. if ( CheckFives != 1){
  196. add += FiveOfAKind ( inputNumbers [counter2], &CheckFives );
  197. if ( counter1 == 5 && add >= 63 ){
  198. add += 35;
  199. }if ( CheckFives == 1 )
  200. {break;}
  201. else{
  202. counter1++;}
  203.  
  204.  
  205. }case (1):
  206. if ( Checkfullhouse != 1 ){
  207. add += fullHouse ( inputNumbers [counter2], &Checkfullhouse );
  208. if ( counter1 == 5 && add >= 63 ){
  209. add += 35;
  210. }if ( Checkfullhouse == 1)
  211. {break;}
  212. else{
  213. counter1++;}
  214.  
  215. }case (2):
  216. if ( CheckLongStraight !=1 )
  217. { add += LongStraight ( inputNumbers [counter2], &CheckLongStraight );
  218. if ( counter1 == 5 && add >= 63 ){
  219. add += 35;
  220. }if ( CheckLongStraight == 1 )
  221. {break;}
  222. else{
  223. counter1++;}
  224.  
  225. }case (3):
  226. if ( CheckShortStraight != 1 ){
  227. add += ShortStraight ( inputNumbers [counter2], &CheckShortStraight );
  228. if ( counter1 == 5 && add >= 63 ){
  229. add += 35;
  230. }if ( CheckShortStraight == 1 )
  231. {break;}
  232. else{
  233. counter1++;}
  234.  
  235. }case (4):
  236. if ( CheckFours != 1){
  237. add += FourOfAKind ( inputNumbers [counter2], &CheckFours );
  238. if ( counter1 == 5 && add >= 63 ){
  239. add += 35;
  240. }if ( CheckFours == 1 )
  241. {break;}
  242. else{
  243. counter1++;}
  244.  
  245.  
  246.  
  247. }case (5):
  248. if ( checkthreeskinds != 1 ){
  249. add += Threeofakind( 5, inputNumbers [counter2], &checkthreeskinds );
  250. if ( counter1 == 5 && add >= 63 ){
  251. add += 35;
  252. }if (checkthreeskinds == 1)
  253. {break;}
  254. else{
  255. counter1++;}
  256.  
  257. }case (6):
  258. if ( CheckChance != 1 ){
  259. add += Chance ( inputNumbers [counter2], &CheckChance );
  260. if ( counter1 == 5 && add >= 63 ){
  261. add += 35;
  262. }if ( CheckChance == 1 )
  263. {break;
  264. counter1++;}
  265.  
  266. }case (7):
  267. if ( CheckOnes != 1 ){
  268. add += twos ( inputNumbers [counter2], &CheckOnes, 1 );
  269. if ( counter1 == 5 && add >= 63 ){
  270. add += 35;
  271. }if ( CheckOnes == 1 )
  272. {break;}
  273. else{
  274. counter1++;}
  275.  
  276. }case (8):
  277. if ( CheckTwos != 1 ){
  278. add += twos ( inputNumbers [counter2], &CheckTwos, 2 );
  279. if ( counter1 == 5 && add >= 63 ){
  280. add += 35;
  281. }if ( CheckTwos == 1 )
  282. {break;}
  283. else{
  284. counter1++;}
  285.  
  286. }case (9):
  287. if ( CheckThrees2 != 1 ){
  288. add += twos ( inputNumbers [counter2], &CheckThrees2, 3 );
  289. if ( counter1 == 5 && add >= 63 ){
  290. add += 35;
  291. }if ( CheckThrees2 == 1 )
  292. {break;}
  293. else{
  294. counter1++;}
  295.  
  296. }case (10):
  297. if ( CheckFours2 != 1 ){
  298. add += twos ( inputNumbers [counter2], &CheckFours2, 4 );
  299. if ( counter1 == 5 && add >= 63 ){
  300. add += 35;
  301. }if ( CheckFours2 == 1 )
  302. {break;}
  303. else{
  304. counter1++;}
  305.  
  306. }case (11):
  307. if ( CheckFives2 != 1 ){
  308. add += twos ( inputNumbers [counter2], &CheckFives2, 5 );
  309. if ( counter1 == 5 && add >= 63 ){
  310. add += 35;
  311. }if ( CheckFives2 == 1 )
  312. {break;}
  313. else{
  314. counter1++;}
  315.  
  316. }case (12):
  317. if ( CheckSixes != 1 ){
  318. add += twos ( inputNumbers [counter2], &CheckSixes, 6 );
  319. if ( counter1 == 5 && add >= 63 ){
  320. add += 35;
  321. }if ( CheckSixes == 1 )
  322. {break;}
  323. else{
  324. counter1++;}
  325. }
  326.  
  327. }
  328. }printf ( "The score is %d\n", add );
  329.  
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement