private int CheckWinner() { int winner = -1; // rows for (int i = 0; i < Math.Pow(gameSize, 2); i += gameSize) { if (i % gameSize == 0) { if (Places.FindAll(z => z.Id >= i && z.Id < i + gameSize).Where(z => z.Type == IconType.Circle).Count() == gameSize) { winner = 2; } if (Places.FindAll(z => z.Id >= i && z.Id < i + gameSize).Where(z => z.Type == IconType.Cross).Count() == gameSize) { winner = 1; } } } // columns for (int i = 0; i < gameSize; i++) { if (Places.FindAll(z => (z.Id - i) % gameSize == 0).Where(z => z.Type == IconType.Circle).Count() == gameSize) { winner = 2; } if (Places.FindAll(z => (z.Id - i) % gameSize == 0).Where(z => z.Type == IconType.Cross).Count() == gameSize) { winner = 1; } } // diagonal var diagonal = new List <int>(); for (int i = 0; i < Math.Pow(gameSize, 2); i += gameSize + 1) { diagonal.Add(i); } if (Places.FindAll(z => diagonal.Contains(z.Id)).Where(z => z.Type == IconType.Circle).Count() == gameSize) { winner = 2; } if (Places.FindAll(z => diagonal.Contains(z.Id)).Where(z => z.Type == IconType.Cross).Count() == gameSize) { winner = 1; } diagonal.Clear(); for (int i = gameSize - 1; i < Math.Pow(gameSize, 2) - 1; i += gameSize - 1) { diagonal.Add(i); } if (Places.FindAll(z => diagonal.Contains(z.Id)).Where(z => z.Type == IconType.Circle).Count() == gameSize) { winner = 2; } if (Places.FindAll(z => diagonal.Contains(z.Id)).Where(z => z.Type == IconType.Cross).Count() == gameSize) { winner = 1; } return(winner); }