Changed a bit the core mechanics with a slight improvement in performance
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PropagationRemasteredBeta
|
||||
{
|
||||
public class Human:ICloneable
|
||||
public class Human : ICloneable
|
||||
{
|
||||
//State values
|
||||
public Color SAIN_COLOR = Color.Green;
|
||||
@@ -34,8 +34,9 @@ namespace PropagationRemasteredBeta
|
||||
{
|
||||
get { return _state; }
|
||||
//We set the counter of infection whenever we set it to infected
|
||||
set {
|
||||
_state = value;
|
||||
set
|
||||
{
|
||||
_state = value;
|
||||
if (_state == INFECTED) { _InfectedTimeCounter = 1; }
|
||||
switch (_state)
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace PropagationRemasteredBeta
|
||||
}
|
||||
//we dont have any constructor with only default values because the human needs his position in the field to process the infection
|
||||
|
||||
public void ChangeBaseColors(Color sainColor,Color infectedColor,Color immuneColor,Color deadColor)
|
||||
public void ChangeBaseColors(Color sainColor, Color infectedColor, Color immuneColor, Color deadColor)
|
||||
{
|
||||
SAIN_COLOR = sainColor;
|
||||
IMMUNE_COLOR = immuneColor;
|
||||
@@ -81,91 +82,118 @@ namespace PropagationRemasteredBeta
|
||||
INFECTED_COLOR = infectedColor;
|
||||
}
|
||||
|
||||
public void Propagate(Human[,] previousTerrain, Human[,] nextTerrain, int infectiosity, int deathRate, int cureTime, Random rnd)
|
||||
public Human Propagate(Terrain T)
|
||||
{
|
||||
Human target;
|
||||
Point location;
|
||||
|
||||
//target = previousTerrain[Position.X, Position.Y];
|
||||
|
||||
LifeTimeCounter++;
|
||||
|
||||
if (this.State == INFECTED)
|
||||
{
|
||||
InfectedTimeCounter++;
|
||||
if (rnd.Next(0, 100) <= deathRate)
|
||||
if (T.Rnd.Next(0, 100) <= T.DeathRate)
|
||||
{
|
||||
this.State = DEAD;
|
||||
nextTerrain[this.Position.X, this.Position.Y] = this;
|
||||
State = DEAD;
|
||||
}
|
||||
if (LifeTimeCounter >= cureTime)
|
||||
if (LifeTimeCounter >= T.CureTime)
|
||||
{
|
||||
this.State = IMMUNE;
|
||||
State = IMMUNE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we need to check if we are not in a corner
|
||||
if (Position.X > 0 && Position.Y > 0 && Position.X < (previousTerrain.GetLength(0) - 1) && Position.Y < (previousTerrain.GetLength(1) - 1))
|
||||
if (Position.X > 0 && Position.Y > 0 && Position.X < (T.TerrainSize.Width - 1) && Position.Y < (T.TerrainSize.Height - 1))
|
||||
{
|
||||
//check top left
|
||||
location = new Point(Position.X - 1, Position.Y + 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check top
|
||||
location = new Point(Position.X, Position.Y + 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check top left
|
||||
location = new Point(Position.X + 1, Position.Y + 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check left
|
||||
location = new Point(Position.X - 1, Position.Y);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check right
|
||||
location = new Point(Position.X + 1, Position.Y);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check bottom left
|
||||
location = new Point(Position.X - 1, Position.Y - 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check bottom
|
||||
location = new Point(Position.X, Position.Y - 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
|
||||
//check bottom right
|
||||
location = new Point(Position.X + 1, Position.Y - 1);
|
||||
target = previousTerrain[location.X, location.Y];
|
||||
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
|
||||
target = T.Population[location.X, location.Y];
|
||||
|
||||
if (target.State == Human.SAIN)
|
||||
{
|
||||
T.PeopleToCheck.Add(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void CheckInfection(Human[,] nextTerrain, Human target, int infectiosity, int deathRate, Random rnd)
|
||||
public Human CheckInfection(int infectiosity, Random rnd)
|
||||
{
|
||||
if (target.State == SAIN)
|
||||
if (rnd.Next(0, 100) <= infectiosity)
|
||||
{
|
||||
if (rnd.Next(0, 100) <= infectiosity)
|
||||
{
|
||||
target.State = INFECTED;
|
||||
}
|
||||
State = INFECTED;
|
||||
}
|
||||
|
||||
nextTerrain[target.Position.X, target.Position.Y] = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
Human newHuman = new Human(Position,State);
|
||||
Human newHuman = new Human(Position, State);
|
||||
newHuman.HumanSize = HumanSize;
|
||||
newHuman.InfectedTimeCounter = InfectedTimeCounter;
|
||||
newHuman.LifeTimeCounter = LifeTimeCounter;
|
||||
|
||||
Reference in New Issue
Block a user