Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace AngryBits
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] grid = new int[8, 16];
- bool noHit = true;
- bool movingUp = true;
- int rowThrow, colThrow;
- int endOfFlight = 0;
- int pigs = 0;
- int score = 0;
- string win = "Yes";
- for (int rows = 0; rows < 8; rows++)
- {
- int N = int.Parse(Console.ReadLine());
- char[] charArray = Convert.ToString(N, 2).ToCharArray();
- int columns = charArray.Length - 1;
- foreach (char bits in charArray)
- {
- grid[rows, columns] = bits - '0';
- columns--;
- }
- }
- //SEARCH FOR A BIRD FROM RIGHT TO LEFT
- for (int cols = 8; cols <= 15; cols++)
- {
- for (int rows = 0; rows < 8; rows++)
- {
- rowThrow = rows;
- colThrow = cols;
- endOfFlight = 0;
- pigs = 0;
- noHit = true;
- movingUp = true;
- //Check for a bird every single cell
- if (grid[rowThrow, colThrow] == 1)
- {
- //we are throwing the bird and making it a zero
- grid[rowThrow, colThrow] = 0;
- while (noHit)
- {
- if (rowThrow == 0)
- {
- movingUp = false;
- }
- else if (rowThrow == 7)
- {
- movingUp = true;
- }
- if (movingUp == true)
- {
- rowThrow--;
- }
- else
- {
- //solve for OutOfRange
- if (rowThrow <= 6)
- {
- rowThrow++;
- }
- }
- if (colThrow > 0)
- {
- colThrow--;
- }
- else
- {
- noHit = false;
- }
- endOfFlight++;
- if (grid[rowThrow, colThrow] == 1)
- {
- pigs++;
- grid[rowThrow, colThrow] = 2;
- int pigsRow = 0;
- if (rowThrow - 1 >= 0)
- {
- pigsRow = rowThrow - 1;
- }
- else
- {
- pigsRow = rowThrow;
- }
- int pigsCol;
- pigsCol = colThrow + 1;
- for (int i = 0; i < (pigsRow == rowThrow ? 2 : 3) && pigsRow + i <= 7; i++)
- {
- for (int j = 0; j < 3 && pigsCol - j >= 0; j++)
- {
- if (grid[pigsRow + i, pigsCol - j] == 1)
- {
- pigs++;
- grid[pigsRow + i, pigsCol - j] = 0;
- }
- }
- }
- noHit = false;
- }
- grid[rowThrow, colThrow] = 2;
- //stop when hit the end ot the bottom of the grid
- if (colThrow == 0 || rowThrow == 7)
- {
- noHit = false;
- }
- }
- score += (endOfFlight * pigs);
- }
- }
- }
- for (int i = 0; i < 8; i++)
- {
- for (int j = 8; j >= 0; j--)
- {
- if (grid[i, j] == 1)
- {
- win = "No";
- break;
- }
- }
- }
- Console.Write("{0} {1}", score, win);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement