using System.Collections.Generic;
using System.Threading.Tasks;
public static List<string> buffering = new List<string>();
public static void Main()
int[,] arr = { { 1,1,2,2,2,2 }, { 2,1,1,2,2,2 } };
List<string> testResult = returnListDamage(arr, 1);
foreach (string x in testResult)
public static bool[] findOtherPosition(int x, int y, int[,] arr, int color)
bool[] arrayPosition = { false, false, false, false };
arrayPosition[1] = color.Equals(arr[x, y + 1]);
arrayPosition[0] = color.Equals(arr[x, y - 1]);
arrayPosition[0] = color.Equals(arr[x, y - 1]);
arrayPosition[1] = color.Equals(arr[x, y + 1]);
arrayPosition[3] = color.Equals(arr[x + 1, y]);
arrayPosition[2] = color.Equals(arr[x - 1, y]);
arrayPosition[2] = color.Equals(arr[x - 1, y]);
arrayPosition[3] = color.Equals(arr[x + 1, y]);
public static void checkCrush(int x, int y, int[,] arr, int color) {
bool[] ps = findOtherPosition(x, y, arr, color);
string adds = x.ToString() + "|" + (y - 1).ToString();
if (!buffering.Contains(adds)) {
string adds = x.ToString() + "|" + (y + 1).ToString();
if (!buffering.Contains(adds))
string adds = (x - 1).ToString() + "|" + y.ToString();
if (!buffering.Contains(adds))
string adds = (x + 1).ToString() + "|" + y.ToString();
if (!buffering.Contains(adds))
public static Dictionary<string, int> findColorAllFollowInput(int color,int[, ] arr) {
Dictionary<string, int> dict = new Dictionary<string, int>();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 6; j++)
if (color.Equals(arr[i, j])) {
buffering = new List<string>();
checkCrush(i, j, arr, color);
dict.Add(i.ToString() + "|" + j.ToString(),buffering.Count);
public static List<string> returnListDamage(int[,] arr, int color) {
List<string> returnLst = new List<string>();
Dictionary<string, int> dictionarys = new Dictionary<string, int>();
dictionarys = findColorAllFollowInput(color, arr);
string keyOfMaxValue = dictionarys.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
buffering = new List<string>();
buffering.Add(keyOfMaxValue);
if (buffering.Count() == i) break;
int x = int.Parse(buffering[i].Split('|')[0]);
int y = int.Parse(buffering[i].Split('|')[1]);
checkCrush(x, y, arr, color);