<mosaic.cnfolio.com>
PROGRAM
1. /*START
2. WHILE both player’s hand is not between 1 and 11, excluding 1 and 11
3.   obtain hand size for player 1 and player 2
4.    IF player player 1's hand is below 2
5.      display player's hand size is too small
6.       END IF
7.    IF player 1's hand is above 10
8.      display player's hand size is too big
9.
10. END WHILE
11. WHILE numbered cards of player 1 and player 2 are between 1 and 10, including 1 & 10
12. obtain the numbered cards in their hand
13. END WHILE
14.
15. WHILE both players’ hand have not been sorted
16. WHILE the list is not sorted properly in cycles of descending order
17.   WHILE the list is not properly sorted
18.       IF the next card in player’s hand is greater than the current card
19.     Swap the 2 numbers
20. END IF
21.   Go to next card after the current card
22. END WHILE
23. END WHILE
24. Go to next player
25. END WHILE
26.
27. WHILE player has card in hand
28.   IF Player 1 hand and Player 2 hand is equal to 0
29.     OUTPUT Draw
30.   END IF
31.   IF Check for Player 1’s hand is 0
32.     Player 2 wins
33.   END IF
34. IF Check for Player 2’s hand is 0
35.   Player 1 Wins
36. END IF
37. IF Player 1 is greater than Player 2
38.     OUTPUT player 1 wins
39.   END IF
40.   IF Player 1 is less than Player 2
41. OUTPUT player 2 wins
42. END IF
43. IF Player 1 is equal to Player 2
44. OUTPUT Draw
45.   END IF
46.     /*Go to next card in the players’ hand
47. END WHILE
48. END*/
49. /*===============================================================================================*/
50. #include <stdio.h>
51. #include <stdlib.h>
52.
53. int main(){
54.
55.     int hand_size1=0;    /*The Number of cards in Player1's Hand*/
56.     int hand_size2=0;    /*The Number of cards in Player2's Hand*/
57.     int player1[10]={0}; /*The Numbered cards in Player1's Hand*/
58.     int player2[10]={0}; /*The Numbered cards in Player2's Hand*/
59.     int i,j;             /*Use for loops*/
60.     int temp;            /*Temporary variable to hold the current number in current element*/
61. /*===============================================================================================*/
62.     /*Player 1 - No. of cards in hand*/
63.     while(hand_size1<1 || hand_size1>11){
64.       scanf(" %d", &hand_size1);
65.          if(hand_size1<2){
66.                printf("Error! Player 1 you have gone below the card limit or have entered a non integer value\n");
67.                printf("i.e. letters or special characters \n");
68.                return 0;
69.          }
70.          if(hand_size1>10){
71.                printf("Error! You've gone above the card limit Player 1\n");
72.                return 0;
73.          }
74.     }
75.
76.    /*Player 1 - The Numbered Cards*/
77.     for(i = 0;i<hand_size1;i++){
78.         scanf(" %d", &player1[i]);
79.           if(player1[i]<1){
80.                printf("Error! You have gone below the number limit or have entered a non integer value Player 1\n");
81.                printf("i.e. letters or special characters \n");
82.                i--;
83.                return 0;
84.           }
85.           if(player1[i]>10){
86.                printf("Error! You've gone above the number limit Player 1\n");
87.                i--;
88.                return 0;
89.           }
90.     }
91. /*===============================================================================================*/
92.     /*Player 2 - No. of cards in hand*/
93.     while(hand_size2<1 || hand_size2>11){
94.       scanf(" %d", &hand_size2);
95.          if(hand_size2<2){
96.                printf("Error! Player 2 you have gone below the card limit or have entered a non integer value\n");
97.                printf("i.e. letters or special characters \n");
98.                return 0;
99.          }
100.          if(hand_size2>10){
101.                printf("Error! You've gone above the card limit Player 2\n");
102.                return 0;
103.          }
104.     }
105.
106.     /*Player 2 - The Numbered Cards*/
107.     for(j = 0;j<hand_size2;j++){
108.         scanf(" %d", &player2[j]);
109.           if(player2[j]<1){
110.                printf("Error! You have gone below the number limit or have entered a non integer value Player 2\n");
111.                printf("i.e. letters or special characters \n");
112.                j--;
113.                return 0;
114.           }
115.           if(player2[j]>10){
116.                printf("Error! You've gone above the number limit Player 2\n");
117.                j--;
118.                return 0;
119.           }
120.      }
121. /*================================================================================*/
122.     /*Player 1 - Descending Bubble sort algorithm*/
123.     for(i=0;i<hand_size1-1;i++){     /*How many times you gone through the list*/
124.         for(j=0;j <hand_size1;j++){  /*going through every element of the array*/
125.             if(player1[j+1] > player1[j]){
126.                 temp = player1[j];        /*storing the current number in a temporary value*/
127.                 player1[j] = player1[j+1];
128.                 player1[j+1] = temp;
129.
130.             }
131.         }
132.     }
133.
134.     /*Player 2 - Descending Bubble sort algorithm*/
135.     for(i=0;i<hand_size2-1;i++){     /*How many times you gone through the list*/
136.         for(j=0;j <hand_size2;j++){  /*going through every element of the array*/
137.             if(player2[j+1] > player2[j]){
138.                 temp = player2[j];        /*storing the current number in a temporary value*/
139.                 player2[j] = player2[j+1];
140.                 player2[j+1] = temp;
141.
142.             }
143.         }
144.     }
145. /*===============================================================================================*/
146.     /*Final Outputs for game outcome*/
147.     for(i=0; i<10;i++){
148.         if(hand_size1 == 0 && hand_size2 == 0){
149.             printf("It is a Draw!\n");
150.             break;
151.         }
152.         if(hand_size1 == 0){
153.             printf("Player 2 Wins!\n");
154.             break;
155.         }
156.         if(hand_size2 == 0){
157.             printf("Player 1 Wins!\n");
158.            break;
159.         }
160.         if(player1[i] > player2[i]){
161.             printf("Player 1 Wins!");
162.             break;
163.         }
164.         if(player1[i] < player2[i]){
165.             printf("Player 2 Wins!");
166.             break;
167.         }
168.         if(player1[i] == player2[i]){
169.             printf("It's a Draw\n");
170.             break;
171.         }
172.         hand_size1--;    //Decrement cards in hand
173.         hand_size2--;    //Decrement cards in hand
174.     }
175.   return 0;
176. }