private void GenerateMinefield(Location clickedLocation) { List <Location> allLocations = new(); for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { allLocations.Add(new Location(x, y)); minefield.Add(new Cell(new Location(x, y), false, 0, false)); } } IReadOnlyCollection <Location> mineLocations = minelayer.PlaceMines(allLocations, mineCount, clickedLocation); foreach (Cell minefieldCell in minefield) { if (mineLocations.Contains(minefieldCell.Location)) { minefieldCell.IsMine = true; continue; } IEnumerable <Location> locationsArea = Utilities.GetLocationsAreaAroundLocation(allLocations, minefieldCell.Location, true); byte countAdjactentMines = (byte)mineLocations .Intersect(locationsArea) .Count(); minefieldCell.AdjacentMineCount = countAdjactentMines; } }