<mosaic.cnfolio.com>
PROGRAM
  1. /* psuedo woodo
  2.     Start
  3.     Obatin input of player 1
  4.        Validate input for player 1
  5.     Obtain input of player 2
  6.        Validate input for player 2
  7.     Sort values high-low for player 1
  8.     Sort values high-low for player 2
  9.     While Players have cards in hand
  10.     Compare the highest values of both players
  11.        IF A Larger than B, then A Winner
  12.        ELSE IF B Larger than A, then B Winner
  13.        ELSE IF A = B, move onto next sets of values
  14.       Test next group of cards
  15.        IF no cards remaining = Draw
  16.     End While
  17.     End
  18.     */
  19.      
  20.     #include <stdio.h>
  21.      
  22.     /*codowoodo*/
  23.      
  24.     int main(void)
  25.     {
  26.      
  27.     /* Variables for input */
  28.      
  29.     int i; /* Variable used for player 1s array*/
  30.     int Player1Size = 0; /* player1 hand size, this will be used to define the size of the array*/
  31.     int Player1Hand[10] = {0}; /* Defining player 1's hand, the arary will be sized to the maximum value and any "none used" values will be left as 0 for the comparison stage */
  32.      
  33.     int j; /* Variable to define player 2s array*/
  34.     int Player2Size = 0; /*player 2 hand size, used to define the size of the array to store cards */
  35.     int Player2Hand[10] = {0}; /*Defining the array storing the cards, the array is sized to the maximum possible hand size and any "unused" values will be left as a zero value for the comparison */
  36.      
  37.     /* Hand Input for both players */   
  38.        scanf("%d", &Player1Size)/* Taking player 1s hand size*/
  39.          if(Player1Size < 2) { /* Checking if the player hand is too small */
  40.          printf("ERROR, Player 1 Hand size is too small, enter a value above 1");
  41.          return 0; }
  42.          if(Player1Size > 10) { /* Checking if the player hand is too large */
  43.          printf("ERROR, Player 1 Hand size is too large, enter a value below 10");
  44.          return 0;}
  45.        for (i = 0; i < Player1Size; i++) {/* Inputing values into the array until the number of cards equal to the handsize recorded is met */
  46.           scanf("%d", &Player1Hand[i]); /* Taking player 1s card values*/
  47.             if(Player1Hand[i] < 1) { /*Checking if the inputted values into player 1's hand array are valid*/
  48.             printf("ERROR, a card in player 1's hand is below the accepted range, please enter a value above 0.");
  49.             return 0; }
  50.             if(Player1Hand[i] > 10) { /*Checking if the inputted values into player 1's hand array are valid*/
  51.             printf("ERROR, a card in player 1's hand is above the accepted range, please enter a value below 11.");
  52.             return 0; }
  53.        }
  54.        scanf("%d", &Player2Size); /* Taking player 2s hand size*/
  55.          if(Player2Size < 2){ /* Checking if player 2s hand size is in the valid range for accepted values, if this statement is true an error message will be displayed to the user*/
  56.             printf("ERROR, Player 2 Hand size is too small, enter a value above 1");
  57.             return 0; }
  58.          if(Player2Size > 10){
  59.             printf("ERROR, Player 2 Hand size is too large, enter a value below 11");
  60.             return 0; }
  61.        for (j = 0; j < Player2Size; j++) {/* Inputing values into the array until the the number of cards equal to the players hand size is met */
  62.           scanf("%d", &Player2Hand[j]); /* Taking player 2s card values*/
  63.             if(Player2Hand[j] < 1) { /* Checking if the cards in player 2's hand are in the accepted range, if this "if" statement is true it will produce a relevent error message*/
  64.                printf("ERROR, a card in player 2's hand is below the accepted range, please enter a value above 0.");
  65.                return 0; }
  66.             if(Player2Hand[j] > 10) {
  67.                printf("ERROR, a card in player 2's hand is above the accepted range, please enter a value below 11.");
  68.                return 0; }
  69.        }   
  70.      
  71.     /* Testing for Input
  72.      
  73.     ~~~Tempory test to see if player 1 hand is being recorded~~~
  74.     printf("%d \n" , Player1Size);
  75.     for(i =0; i < Player1Size; i++) {
  76.        printf("%d ", Player1Hand[i]);
  77.     }
  78.     ~~~Tempory test to check recording player 2s hand is being recorded~~~
  79.     printf("\n%d \n", Player2Size);
  80.        for (j =0; j < Player2Size; j++) {
  81.        printf("%d ", Player2Hand[j]);
  82.     }
  83.     End of Input Testing */
  84.      
  85.     /* Sorting Section */
  86.     int a, b; /*asigning variables which will be used in sorting of values in each players hand */
  87.     {
  88.        for(i=0; i<Player1Size; i++) /* sets player 1 array into the first position and subsequent tests will move along the array by one position each time */
  89.           {
  90.           for(a=i+1; a<Player1Size; a++) /* sets a to the position after i in the array and will move the array along one point until the array reaches the final point */
  91.              {
  92.              if(Player1Hand[i] < Player1Hand[a]) /* checks if a is larger than i, as i comes first in the array it needs to be larger */
  93.                 {
  94.                    b  = Player1Hand[i]; /* copies the value of i into the temporary variable b */
  95.                    Player1Hand[i] = Player1Hand[a]; /* copies the value from a into i moving the larger value over to the left one in hte array */
  96.                    Player1Hand[a] = b; /* copies the value from b back to the array now in position a so that it has been moved over one to the right from its position at the beginning of this test itteration */
  97.                 }
  98.               } /* repreates the above process until all cards have been tested by moving the array to its fianl position and having moved to their required points */
  99.            }
  100.     {
  101.        for(j=0; j<Player2Size; j++) /* Similar concept to the above code, just will values changed for player 2 and its array */
  102.           {
  103.           for(a=j+1; a<Player2Size; a++)
  104.              {
  105.              if(Player2Hand[j] < Player2Hand[a])
  106.                 {
  107.                    b  = Player2Hand[j];
  108.                    Player2Hand[j] = Player2Hand[a];
  109.                    Player2Hand[a] = b;
  110.                 }
  111.               }
  112.            }
  113.     /* Testingoutput post sorting system
  114.     printf("Player 1 has %d cards in their hand: \n" , Player1Size);
  115.     for(i =0; i < Player1Size; i++) {
  116.        printf("%d ", Player1Hand[i]);
  117.     }
  118.     printf("\nPlayer 2 has %d cards in their hand: \n", Player2Size);
  119.        for (j =0; j < Player2Size; j++) {
  120.        printf("%d ", Player2Hand[j]);
  121.     }
  122.    
  123.     End test    */
  124.    
  125.     }
  126.     }
  127.     /* Comparison */
  128. int roundlimit; /* creating a round counter to be used in the comparison to limit the number of rounds */
  129. int currentround = 0; /* sets a counter that will be used in the comparison to allow for limiting number of tests*/
  130.  
  131. if(Player1Size > Player2Size) { /*tests which hand is larger and if player 1 has the larger hand sets that hand size as the round limit*/
  132.    (roundlimit = Player1Size);
  133.    }
  134. else if(Player1Size < Player2Size) { /*tests which hand is larger and if player 2 has the larger hand sets that hand size as the round limit*/
  135.    (roundlimit = Player2Size);
  136.    }
  137. else if(Player1Size = Player2Size) { /* tests which hand is larger, if both are the same size, it sets player 1 hand as round limit as the values are equal*/
  138.    (roundlimit = Player1Size);   
  139.    }
  140.  
  141. (i=0, Player1Hand[i]); /*sets player 1's hand/array to the largest card/first position for the first round of testing */
  142. (j=0, Player2Hand[j]); /* sets player 2's hand/array to the largetst card/first position for the first round of testing */
  143.      
  144. do {
  145.          if (Player1Hand[i] > Player2Hand[j]) { /*tests if player 1 is larger than 2, if this statement is true Player 1 wins the game and this result is outputted */
  146.             printf("Player 1 Wins");
  147.             return 0; }
  148.          if (Player1Hand[i] < Player2Hand[j]) { /*tests if player 2 has won the game by having a larger value than player 1, if this statement is true the program will end with a victory message for player 2 */
  149.             printf("Player 2 Wins");
  150.             return 0; }
  151.          if (Player1Hand[i] = Player2Hand[j]) { /* tests if both players have the same card value if true: */
  152.             currentround++;                     /* adds 1 to the round counter variable */
  153.             (i++, Player1Hand);            /* moves player 1's array to the next position */
  154.             (j++, Player2Hand); }               /* moves player 2's array to the next position */
  155.     }               
  156.     while(currentround < roundlimit);        /*checks if current round is less than the round limit, if true there will be another round of testing*/
  157.       if(currentround = roundlimit) {    /*If current round = round limit than both hands have been exhausted from consecutive draws and the game ends as a draw*/
  158.         printf("Draw");                /*Outputs the Draw message and ends the program*/
  159.           return 0;}
  160. /*end codowoodo*/
  161.     }