Advertisement
CuST0M1z3

CardWars

Jun 26th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. class Program
  9. {
  10.     static void Main()
  11.     {
  12.         int games = int.Parse(Console.ReadLine());
  13.  
  14.         int cards = games * 6;
  15.  
  16.         string[] input = new string[cards];
  17.  
  18.         for (int i = 0; i < cards; i++)
  19.         {
  20.             input[i] = Console.ReadLine();
  21.         }
  22.  
  23.         int gameCount = 0;
  24.  
  25.         int[] array = new int[cards];
  26.  
  27.         for (int i = 0; i < cards; i++)
  28.         {
  29.             switch (input[i])
  30.             {
  31.                 case "2": array[i] = 10;
  32.                     break;
  33.                 case "3": array[i] = 9;
  34.                     break;
  35.                 case "4": array[i] = 8;
  36.                     break;
  37.                 case "5": array[i] = 7;
  38.                     break;
  39.                 case "6": array[i] = 6;
  40.                     break;
  41.                 case "7": array[i] = 5;
  42.                     break;
  43.                 case "8": array[i] = 4;
  44.                     break;
  45.                 case "9": array[i] = 3;
  46.                     break;
  47.                 case "10": array[i] = 2;
  48.                     break;
  49.                 case "J": array[i] = 11;
  50.                     break;
  51.                 case "Q": array[i] = 12;
  52.                     break;
  53.                 case "K": array[i] = 13;
  54.                     break;
  55.                 case "A": array[i] = 1;
  56.                     break;
  57.                 case "Z": array[i] = 20;
  58.                     break;
  59.                 case "Y": array[i] = 30;
  60.                     break;
  61.                 case "X": array[i] = 40;
  62.                     break;
  63.             }
  64.         }
  65.  
  66.         BigInteger playerOneScore = 0;
  67.         BigInteger playerTwoScore = 0;
  68.  
  69.         BigInteger playerOneGameScore = 0;
  70.         BigInteger playerTwoGameScore = 0;
  71.  
  72.         int cardcount = 0;
  73.  
  74.         int gamesWon1 = 0;
  75.         int gamesWon2 = 0;
  76.  
  77.         int oneHaveX = 0;
  78.         int twoHaveX = 0;
  79.         int onezCount = 0;
  80.         int oneyCount = 0;
  81.         int twozCount = 0;
  82.         int twoyCount = 0;
  83.  
  84.         int j = 0;
  85.  
  86.         for (int i = 1; i <= games; i++)
  87.         {
  88.             cardcount = i * 6;
  89.             playerOneScore = 0;
  90.             playerTwoScore = 0;
  91.             oneHaveX = 0;
  92.             twoHaveX = 0;
  93.             onezCount = 0;
  94.             twozCount = 0;
  95.             oneyCount = 0;
  96.             twoyCount = 0;
  97.             while ((gameCount < (cardcount)) && (j < cardcount))
  98.             {
  99.                 if (j < cardcount - 3)
  100.                 {
  101.                     if (array[j] < 20)
  102.                     {
  103.                         playerOneScore += array[j];
  104.                     }
  105.                     else if (array[j] == 20)
  106.                     {
  107.                         onezCount++;
  108.                        
  109.                     }
  110.                     else if (array[j] == 30)
  111.                     {
  112.                         oneyCount++;
  113.                        
  114.                     }
  115.                     else if (array[j] == 40)
  116.                     {
  117.                         oneHaveX = 1;
  118.                     }
  119.                 }
  120.                 else
  121.                 {
  122.                     if (array[j] < 20)
  123.                     {
  124.                         playerTwoScore += array[j];
  125.                     }
  126.                     else if (array[j] == 20)
  127.                     {
  128.                         twozCount++;
  129.                        
  130.                     }
  131.                     else if (array[j] == 30)
  132.                     {
  133.                         twoyCount++;
  134.                     }
  135.                     else if (array[j] == 40)
  136.                     {
  137.                         twoHaveX = 1;
  138.                     }
  139.                 }
  140.                 j++;
  141.  
  142.             }
  143.             if (oneyCount >= 1)
  144.             {
  145.                 playerOneGameScore -= (oneyCount * 200);
  146.             }
  147.             if (onezCount >= 1)
  148.             {
  149.                 playerOneGameScore *= ((int)Math.Pow(2, onezCount));
  150.             }
  151.             if (twoyCount >= 1)
  152.             {
  153.                 playerTwoGameScore -= (twoyCount * 200);
  154.             }
  155.             if (twozCount >= 1)
  156.             {
  157.                 playerTwoGameScore *= ((int)Math.Pow(2, twozCount));
  158.             }
  159.            
  160.            
  161.             if (((oneHaveX != 0) && (twoHaveX != 0)) && (oneHaveX == twoHaveX))
  162.             {
  163.                 playerOneGameScore += 50;
  164.                 playerTwoGameScore += 50;
  165.             }
  166.             else if (((oneHaveX != 0) || (twoHaveX != 0)) && (oneHaveX != twoHaveX))
  167.             {
  168.                 if ((oneHaveX != 0) && (oneHaveX > twoHaveX))
  169.                 {
  170.                     Console.WriteLine("X card drawn! Player one wins the match!");
  171.                     break;
  172.                 }
  173.                 else if((twoHaveX != 0) && (twoHaveX > oneHaveX))
  174.                 {
  175.                     Console.WriteLine("X card drawn! Player two wins the match!");
  176.                     break;
  177.                 }
  178.             }
  179.            
  180.             gameCount += 6;
  181.  
  182.             if (playerOneScore > playerTwoScore)
  183.             {
  184.                 gamesWon1++;
  185.                 playerOneGameScore += playerOneScore;
  186.             }
  187.             else if (playerTwoScore > playerOneScore)
  188.             {
  189.                 gamesWon2++;
  190.                 playerTwoGameScore += playerTwoScore;
  191.             }
  192.             else if (playerOneScore == playerTwoScore)
  193.             {
  194.                 playerOneScore = 0;
  195.                 playerTwoScore = 0;
  196.             }
  197.         }
  198.         if (oneHaveX == twoHaveX)
  199.         {
  200.             if (playerOneGameScore > playerTwoGameScore)
  201.             {
  202.                 Console.WriteLine("First player wins!");
  203.                 Console.WriteLine("Score: " + playerOneGameScore);
  204.                 Console.WriteLine("Games won: " + gamesWon1);
  205.             }
  206.             else if (playerTwoGameScore > playerOneGameScore)
  207.             {
  208.                 Console.WriteLine("Second player wins!");
  209.                 Console.WriteLine("Score: " + playerTwoGameScore);
  210.                 Console.WriteLine("Games won: " + gamesWon2);
  211.             }
  212.             else if (playerOneGameScore == playerTwoGameScore)
  213.             {
  214.                 Console.WriteLine("It's a tie!");
  215.                 Console.WriteLine("Score: " + playerOneGameScore);
  216.             }
  217.         }  
  218.     }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement