Compare commits
3 Commits
d21d626842
...
3d9d23ba7b
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d9d23ba7b | |||
| 11c84ea2d4 | |||
| 3a91edfaa3 |
@@ -47,7 +47,7 @@ namespace SharpPropagation
|
||||
Dimensions = dimensions;
|
||||
Rnd = rnd;
|
||||
Age = 0;
|
||||
Humans = new Human[dimensions.Width,dimensions.Height];
|
||||
Humans = new Human[dimensions.Width, dimensions.Height];
|
||||
|
||||
Generate();
|
||||
}
|
||||
@@ -122,12 +122,169 @@ namespace SharpPropagation
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Propagate()
|
||||
{
|
||||
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.Height; y++)
|
||||
{
|
||||
switch (Humans[x, y].PresentState)
|
||||
{
|
||||
//for now only infected peoples are interesting
|
||||
case Human.State.Infected:
|
||||
peopleToCheck.Add(Humans[x, y]);
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
}//);
|
||||
}//);
|
||||
|
||||
List<Human> peopleToInfect = new List<Human>();
|
||||
List<Human> peopleToCure = new List<Human>();
|
||||
List<Human> peopleToKill = new List<Human>();
|
||||
|
||||
//Parallel.ForEach(peopleToCheck, person =>
|
||||
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(Rnd))
|
||||
{
|
||||
peopleToCure.Add(person);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
/// ###
|
||||
/// #@#
|
||||
/// ###
|
||||
|
||||
List<Human> potentialInfections = new List<Human>();
|
||||
//potentialInfections.Add(Humans[person.Position.X,person.Position.Y]);
|
||||
|
||||
potentialInfections.Add(Humans[person.Position.X - 1, person.Position.Y - 1]); //Top Left
|
||||
potentialInfections.Add(Humans[person.Position.X, person.Position.Y - 1]); //Top
|
||||
potentialInfections.Add(Humans[person.Position.X + 1, person.Position.Y - 1]); //Top Right
|
||||
|
||||
potentialInfections.Add(Humans[person.Position.X - 1, person.Position.Y]); //Left
|
||||
potentialInfections.Add(Humans[person.Position.X + 1, person.Position.Y]); //Right
|
||||
|
||||
potentialInfections.Add(Humans[person.Position.X - 1, person.Position.Y + 1]); //Bottom Left
|
||||
potentialInfections.Add(Humans[person.Position.X, person.Position.Y + 1]); //Bottom
|
||||
potentialInfections.Add(Humans[person.Position.X + 1, person.Position.Y + 1]); //Bottom Right
|
||||
|
||||
foreach (Human potentialInfected in potentialInfections)
|
||||
{
|
||||
if (wouldBeInfected(Rnd))
|
||||
{
|
||||
if (potentialInfected.PresentState == Human.State.Normal)
|
||||
{
|
||||
peopleToInfect.Add(potentialInfected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO
|
||||
//Check every special cases (corners sides etc..)
|
||||
|
||||
//REMOVE WHEN IMPLEMENTED
|
||||
//It is here to prevent an infected in the borders to keep the programm running as he thinks there are still people to simulate
|
||||
peopleToKill.Add(person);
|
||||
|
||||
/// @##
|
||||
/// ###
|
||||
/// ###
|
||||
|
||||
/// #@#
|
||||
/// ###
|
||||
/// ###
|
||||
|
||||
/// ##@
|
||||
/// ###
|
||||
/// ###
|
||||
|
||||
/// ###
|
||||
/// @##
|
||||
/// ###
|
||||
|
||||
/// ###
|
||||
/// ##@
|
||||
/// ###
|
||||
|
||||
/// ###
|
||||
/// ###
|
||||
/// @##
|
||||
|
||||
/// ###
|
||||
/// ###
|
||||
/// #@#
|
||||
|
||||
/// ###
|
||||
/// ###
|
||||
/// ##@
|
||||
}
|
||||
}
|
||||
}
|
||||
}//);
|
||||
if (peopleToInfect.Count > 0)
|
||||
{
|
||||
//Parallel.ForEach(peopleToInfect, infected =>
|
||||
foreach (Human infected in peopleToInfect)
|
||||
{
|
||||
Humans[infected.Position.X, infected.Position.Y].PresentState = Human.State.Infected;
|
||||
}//);
|
||||
}
|
||||
if (peopleToCure.Count > 0)
|
||||
{
|
||||
//Parallel.ForEach(peopleToCure, cured =>
|
||||
foreach (Human cured in peopleToCure)
|
||||
{
|
||||
Humans[cured.Position.X, cured.Position.Y].PresentState = Human.State.Immune;
|
||||
}//);
|
||||
}
|
||||
if (peopleToKill.Count > 0)
|
||||
{
|
||||
//Parallel.ForEach(peopleToKill, dead =>
|
||||
foreach (Human dead in peopleToKill)
|
||||
{
|
||||
Humans[dead.Position.X, dead.Position.Y].PresentState = Human.State.Dead;
|
||||
}//);
|
||||
}
|
||||
}
|
||||
public bool wouldBeInfected(Random rnd)
|
||||
{
|
||||
return rnd.Next(0, CORRECTED_PERCENTAGE) < Plague.InfectionRate;
|
||||
}
|
||||
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;
|
||||
}
|
||||
public bool wouldDie(Random rnd)
|
||||
{
|
||||
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)
|
||||
@@ -141,29 +298,32 @@ namespace SharpPropagation
|
||||
switch (Humans[x, y].PresentState)
|
||||
{
|
||||
case Human.State.Normal:
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
//Console.BackgroundColor = ConsoleColor.Green;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
break;
|
||||
case Human.State.Infected:
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
//Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
break;
|
||||
case Human.State.Immune:
|
||||
Console.BackgroundColor = ConsoleColor.Blue;
|
||||
//Console.BackgroundColor = ConsoleColor.Blue;
|
||||
Console.ForegroundColor = ConsoleColor.Blue;
|
||||
break;
|
||||
case Human.State.Dead:
|
||||
Console.BackgroundColor = ConsoleColor.Gray;
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
//Console.BackgroundColor = ConsoleColor.Gray;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
break;
|
||||
default:
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
//Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
break;
|
||||
}
|
||||
Console.Write(sprite);
|
||||
//We reset to the default
|
||||
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
|
||||
{
|
||||
@@ -12,17 +13,26 @@ namespace SharpPropagation
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("********** Sharp Propagation (Console) 2022 **********");
|
||||
Console.WriteLine("Press any key to start the propagation");
|
||||
Console.ReadLine();
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
Population peoples = new Population(new Size(30,50),random,10,10,5);
|
||||
peoples.SetDisease(new Disease(random,20,10,5,"Chick Chicken"));
|
||||
Console.WriteLine("Before Propagation");
|
||||
peoples.Display();
|
||||
|
||||
Console.ReadKey();
|
||||
int[] stats = peoples.GetStats();
|
||||
// 0:normal 1:infected
|
||||
int test = 1;
|
||||
while (stats[1] > 5 && test < 60)
|
||||
{
|
||||
Console.Clear();
|
||||
peoples.Propagate();
|
||||
peoples.Display();
|
||||
test++;
|
||||
//Thread.Sleep(200);
|
||||
}
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user