Ready to compare with Rust

This commit is contained in:
2022-05-03 14:50:44 +02:00
parent 3d9d23ba7b
commit e29ff7948e
2 changed files with 34 additions and 59 deletions
+17 -44
View File
@@ -86,45 +86,11 @@ namespace SharpPropagation
} }
} }
} }
public int[] GetStats() public int[] Propagate()
{
int[] result;
if (Humans != null)
{
int normalCount = 0;
int infectedCount = 0;
int immuneCount = 0;
int deadCount = 0;
foreach (Human michel in Humans)
{
switch (michel.PresentState)
{
case Human.State.Normal:
normalCount++;
break;
case Human.State.Infected:
infectedCount++;
break;
case Human.State.Immune:
immuneCount++;
break;
case Human.State.Dead:
deadCount++;
break;
}
}
result = new int[] { normalCount, infectedCount, immuneCount, deadCount };
}
else
{
result = new int[] { 0, 0, 0, 0 };
}
return result;
}
public void Propagate()
{ {
List<Human> peopleToCheck = new List<Human>(); List<Human> peopleToCheck = new List<Human>();
int[] stats = new int[] { 0, 0, 0, 0 };
// 0 Normal, 1 Infected, 2 Immune, 3 Dead
//Parallel.For(0, Dimensions.Width,x => //Parallel.For(0, Dimensions.Width,x =>
for (int x = 0; x < Dimensions.Width; x++) for (int x = 0; x < Dimensions.Width; x++)
@@ -134,12 +100,18 @@ namespace SharpPropagation
{ {
switch (Humans[x, y].PresentState) switch (Humans[x, y].PresentState)
{ {
//for now only infected peoples are interesting case Human.State.Normal:
stats[0]+=1;
break;
case Human.State.Infected: case Human.State.Infected:
peopleToCheck.Add(Humans[x, y]); peopleToCheck.Add(Humans[x, y]);
stats[1]+=1;
break; break;
default: case Human.State.Immune:
//do nothing stats[2] += 1;
break;
case Human.State.Dead:
stats[3] += 1;
break; break;
} }
}//); }//);
@@ -187,10 +159,10 @@ namespace SharpPropagation
potentialInfections.Add(Humans[person.Position.X + 1, person.Position.Y + 1]); //Bottom Right potentialInfections.Add(Humans[person.Position.X + 1, person.Position.Y + 1]); //Bottom Right
foreach (Human potentialInfected in potentialInfections) foreach (Human potentialInfected in potentialInfections)
{
if (wouldBeInfected(Rnd))
{ {
if (potentialInfected.PresentState == Human.State.Normal) if (potentialInfected.PresentState == Human.State.Normal)
{
if (wouldBeInfected(Rnd))
{ {
peopleToInfect.Add(potentialInfected); peopleToInfect.Add(potentialInfected);
} }
@@ -265,6 +237,7 @@ namespace SharpPropagation
Humans[dead.Position.X, dead.Position.Y].PresentState = Human.State.Dead; Humans[dead.Position.X, dead.Position.Y].PresentState = Human.State.Dead;
}//); }//);
} }
return stats;
} }
public bool wouldBeInfected(Random rnd) public bool wouldBeInfected(Random rnd)
{ {
@@ -282,11 +255,11 @@ namespace SharpPropagation
} }
public void Display() public void Display()
{ {
int[] stats = GetStats(); //int[] stats = GetStats();
char sprite = '#'; char sprite = '#';
//Console.Clear(); //Console.Clear();
Console.WriteLine(String.Format("Population aged {0}", Age)); Console.WriteLine(String.Format("Population aged {0}", Age));
Console.WriteLine(String.Format("Population : {0} Normals : {1} Infecteds : {2} Immunes : {3} Deads : {4}", Humans.Length, stats[0], stats[1], stats[2], stats[3])); //Console.WriteLine(String.Format("Population : {0} Normals : {1} Infecteds : {2} Immunes : {3} Deads : {4}", Humans.Length, stats[0], stats[1], stats[2], stats[3]));
if (Plague != null) if (Plague != null)
Console.WriteLine(Plague); Console.WriteLine(Plague);
Console.Write("\n"); Console.Write("\n");
+16 -14
View File
@@ -14,24 +14,26 @@ namespace SharpPropagation
{ {
Console.WriteLine("********** Sharp Propagation (Console) 2022 **********"); Console.WriteLine("********** Sharp Propagation (Console) 2022 **********");
Random random = new Random(); Random random = new Random();
Console.WriteLine("Initialisation");
Population peoples = new Population(new Size(30,50),random,10,10,5); Population peoples = new Population(new Size(1000,1000),random,10,10,5);
peoples.SetDisease(new Disease(random,20,10,5,"Chick Chicken")); peoples.SetDisease(new Disease(random,20,10,5,"Chick Chicken"));
Console.WriteLine("Before Propagation"); //peoples.Display();
peoples.Display(); Console.WriteLine("Propagation :");
int[] stats;
int[] stats = peoples.GetStats(); int steps = 0;
// 0:normal 1:infected // 0:normal 1:infected
int test = 1; while(true)
while (stats[1] > 5 && test < 60)
{ {
Console.Clear(); steps++;
peoples.Propagate(); stats = peoples.Propagate();
peoples.Display(); Console.WriteLine($"Infecteds: {stats[1]} Immunes: {stats[2]} Deads: {stats[3]}");
test++; if (stats[1] == 0)
//Thread.Sleep(200); {
break;
} }
}
//peoples.Display();
Console.WriteLine($"Propagation finished in {steps}");
Console.ReadKey(); Console.ReadKey();
} }
} }