<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3.    FETCH Player1_CardsTotalValue
4.    FETCH Player2_CardsTotalValue
5.          CHECK Number of Cards Quantity in Player1 Hand (Max 10)
6.          CHECK Number of Cards Quantity in Player2 Hand (Max 10)
7.          CHECK Total Cards Value belonging to Player 1
8.          CHECK Total Cards Value belonging to Player 2
9. SORT Card Values to Numerical Order (Highest to Lowest)
10.    WHILE Cards are issued
11.       COMPARE CardsValues between Player1 Hand and Player2 Hand
12.        IF Player1>Player2
13.             PRINT PLAYER1 Is the Winner
14.          ELSE PLAYER2 WIN
15.             PRINT PLAYER 2 Is the Winner
16.        ELSEIF PLAYER1=PLAYER2
17.            PRINT It's a Draw
18.    CHECK next highest hand - if no more cards = DRAW
19. END
20. */
21.
22. #include <stdio.h>
23.
24. /* START OF PROGRAM */
25.
26. /* Variables Declaration */
27.
28. int main(void)
29. {
30.
31. int i, j, l;
32. int Player1Total;
33. int Player1Cards[10] = {0};
34. int Player2Total = 0;
35. int Player2Cards[10] = {0};
36.
37. /* User Input (Card Values) */
38.
39.    /* Player 1 Cards in Hand */
40. scanf("%d", &Player1Total);
41.     for(i = 0; i < Player1Total; i++) {
42.         scanf("%d", &Player1Cards[i]);
43.     }
44.
45.     /* PLayer 2 Cards in Hand */
46. scanf("%d", &Player2Total);
47.     for(i = 0; i < Player2Total; i++) {
48.         scanf("%d", &Player2Cards[i]);
49.     }
50.
51. /* Data Validation / Error Checking */
52.
53. /* Check that the total cards value of Player 1 is more than 2 and less than 10 */
54. if(Player1Total > 10 || Player1Total < 2) {
55.     printf("Player 1 has too many cards in hand (Max is 10)");
56.     return 0;
57.     }
58.
59.
60. /* Check that the total cards value of Player 2 is more than 2 and less than 10 */
61. if(Player2Total > 10 || Player2Total < 2) {
62.     printf("Player 2 has too many cards in hand (Max is 10)");
63.     return 0;
64.     }
65.
66. /* Check that the total cards value of Player 1 are between 1 and 10 */
67. for(i = 0; i < Player1Total; i++) {
68. if(Player1Cards[i] < 1 || Player1Cards[i] > 10) {
69.     printf("Player 1 has entered incorrect values in their hand");
70.     return 0;
71.     }
72. }
73.
74. /* Check that the total cards value of Player 2 are between 1 and 10 */
75. for(i = 0; i < Player2Total; i++) {
76. if(Player2Cards[i] < 1 || Player2Cards[i] > 10) {
77.     printf("Player 2 has entered incorrect values in their hand");
78.     return 0;
79.     }
80. }
81.
82. /*Sorting the issued cards to Players */
83.
84. /*SORT FOR PLAYER 1 CARDS */
85. for(i = 0; i < Player1Total; i ++) {
86.     for(j = 0; j < Player1Total; j++) {
87.      if(Player1Cards[j + 1] > Player1Cards[j]) {
88.
89.          l = Player1Cards[j];
90.          Player1Cards[j] = Player1Cards[j + 1];
91.          Player1Cards[j + 1] = l;
92.
93.     }
94. }
95.
96. }
97. /*SORT FOR PLAYER 2 CARDS */
98. for(i = 0; i < Player2Total; i ++) {
99.     for(j = 0; j < Player2Total; j++) {
100.      if(Player2Cards[j + 1] > Player2Cards[j]) {
101.
102.          l = Player2Cards[j];
103.          Player2Cards[j] = Player2Cards[j + 1];
104.          Player2Cards[j + 1] = l;
105.
106.     }
107. }
108. }
109.
110. /*Verification of Final Result - Check Sequences*/
111. for(i = 0; i < 10; i++) {
112.
113.     /* Winner: Player 1*/
114.     if(Player1Cards[i] > Player2Cards[i]) {
115.         printf("Player 1 is the winner!");
116.         return 0;
117.     }
118.
119.
120.     /* Winner: Player 2*/
121.     if(Player2Cards[i] > Player1Cards[i]) {
122.         printf("Player 2 is the winner!");
123.         return 0;
124.     }
125. }
126.
127. /* No Winner */
128.
129. printf("It's a draw!");
130.      }
131.
132.
133. /* END OF PROGRAM */