Added Ui to alter simulation settings and added paralell processing with huge performance benefits over little grids

This commit is contained in:
M.Rohmer
2022-03-07 11:03:09 +01:00
parent 9ca64a3c41
commit 0ca5b842ff
10 changed files with 812 additions and 172 deletions
+48 -50
View File
@@ -60,7 +60,7 @@ namespace PropagationRemasteredBeta
public Human(Point position, int state, SolidBrush sainColor, SolidBrush infectedColor, SolidBrush immuneColor, SolidBrush deadColor)
{
Position = position;
LifeTimeCounter = 1;
InfectedTimeCounter = 0;
SAIN_COLOR = sainColor;
@@ -71,9 +71,9 @@ namespace PropagationRemasteredBeta
State = state;
}
public Human(Point position, int state) : this(position,state, new SolidBrush(Color.Green), new SolidBrush(Color.Red), new SolidBrush(Color.Blue), new SolidBrush(Color.Black))
public Human(Point position, int state) : this(position, state, new SolidBrush(Color.Green), new SolidBrush(Color.Red), new SolidBrush(Color.Blue), new SolidBrush(Color.Black))
{
}
public void ChangeBaseColors(SolidBrush sainColor, SolidBrush infectedColor, SolidBrush immuneColor, SolidBrush deadColor)
@@ -90,58 +90,45 @@ namespace PropagationRemasteredBeta
Point location;
LifeTimeCounter++;
InfectedTimeCounter++;
if (this.State == INFECTED)
List<Point> peopleToCheckLocations = new List<Point>();
//we need to check if we are not in a corner
if (Position.X > 0 && Position.Y > 0 && Position.X < (T.TerrainSize.Width - 1) && Position.Y < (T.TerrainSize.Height - 1))
{
InfectedTimeCounter++;
if (T.Rnd.Next(0, 100) <= T.DeathRate)
//check top left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y + 1));
//check top
peopleToCheckLocations.Add(new Point(Position.X, Position.Y + 1));
//check top left
peopleToCheckLocations.Add(new Point(Position.X, Position.Y + 1));
//check left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y));
//check right
peopleToCheckLocations.Add(new Point(Position.X + 1, Position.Y));
//check bottom left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y - 1));
//check bottom
peopleToCheckLocations.Add(new Point(Position.X, Position.Y - 1));
//check bottom right
peopleToCheckLocations.Add(new Point(Position.X + 1, Position.Y - 1));
foreach (Point p in peopleToCheckLocations)
{
State = DEAD;
}
if (LifeTimeCounter >= T.CureTime)
{
State = IMMUNE;
}
else
{
List<Point> peopleToCheckLocations = new List<Point>();
//we need to check if we are not in a corner
if (Position.X > 0 && Position.Y > 0 && Position.X < (T.TerrainSize.Width - 1) && Position.Y < (T.TerrainSize.Height - 1))
target = T.Population[p.X, p.Y];
if (target.State == Human.SAIN)
{
//check top left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y + 1));
//check top
peopleToCheckLocations.Add(new Point(Position.X, Position.Y + 1));
//check top left
peopleToCheckLocations.Add(new Point(Position.X, Position.Y + 1));
//check left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y));
//check right
peopleToCheckLocations.Add(new Point(Position.X + 1, Position.Y));
//check bottom left
peopleToCheckLocations.Add(new Point(Position.X - 1, Position.Y - 1));
//check bottom
peopleToCheckLocations.Add(new Point(Position.X, Position.Y - 1));
//check bottom right
peopleToCheckLocations.Add(new Point(Position.X + 1, Position.Y - 1));
foreach (Point p in peopleToCheckLocations)
{
target = T.Population[p.X, p.Y];
if (target.State == Human.SAIN)
{
T.PeopleToCheck.Add(target);
}
}
T.PeopleToCheck.Add(target);
}
}
T.InfectedsToCheck.Add(this);
}
return this;
}
@@ -153,7 +140,18 @@ namespace PropagationRemasteredBeta
}
return this;
}
public Human CheckDeath(int deathRate, int cureTime, Random rnd)
{
if (rnd.Next(0, 100) <= deathRate)
{
State = DEAD;
}
if (InfectedTimeCounter >= cureTime)
{
State = IMMUNE;
}
return this;
}
public object Clone()
{
Human newHuman = new Human(Position, State);