vonko1988

c#Angry_Bitsver3

Apr 30th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. using System;
  2.  
  3. class AngryBits
  4. {
  5.     static void Main()
  6.     {
  7.         int[,] startArray = new int[8, 16];
  8.  
  9.         //Now we will fill the matrix with the given bits
  10.  
  11.         for (int i = 0; i < 8; i++)
  12.         {
  13.             int input = int.Parse(Console.ReadLine());
  14.  
  15.             for (int j = 15; j >= 0; j--)
  16.             {
  17.                 int bit = (input >> j) & 1;
  18.                 startArray[i, 15 - j] = bit;
  19.             }
  20.         }
  21.  
  22.         //for (int i = 0; i < 8; i++)
  23.         //{
  24.         //    for (int j = 0; j < 16; j++)
  25.         //    {
  26.         //        Console.Write(startArray[i, j] + " ");
  27.         //    }
  28.         //    Console.WriteLine();
  29.         //}
  30.  
  31.         //Now we will throw the birds
  32.         int center = 7;
  33.         string direction = "topLeft";
  34.         int x = 0;
  35.         int y = 0;
  36.         int numberHitPigs = 0;
  37.         int points = 0;
  38.  
  39.         for (int col = center; col >= 0; col--)
  40.         {
  41.             for (int row = 0; row < 8; row++)
  42.             {
  43.                 if (startArray[row, col] == 1)
  44.                 {
  45.                     startArray[row, col] = 0;
  46.  
  47.                     //here the bird will start flying
  48.                     y = row;
  49.                     x = col;
  50.                     direction = "topRight";
  51.  
  52.                     for (int i = x+1; i <=15; i++)
  53.                     {
  54.                         switch (direction)
  55.                         {
  56.                             case "topRight":
  57.                                 if (y > 0)
  58.                                 {
  59.                                     x++;
  60.                                     y--;
  61.                                 }
  62.                                 else if (y == 0)
  63.                                 {
  64.                                     x++;
  65.                                     y++;
  66.                                     direction = "bottomRight";
  67.                                 }
  68.                                 break;
  69.  
  70.                             case "bottomRight":
  71.                                 if (y < 7)
  72.                                 {
  73.                                     x++;
  74.                                     y++;
  75.                                 }
  76.                                 else if (y == 7)
  77.                                 {
  78.                                     x++;
  79.                                     y--;
  80.                                     direction = "topRight";
  81.                                 }
  82.                                 break;
  83.                         }
  84.  
  85.                         if (startArray[y, x] == 1 && x > center)
  86.                         {
  87.                             numberHitPigs = 1;
  88.                             //Console.WriteLine("hit");
  89.                             //Console.WriteLine("flightCounter : {0}", (x-col));
  90.                             //Console.WriteLine("{0},{1}", y, x);
  91.                             startArray[y, x] = 0;
  92.  
  93.                             for (int k = y - 1; k < (y - 1 + 3); k++)
  94.                             {
  95.                                 for (int m = x - 1; m < (x - 1 + 3); m++)
  96.                                 {
  97.                                     if ((k >= 0 && k <= 7 && m >= center + 1 && m <= 15) &&
  98.                                         (startArray[k, m] == 1))
  99.                                     {
  100.                                         numberHitPigs++;
  101.                                         //Console.WriteLine("hit");
  102.                                         //Console.WriteLine("{0},{1}", k, m);
  103.                                         startArray[k, m] = 0;
  104.                                     }
  105.                                 }
  106.                             }
  107.  
  108.                             points += (x-col) * numberHitPigs;
  109.                             break;
  110.                         }
  111.                     }
  112.                 }
  113.             }
  114.         }
  115.  
  116.         //now we check if the player won
  117.  
  118.         string win = "Yes";
  119.  
  120.         for (int j = center + 1; j <= 15; j++)
  121.         {
  122.             for (int i = 0; i < 8; i++)
  123.             {
  124.                 if (startArray[i, j] == 1)
  125.                 {
  126.                     win = "No";
  127.                 }
  128.             }
  129.         }
  130.  
  131.         Console.WriteLine(points + " " + win);
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment