diff --git a/SharpPropagation/Population.cs b/SharpPropagation/Population.cs index 5e6c934..b84995b 100644 --- a/SharpPropagation/Population.cs +++ b/SharpPropagation/Population.cs @@ -60,8 +60,10 @@ namespace SharpPropagation public void Generate() { + //Parallel.For(0, Dimensions.Width, x => for (int x = 0; x < Dimensions.Width; x++) { + //Parallel.For(0, Dimensions.Height, y => for (int y = 0; y < Dimensions.Height; y++) { //The ratios will not be exact, for example someone who wants 100% infected 100% immune and 100% dead, he will have 100% dead because they are overwriting each others @@ -71,33 +73,33 @@ namespace SharpPropagation //In other words I did it that way but it can be changed just its not the right method to have perfect ratios if (StartInfectedRatio != 0) { - if (StartInfectedRatio == 100 || Roll(Rnd,StartInfectedRatio)) - { + if (StartInfectedRatio == 100 || Roll(Rnd, StartInfectedRatio)) + { Humans[x, y] = new Human(new Point(x, y), Human.State.Infected); } } if (StartImmuneRatio != 0) { - if (StartImmuneRatio == 100 || Roll(Rnd,StartImmuneRatio)) + if (StartImmuneRatio == 100 || Roll(Rnd, StartImmuneRatio)) { Humans[x, y] = new Human(new Point(x, y), Human.State.Immune); } } if (StartDeadRatio != 0) { - if (StartDeadRatio == 100 || Roll(Rnd,StartDeadRatio)) + if (StartDeadRatio == 100 || Roll(Rnd, StartDeadRatio)) { Humans[x, y] = new Human(new Point(x, y), Human.State.Dead); } } - if (Humans[x,y] is null) + if (Humans[x, y] is null) { Humans[x, y] = new Human(new Point(x, y), Human.State.Normal); } - - } - } + + }//); + }//); } public int[] Propagate() { @@ -108,7 +110,7 @@ namespace SharpPropagation //Parallel.For(0, Dimensions.Width,x => for (int x = 0; x < Dimensions.Width; x++) { - //Parallel.For(0, Dimensions.Width,y => + //Parallel.For(0, Dimensions.Height,y => for (int y = 0; y < Dimensions.Height; y++) { switch (Humans[x, y].PresentState) @@ -158,7 +160,6 @@ namespace SharpPropagation /// ### List potentialInfections = new List(); - //potentialInfections.Add(Humans[person.Position.X,person.Position.Y]); potentialInfections.Add(new Point(person.X - 1, person.Y - 1)); //Top Left potentialInfections.Add(new Point(person.X, person.Y - 1)); //Top @@ -256,6 +257,39 @@ namespace SharpPropagation { return rnd.Next(0, CORRECTED_PERCENTAGE) < rate; } + public void DisplayPng(string name) + { + Bitmap bitmap = new Bitmap(Dimensions.Width,Dimensions.Height); + Color color = new Color(); + using (Graphics g = Graphics.FromImage(bitmap)) + { + //Parallel.For(0, Dimensions.Width, x => + for (int x = 0; x < Dimensions.Width; x++) + { + for (int y = 0; y < Dimensions.Height; y++) + { + + switch (Humans[x, y].PresentState) + { + case Human.State.Normal: + color = Color.Green; + break; + case Human.State.Infected: + color = Color.Red; + break; + case Human.State.Immune: + color = Color.Blue; + break; + case Human.State.Dead: + color = Color.Black; + break; + } + bitmap.SetPixel(x, y, color); + } + }//); + } + bitmap.Save(name + ".png",System.Drawing.Imaging.ImageFormat.Png); + } public void Display() { //int[] stats = GetStats(); @@ -266,9 +300,12 @@ namespace SharpPropagation if (Plague != null) Console.WriteLine(Plague); Console.Write("\n"); + + //Parallel.For(0, Dimensions.Width, x => for (int x = 0; x < Dimensions.Width; x++) { Console.Write("\n"); + //Parallel.For(0, Dimensions.height, y => for (int y = 0; y < Dimensions.Height; y++) { switch (Humans[x, y].PresentState) @@ -297,8 +334,8 @@ namespace SharpPropagation Console.Write(sprite); //We reset to the default Console.ForegroundColor = ConsoleColor.White; - } - } + }//); + }//); Console.Write(Environment.NewLine); } } diff --git a/SharpPropagation/Program.cs b/SharpPropagation/Program.cs index b7cdda5..af16d8f 100644 --- a/SharpPropagation/Program.cs +++ b/SharpPropagation/Program.cs @@ -17,7 +17,9 @@ namespace SharpPropagation Size populationSize = new Size(1000,1000); Population peoples = new Population(populationSize,random,10,10,5); peoples.SetDisease(new Disease(random,20,10,5,"Chick Chicken")); + string ImagesLocation = "Test/"; //peoples.Display(); + Console.WriteLine($"Propagation started with {populationSize.Width} x {populationSize.Height} humans ({populationSize.Width*populationSize.Height})"); int[] stats; int steps = 0; @@ -31,6 +33,7 @@ namespace SharpPropagation { break; } + peoples.DisplayPng(ImagesLocation+"Test_"+steps); } //peoples.Display(); Console.WriteLine($"Propagation finished in {steps}");