public static void DistributeEnergy(this Matrix matrix, EnergyDistributionType energyDistributionType) { switch (energyDistributionType) { case EnergyDistributionType.Homogenous: { for (int i = 0; i < matrix.Width; i++) { for (int j = 0; j < matrix.Height; j++) { matrix.Energy[i, j] = 5; } } break; } case EnergyDistributionType.Heterogenous: { var borderCellsHelper = new BorderCellsHelpers(); var borderCells = borderCellsHelper.GetBorderCells(matrix); Parallel.ForEach(borderCells, (cell) => { matrix.Energy[cell.X, cell.Y] = 7; }); Parallel.ForEach(matrix.CellsWOId, (cell) => { if (matrix.Energy[cell.X, cell.Y] != 7) { matrix.Energy[cell.X, cell.Y] = 2; } }); break; } } }
public async Task DistributeEnergy(EnergyDistributionType energyDistributionType) { await Task.Run(() => this.matrix1.DistributeEnergy(energyDistributionType)); EnergyDistributed = true; CloneMatrix(matrix1, matrix2); }