Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace KnightGame2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int boardSize = int.Parse(Console.ReadLine());
- string[,] board = new string[boardSize, boardSize];
- int[,] danger = new int[boardSize, boardSize];
- for (int i = 0; i < boardSize; i++)
- {
- string row = Console.ReadLine();
- for (int j = 0; j < boardSize; j++)
- {
- board[i, j] = row[j].ToString();
- }
- }
- //====
- int count = 8;
- int removedKnights = 0;
- int removedLowestDanger = 0;
- while (count > 0)
- {
- Evaluate(boardSize,board,danger);
- for (int y = 0; y < boardSize; y++)
- {
- for (int x = 0; x < boardSize; x++)
- {
- if (danger[y, x] == count && count > 1)
- {
- danger[y, x] = 0;
- board[y, x] = "0";
- removedKnights++;
- }
- else if (danger[y, x] == count && count == 1)
- {
- danger[y, x] = 0;
- board[y, x] = "0";
- removedKnights++;
- removedLowestDanger++;
- }
- }
- }
- //Only for displaying purposes
- //Console.WriteLine();
- //for (int y = 0; y < boardSize; y++)
- //{
- // for (int x = 0; x < boardSize; x++)
- // {
- // Console.Write(danger[y, x]);
- // }
- // Console.WriteLine();
- //}
- count--;
- }
- Console.WriteLine(removedKnights - (removedLowestDanger / 2));
- }
- public static bool IsWithin(int row, int col, int size, string[,] array)
- {
- if (row >= 0 && col >= 0 && row < size && col < size)
- {
- return true;
- }
- return false;
- }
- public static void Evaluate(int boardSize, string[,]board, int[,]danger)
- {
- for (int y = 0; y < boardSize; y++)
- {
- for (int x = 0; x < boardSize; x++)
- {
- int dangerLevel = 0;
- if (board[y, x] == "K")
- {
- bool topTopLeft = IsWithin(x - 1, y - 2, boardSize, board) && board[y - 2, x - 1] == "K";
- bool topLeftLeft = IsWithin(x - 2, y - 1, boardSize, board) && board[y - 1, x - 2] == "K";
- bool bottomLeftLeft = IsWithin(x - 2, y + 1, boardSize, board) && board[y + 1, x - 2] == "K";
- bool bottomBottomLeft = IsWithin(x - 1, y + 2, boardSize, board) && board[y + 2, x - 1] == "K";
- bool topTopRight = IsWithin(x + 1, y - 2, boardSize, board) && board[y - 2, x + 1] == "K";
- bool topRightRight = IsWithin(x + 2, y - 1, boardSize, board) && board[y - 1, x + 2] == "K";
- bool bottomRigghtRight = IsWithin(x + 2, y + 1, boardSize, board) && board[y + 1, x + 2] == "K";
- bool bottomBottomRight = IsWithin(x + 1, y + 2, boardSize, board) && board[y + 2, x + 1] == "K";
- if (topTopLeft)
- {
- dangerLevel++;
- }
- if (topLeftLeft)
- {
- dangerLevel++;
- }
- if (bottomLeftLeft)
- {
- dangerLevel++;
- }
- if (bottomBottomLeft)
- {
- dangerLevel++;
- }
- if (topTopRight)
- {
- dangerLevel++;
- }
- if (topRightRight)
- {
- dangerLevel++;
- }
- if (bottomRigghtRight)
- {
- dangerLevel++;
- }
- if (bottomBottomRight)
- {
- dangerLevel++;
- }
- danger[y, x] = dangerLevel;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment