fixed all problems, now its working
This commit is contained in:
@@ -124,27 +124,13 @@ namespace SharpPropagation
|
||||
}
|
||||
public void Propagate()
|
||||
{
|
||||
int test = 0;
|
||||
int[] stats;
|
||||
do
|
||||
{
|
||||
//REMOVE THIS WHEN RELEASE
|
||||
test++;
|
||||
|
||||
if (test > 100)
|
||||
{
|
||||
//Display();
|
||||
test = 0;
|
||||
}
|
||||
|
||||
stats = GetStats();
|
||||
List<Human> peopleToCheck = new List<Human>();
|
||||
|
||||
//Parallel.For(0, Dimensions.Width,x =>
|
||||
for (int x = 0; x < Dimensions.Width; x++)
|
||||
{
|
||||
//Parallel.For(0, Dimensions.Width,y =>
|
||||
for (int y = 0; y < Dimensions.Width; y++)
|
||||
for (int y = 0; y < Dimensions.Height; y++)
|
||||
{
|
||||
switch (Humans[x, y].PresentState)
|
||||
{
|
||||
@@ -167,20 +153,20 @@ namespace SharpPropagation
|
||||
foreach (Human person in peopleToCheck)
|
||||
{
|
||||
//I am assuming that if the Human is Curing or dying on this tick, he cant infect anyone
|
||||
if (wouldCure())
|
||||
if (wouldCure(Rnd))
|
||||
{
|
||||
peopleToCure.Add(person);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wouldDie())
|
||||
if (wouldDie(Rnd))
|
||||
{
|
||||
peopleToKill.Add(person);
|
||||
}
|
||||
else
|
||||
{
|
||||
//now we can start to check if people would be infected or not
|
||||
if (person.Position.X > 0 && person.Position.X < Dimensions.Width - 1 && person.Position.Y > 0 && person.Position.Y < Dimensions.Height - 1)
|
||||
if (person.Position.X > 0 && person.Position.X < Dimensions.Width -1 && person.Position.Y > 0 && person.Position.Y < Dimensions.Height -1)
|
||||
{
|
||||
/// ###
|
||||
/// #@#
|
||||
@@ -202,7 +188,7 @@ namespace SharpPropagation
|
||||
|
||||
foreach (Human potentialInfected in potentialInfections)
|
||||
{
|
||||
if (wouldBeInfected())
|
||||
if (wouldBeInfected(Rnd))
|
||||
{
|
||||
if (potentialInfected.PresentState == Human.State.Normal)
|
||||
{
|
||||
@@ -279,30 +265,26 @@ namespace SharpPropagation
|
||||
Humans[dead.Position.X, dead.Position.Y].PresentState = Human.State.Dead;
|
||||
}//);
|
||||
}
|
||||
|
||||
}while (stats[1] > 0); /*while (test < 1000);*/
|
||||
// It will run until the last infected man either dies or cures
|
||||
}
|
||||
public bool wouldBeInfected()
|
||||
public bool wouldBeInfected(Random rnd)
|
||||
{
|
||||
return Rnd.Next(0, CORRECTED_PERCENTAGE) > Plague.InfectionRate;
|
||||
return rnd.Next(0, CORRECTED_PERCENTAGE) < Plague.InfectionRate;
|
||||
}
|
||||
public bool wouldCure()
|
||||
public bool wouldCure(Random rnd)
|
||||
{
|
||||
//You could add a modifier that increases the curing chance with the age of the disease in the Human
|
||||
//Like after 2 weeks with it it would be at least 5 times more likely for him to cure
|
||||
return Rnd.Next(0, CORRECTED_PERCENTAGE) > Plague.CuringRate;
|
||||
return rnd.Next(0, CORRECTED_PERCENTAGE) < Plague.CuringRate;
|
||||
}
|
||||
public bool wouldDie()
|
||||
public bool wouldDie(Random rnd)
|
||||
{
|
||||
return Rnd.Next(0, CORRECTED_PERCENTAGE) > Plague.DeathRate;
|
||||
return rnd.Next(0, CORRECTED_PERCENTAGE) < Plague.DeathRate;
|
||||
}
|
||||
public void Display()
|
||||
{
|
||||
int[] stats = GetStats();
|
||||
char sprite = '#';
|
||||
|
||||
Console.Clear();
|
||||
//Console.Clear();
|
||||
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]));
|
||||
if (Plague != null)
|
||||
@@ -341,6 +323,7 @@ namespace SharpPropagation
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
}
|
||||
Console.Write(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace SharpPropagation
|
||||
{
|
||||
@@ -18,9 +19,19 @@ namespace SharpPropagation
|
||||
peoples.SetDisease(new Disease(random,20,10,5,"Chick Chicken"));
|
||||
Console.WriteLine("Before Propagation");
|
||||
peoples.Display();
|
||||
|
||||
int[] stats = peoples.GetStats();
|
||||
// 0:normal 1:infected
|
||||
int test = 1;
|
||||
while (stats[1] > 5 && test < 60)
|
||||
{
|
||||
Console.Clear();
|
||||
peoples.Propagate();
|
||||
Console.WriteLine("After Propagation");
|
||||
peoples.Display();
|
||||
test++;
|
||||
//Thread.Sleep(200);
|
||||
}
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user