vonko1988

c#Angry_Bitsver4

May 5th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.51 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 rows = 0; rows < 8; rows++)
  12.         {
  13.             int input = int.Parse(Console.ReadLine());
  14.  
  15.             for (int cols = 15; cols >= 0; cols--)
  16.             {
  17.                 int bit = (input >> cols) & 1;
  18.                 startArray[rows, 15 - cols] = 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.  
  51.                     if (y != 0)
  52.                     {
  53.                         direction = "topRight";
  54.                     }
  55.                     else
  56.                     {
  57.                         direction = "bottomRight";
  58.                     }
  59.  
  60.                     for (int flightPath = x + 1; flightPath <= 15; flightPath++)
  61.                     {
  62.                         switch (direction)
  63.                         {
  64.                             case "topRight":
  65.                                 if (y > 0)
  66.                                 {
  67.                                     x++;
  68.                                     y--;
  69.                                 }
  70.                                 else if (y == 0)
  71.                                 {
  72.                                     x++;
  73.                                     y++;
  74.                                     direction = "bottomRight";
  75.                                 }
  76.                                 break;
  77.  
  78.                             case "bottomRight":
  79.                                 if (y < 7)
  80.                                 {
  81.                                     x++;
  82.                                     y++;
  83.                                 }
  84.                                 else if (y == 7)
  85.                                 {
  86.                                     x++;
  87.                                     y--;
  88.                                     direction = "topRight";
  89.                                 }
  90.                                 break;
  91.                         }
  92.  
  93.                         if (startArray[y, x] == 1 && x > center)
  94.                         {
  95.                             numberHitPigs = 1;
  96.                             //Console.WriteLine("hit");
  97.                             //Console.WriteLine("flightCounter : {0}", (x-col));
  98.                             //Console.WriteLine("{0},{1}", y, x);
  99.                             startArray[y, x] = 0;
  100.  
  101.                             for (int k = y - 1; k < (y - 1 + 3); k++)
  102.                             {
  103.                                 for (int m = x - 1; m < (x - 1 + 3); m++)
  104.                                 {
  105.                                     if ((k >= 0 && k <= 7 && m >= center + 1 && m <= 15) &&
  106.                                         (startArray[k, m] == 1))
  107.                                     {
  108.                                         numberHitPigs++;
  109.                                         //Console.WriteLine("hit");
  110.                                         //Console.WriteLine("{0},{1}", k, m);
  111.                                         startArray[k, m] = 0;
  112.                                     }
  113.                                 }
  114.                             }
  115.  
  116.                             points += (x-col) * numberHitPigs;
  117.                             break;
  118.                         }
  119.                     }
  120.                 }
  121.             }
  122.         }
  123.  
  124.         //now we check if the player won
  125.  
  126.         string win = "Yes";
  127.  
  128.         for (int j = center + 1; j <= 15; j++)
  129.         {
  130.             for (int i = 0; i < 8; i++)
  131.             {
  132.                 if (startArray[i, j] == 1)
  133.                 {
  134.                     win = "No";
  135.                 }
  136.             }
  137.         }
  138.  
  139.         Console.WriteLine(points + " " + win);
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment