<mosaic.cnfolio.com>
PROGRAM
1. /*
2. Pseudo code
3.
4. START
5.
6. Player1 and Player 2 draw an amount of numbered cards
7.
8. Register player 1, the amount of cards they have and what cards
9. Register player 2, the amount of cards they have and what cards
10.
11. IF Player 1's has less than 2 cards
12.
13.      THEN say "Player 1 needs more cards to play", then end the game
14.
15.      endif
16.
17. IF Player 2's has less than 2 cards
18.
19.      THEN say "Player 2 needs more cards to play", then end the game
20.
21.      endif
22.
23. IF any of Player 1's cards are less than one or more than ten
24.
25.      THEN say "Player 1's card ammount can only be between 1 and 10", then end the game
26.
27.      endif
28.
29. IF any of Player 2's cards are less than one or more than ten
30.
31.      THEN say "Player 2's card ammount can only be between 1 and 10", then end the game
32.
33.      endif
34.
35. Sort the cards using, bubble sort
36.
37. Now game can start
38.
39. Take player 1's first card and Player 2's first card
40.
41. Set the counter equal to the highest array between Player 1 and Player 2
42.
43.    WHILE the variable doesn't equal the highest array
44.
45.          THEN, IF Player 1's card is higher
46.
47.                   THEN, say "Player 1 wins"
48.
49.         ELSE, IF Player 2's card is higher
50.
51.                   THEN say "Player 2 wins"
52.
53.    add 1 to the to the variable
54.
55. "Game ends in a draw"
56.
57. FINISH
58.
59. */
60.
61. /*
62. number = The amount of each card
63. cards = The amount of cards entered
64. */
65.
66. #include <stdio.h>
67.
68. int main( game )
69.
70. {
71.   int number1[10];
72.   int cards1;
73.   int i1, o1, temp1;
74.   int number2[10];
75.   int cards2;
76.   int i2, o2, temp2;
77.   int Maxnum;
78.   int play;
79.   int a, b, c, d, e, f;
80.
81.
82.   c=0;
83.   d=0;
84.
85.   /*
86.   Card registry
87.   */
88.
89.   scanf("%d", &cards1);
90.
91.
92.   for(i1=0; i1<cards1; i1++)
93.
94.   {
95.     scanf("%d", &number1[i1], c++);
96.   }
97.
98.
99.   scanf("%d", &cards2);
100.
101.
102.   for(i2=0; i2<cards2; i2++)
103.
104.   {
105.     scanf("%d", &number2[i2], c++);
106.   }
107.
108.   /* The bubble sort for player 1, puts it in order of
109.   highest to lowest*/
110.
111.   for(i1=0; i1<cards1; i1++)
112.   {
113.     for(o1=0; o1<(cards1-i1-1); o1++)
114.     {
115.       if(number1[o1]<number1[o1+1])
116.       {
117.         temp1=number1[o1];
118.         number1[o1]=number1[o1+1];
119.         number1[o1+1]=temp1;
120.         /* Checks if Player 1 has a number lower than 1*/
121.         if(temp1 < 1)
122.         {
123.           printf("\nERRORPlayer1 can't have cards lower than 1");
124.           return 0;
125.         }
126.       }
127.     }
128.   }
129.   /* Checks to see if player 1 has a cards higher than 10*/
130.   Maxnum = number1[0];
131.   if(Maxnum > 10)
132.   {
133.     printf("\nERRORPlayer1 can't have cards higher than 10");
134.     return 0;
135.   }
136.
137.   printf("Player1's cards in order:\n");
138.   for(i1=0; i1<cards1; i1++)
139.
140.   {
141.
142.
143.     /*
144.     checks and removes null digits from printed results
145.     */
146.
147.     if(number1[i1]>0)
148.
149.     {
150.       printf("%d \f", number1[i1]);
151.     }
152.   }
153.
154.   /* The bubble sort for player 2, puts it in order of
155.   highest to lowest*/
156.
157.   for(i2=0; i2<cards2; i2++)
158.   {
159.     for(o2=0; o2<(cards2-i2-1); o2++)
160.     {
161.       if(number2[o2]<number2[o2+1])
162.       {
163.         temp2=number2[o2];
164.         number2[o2]=number2[o2+1];
165.         number2[o2+1]=temp2;
166.         /* Checks if Player 2 has a number lower than 1*/
167.         if(temp2 < 1)
168.         {
169.           printf("\nERRORPlayer2 can't have cards lower than 1");
170.           return 0;
171.         }
172.       }
173.     }
174.   }
175.   /* Checks to see if player 2 has a cards higher than 10*/
176.   Maxnum = number2[0];
177.   if(Maxnum > 10)
178.   {
179.     printf("\nERRORPlayer2 can't have cards higher than 10");
180.     return 0;
181.   }
182.   printf("\nPlayer2's cards in order:\n");
183.   for(i2=0; i2<cards2; i2++)
184.
185.   {
186.     /*
187.     checks and removes null digits from printed results
188.     */
189.
190.     if(number2[i2]>0)
191.
192.     {
193.       printf("%d \f", number2[i2]);
194.     }
195.   }
196.   d = cards1 + cards2;
197.   if(c != d)
198.   {
199.     printf("\nERROR:Players array must equal the amount of cards inputed");
200.     return 0;
201.   }
202.   if(cards2>10)
203.   {
204.     printf("\nERROR:Player2's number of cards can't exceed 10");
205.     return 0;
206.   }
207.
208.   if(cards2<2)
209.   {
210.     printf("\nERROR:Player2's number of cards can't be lower than 2");
211.     return 0;
212.   }
213.
214.   /* Chooses the largest array out of the two players
215.   as the game only needs to be played up until then
216.   instead of playing through the whole ten rounds */
217.
218.   if(cards1 > cards2)
219.   {
220.     b = cards1;
221.   }
222.   if(cards2 > cards1)
223.   {
224.     b = cards2;
225.   }
226.   if(cards1 == cards2)
227.   {
228.     b = cards1;
229.   }
230.
231.   /*Game starts and a winner is chosen, unless
232.     its a draw"*/
233.
234.   for(a = 0; a < b; a++)
235.
236.   {
237.     if(number1[a] > number2[a])
238.     {
239.       printf("\nPlayer1 wins");
240.       return 0;
241.     }
242.     if(number1[a] < number2[a])
243.     {
244.       printf("\nPlayer2 wins");
245.       return 0;
246.     }
247.   }
248.   printf("\nGame ends in a draw");
249. }