Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Bittris
- {
- static void Main()
- {
- int rounds = int.Parse(Console.ReadLine());
- int[] playField = new int[4];
- int score = 0;
- int points = 0;
- int line = 0;
- int mask = 255;
- bool noCollision = true;
- for (int turn = 0; turn < rounds; turn++)
- {
- string input = Console.ReadLine();
- int turnRemainder = turn % 4;
- if (turnRemainder == 0) //Time for a new number?
- {
- noCollision = true;
- int number = int.Parse(input);
- line = number;
- while (number != 0)
- {
- if ((number & 1) == 1)
- {
- points++;
- }
- number >>= 1;
- }
- }
- else if (noCollision) //Can we move?
- {
- if (input == "L" && (line & 128) != 128) //Left
- {
- line <<= 1;
- }
- else if (input == "R" && (line & 1) != 1) //Right
- {
- line >>= 1;
- }
- if ((playField[turnRemainder] & line) == 0) //Is the next line clear?
- {
- if (turnRemainder == 3)
- {
- if ((playField[turnRemainder] + line) == mask)
- {
- score += (points * 10);
- for (int i = turnRemainder; i > 0; i--)
- {
- playField[i] = playField[i - 1];
- }
- playField[0] = 0;
- }
- else
- {
- score += points;
- playField[turnRemainder] |= line;
- }
- points = 0;
- }
- }
- else //Next line is already occupied
- {
- if ((playField[turnRemainder - 1] + line) == mask)
- {
- for (int i = turnRemainder - 1; i > 0; i--)
- {
- playField[i] = playField[i - 1];
- }
- score += (points * 10);
- playField[0] = 0;
- }
- else
- {
- playField[turnRemainder - 1] |= line;
- score += points;
- }
- points = 0;
- noCollision = false;
- }
- }
- }
- Console.WriteLine(score);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement