<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.  
  3. state is a variable to track current game state
  4. state=0 still running or draw (depends on the input of cards)
  5. state=1 player 1 wins
  6. state=2 player 2 wins
  7. state=-1 input error
  8.  
  9. START
  10.    state=0
  11.    input amount of cards for player 1
  12.    FOR amount of cards for player 1
  13.       input number of card for player 1
  14.    END FOR
  15.    
  16.    IF amount of cards for player 1 between 2 and 10
  17.       THEN
  18.          PRINT amount of cards for player 1
  19.          SORT player 1 cards in descending order
  20.          
  21.          PRINT player 1 has the cards:
  22.          FOR amount of cards for player 1
  23.             IF player 1 card is between 1 and 10
  24.                THEN
  25.                   PRINT the card
  26.                ELSE
  27.                   PRINT invalid card !needs to be from 1-10
  28.             END IF
  29.          END FOR
  30.          
  31.       ELSE
  32.          PRINT oops! player 1 will need to have  from 2 - 10 cards in their hand to play this game
  33.          state=-1
  34.    END IF
  35.  
  36.  
  37.    input amount of cards for player 2
  38.    FOR amount of cards for player 2
  39.       input number of card for player 2
  40.    END FOR
  41.    
  42.    IF amount of cards for player 2 between 2 and 10
  43.       THEN
  44.          PRINT amount of cards for player 2
  45.          SORT player 2 cards in descending order
  46.          
  47.          PRINT player 2 has the cards:
  48.          FOR amount of cards for player 2
  49.             IF player 2 card is between 1 and 10
  50.                THEN
  51.                   PRINT the card
  52.                ELSE
  53.                   PRINT invalid card !needs to be from 1-10
  54.             END IF
  55.          END FOR
  56.          
  57.       ELSE
  58.          PRINT oops! player 2 will need to have  from 2 - 10 cards in their hand to play this game
  59.          state=-1
  60.    END IF
  61.    
  62.    
  63.    SET min to least amount of cards for both players
  64.    FOR min amount of cards
  65.       IF amount of cards for both players are in range and numbers on cards are within range
  66.          THEN
  67.             IF cards for both players are NOT equal
  68.                THEN
  69.                   PRINT cards are not equal
  70.                   IF player 1 has bigger card than player 2
  71.                      THEN
  72.                         state=1
  73.                         BREAK the loop
  74.                   END IF
  75.                   IF player 2 has bigger card than player 1
  76.                      THEN
  77.                         state=2
  78.                         BREAK the loop
  79.                   END IF
  80.                ELSE
  81.                   PRINT cards are equal, look for next card
  82.                  
  83.             END IF
  84.          ELSE
  85.             state=-1
  86.             BREAK the loop
  87.       END IF
  88.    END FOR
  89.    
  90.    
  91.    IF state = 0
  92.       THEN
  93.          IF both players amount of cards are equal(considering that all previous numbers on cards compared are equal)
  94.             THEN
  95.                PRINT All cards are equal
  96.                PRINT DRAW
  97.          END IF
  98.          
  99.          IF player 1 number of cards are more than player 2 number of cards
  100.             THEN
  101.                state=1
  102.                PRINT all previous cards are equal, whoever has more cards will win
  103.          END IF
  104.          
  105.          IF player 2 number of cards are more than player 1 number of cards
  106.             THEN
  107.                state=2
  108.                PRINT all previous cards are equal, whoever has more cards will win
  109.          END IF
  110.    END IF
  111.    
  112.    IF state = 1
  113.       THEN
  114.          PRINT player 1 wins
  115.    END IF
  116.    
  117.    
  118.    IF state = 2
  119.       THEN
  120.          PRINT player 2 wins
  121.    END IF
  122.    
  123.    IF state = -1
  124.       THEN
  125.          PRINT fix the error to start comparing cards
  126.    END IF
  127. END
  128.  
  129. */
  130.  
  131. #include<stdio.h>
  132. int main( void )
  133. {
  134. /*we assign all the values for the game */
  135.     int amount_of_cards_p1 ;
  136.     int amount_of_cards_p2 ;
  137.     int number_on_the_card_p1[10];
  138.     int number_on_the_card_p2[10];
  139.     int t, j ,d ;
  140.     int min;
  141.     int state=0;
  142. /* we limit the amount of cards in each players hand from 2 - 10 cards for player 1 using if condition */
  143.      scanf("%d" , &amount_of_cards_p1) ;
  144.  
  145.          {
  146.         for (t=0; t<amount_of_cards_p1; t++)
  147.    
  148.       scanf( "%d",&number_on_the_card_p1[t]);
  149.       }
  150.     {
  151.      if (amount_of_cards_p1 <=10  && amount_of_cards_p1 >=2) {
  152.       printf(" amount of cards  for player 1 is %d cards \n", amount_of_cards_p1) ;
  153.    
  154.    /*we use an array and for condition  to hold 10 numbers on the cards in hand (1-10) */
  155.      
  156.  
  157.    /*we use arrays-if-for conditions to sort the number on the card in descending order*/
  158.   for(t=0; t< amount_of_cards_p1; t++)
  159.    
  160.    
  161.    
  162.         for(j=t+1; j< amount_of_cards_p1; j++)
  163.      
  164.  
  165.         {
  166.             if(number_on_the_card_p1[t] < number_on_the_card_p1[j])
  167.             {
  168.                 d = number_on_the_card_p1[t];
  169.                 number_on_the_card_p1[t] = number_on_the_card_p1[j];
  170.                 number_on_the_card_p1[j] = d;
  171.             }
  172.         }
  173.    
  174.      
  175.   printf("player 1 has the cards:\n ");
  176.     for(t=0; t< amount_of_cards_p1 ; t++)
  177.              
  178.    {
  179.      if (number_on_the_card_p1[t]<=10  && number_on_the_card_p1[t] >=1) {
  180.  
  181.     {
  182.        
  183.         printf("|%d|", number_on_the_card_p1[t]);
  184.     }
  185.    
  186.            }
  187.          
  188.     else printf (" |invalid card !needs to be from 1-10|") ;
  189.    
  190.    
  191.     } 
  192.     }
  193.     else
  194.     {
  195.     printf ("\noops! player 1 will need to have  from 2 - 10 cards in their hand to play this game\n") ;
  196.     state=-1;
  197.     }
  198.    
  199.    
  200.     }
  201.  
  202.     /* we limit the amount of cards in each players hand from 2 - 10 cards for player 2 using if condition */
  203.          scanf("%d" , &amount_of_cards_p2) ;
  204.     {
  205.      if (amount_of_cards_p2 <=10  && amount_of_cards_p2 >=2) {
  206.       printf(" \namount of cards  for player 2 is %d cards \n", amount_of_cards_p2) ;
  207.    
  208.    /*we use an array and for condition  to hold 10 numbers on the cards in hand (1-10) */
  209.      for (t=0; t<amount_of_cards_p2; t++)
  210.    
  211.       scanf( "%d",&number_on_the_card_p2[t]);
  212.  
  213.    /*we use arrays-if-for conditions to sort the number on the card in descending order*/
  214.   for(t=0; t< amount_of_cards_p2; t++)
  215.    
  216.    
  217.    
  218.         for(j=t+1; j< amount_of_cards_p2; j++)
  219.      
  220.  
  221.         {
  222.             if(number_on_the_card_p2[t] < number_on_the_card_p2[j])
  223.             {
  224.                 d = number_on_the_card_p2[t];
  225.                 number_on_the_card_p2[t] = number_on_the_card_p2[j];
  226.                 number_on_the_card_p2[j] = d;
  227.             }
  228.         }
  229.    
  230.      
  231.   printf("player 2 has the cards:\n ");
  232.     for(t=0; t< amount_of_cards_p2 ; t++)
  233.              
  234.    {
  235.      if (number_on_the_card_p2[t]<=10  && number_on_the_card_p2[t] >=1) {
  236.  
  237.     {
  238.        
  239.         printf("|%d|", number_on_the_card_p2[t]);
  240.     }
  241.    
  242.            }
  243.          
  244.     else printf ("|please input a valid card , from 1-10|") ;
  245.    
  246.    
  247.     } 
  248.     }
  249.     else
  250.     {
  251.     printf ("\noops! player 2 will need to have  from 2 - 10 cards in their hand to play this game\n") ;
  252.     state=-1;
  253.     }
  254.    
  255.    
  256.    
  257.     }
  258.     /*comparing cards */
  259.       {
  260.      
  261.       min = amount_of_cards_p1;
  262.       if (min > amount_of_cards_p2) min = amount_of_cards_p2 ;
  263. printf("\n Comparing cards :");
  264.       for(t=0; t<min ; t++)
  265.      
  266.      if ((amount_of_cards_p1 <=10  && amount_of_cards_p1 >=2)&& (amount_of_cards_p2 <=10  && amount_of_cards_p2 >=2) &&(number_on_the_card_p1[t]<=10  && number_on_the_card_p1[t] >=1)&&(number_on_the_card_p2[t]<=10  && number_on_the_card_p2[t] >=1))
  267.      {
  268.      
  269.              if (number_on_the_card_p1[t] != number_on_the_card_p2[t]) {
  270.      printf("\n cards not equal") ;
  271.  
  272.      if (number_on_the_card_p1[t] > number_on_the_card_p2[t])
  273.      { state =1 ;
  274.    
  275.      break ;
  276.      }
  277.    
  278.      if (number_on_the_card_p1[t] < number_on_the_card_p2[t])
  279.      { state =2 ;
  280.      break ;
  281.      }
  282.    
  283.     }
  284.    
  285.      else if (number_on_the_card_p1[t] == number_on_the_card_p2[t]) {
  286.      printf("\n cards are equal ") ;
  287.       if (t!= min -1 )
  288.     printf(", look for next card ");
  289.      }
  290.    
  291.      }
  292.      else
  293.      {
  294.      state=-1;
  295.      break;
  296.      }
  297.      if (state==0)   
  298.      {
  299.      if (amount_of_cards_p1 == amount_of_cards_p2)
  300.      printf ("\n All cards are equal \n DRAW ");
  301.      else if (amount_of_cards_p1 > amount_of_cards_p2)
  302.      {
  303.      state=1;
  304.         printf ("\n all previous cards are equal, whoever has more cards will win");
  305.      }
  306.      
  307.      else if (amount_of_cards_p1 < amount_of_cards_p2)
  308.      {
  309.      state=2;
  310.         printf ("\n all previous cards are equal, whoever has more cards will win");
  311.         }
  312.      }
  313.      if (state == 1 )
  314.      printf("\nplayer 1 wins") ;
  315.      
  316.         if (state == 2 )
  317.      printf("\nplayer 2 wins") ;
  318.      }
  319.  
  320.    if (state==-1)
  321.    {
  322.     printf("\nfix the error to start comparing cards");
  323.    }
  324.    
  325. return 0;
  326. }