a new version wich is so much worse that i cant just delete it

This commit is contained in:
M.Rohmer
2022-03-03 20:17:36 +01:00
parent 3a561f2d0a
commit 413c6213ce
3 changed files with 157 additions and 130 deletions
+9 -7
View File
@@ -84,12 +84,11 @@ namespace PropagationRemasteredBeta
private void tmrTick_Tick(object sender, EventArgs e) private void tmrTick_Tick(object sender, EventArgs e)
{ {
//t.Refresh();
stopwatch.Start(); stopwatch.Start();
int infecteds; int infecteds;
if (t.InfectedCount.Count > 0) if (t.InfectedPeoples.Count > 0)
{ {
infecteds = t.InfectedCount[t.InfectedCount.Count() - 1]; infecteds = t.InfectedPeoples.Count - 1;
} }
else else
{ {
@@ -97,7 +96,10 @@ namespace PropagationRemasteredBeta
} }
if (infecteds > 0) if (infecteds > 0)
{ {
//MessageBox.Show("total humans : " + (t.DeadPeoples.Count + t.InfectedPeoples.Count + t.SainPeoples.Count + t.ImmunesPeoples.Count).ToString());
t.Refresh(); t.Refresh();
//MessageBox.Show("total humans : " + (t.DeadPeoples.Count + t.InfectedPeoples.Count + t.SainPeoples.Count + t.ImmunesPeoples.Count).ToString());
} }
else else
{ {
@@ -107,10 +109,10 @@ namespace PropagationRemasteredBeta
//refresh all the stats //refresh all the stats
lblMemory.Text = GetMemoryUsage().ToString() + " Mb"; lblMemory.Text = GetMemoryUsage().ToString() + " Mb";
lblelementsCounter.Text = t.DRAWED_ELEMENTS.ToString(); lblelementsCounter.Text = t.DRAWED_ELEMENTS.ToString();
lblInfected.Text = t.InfectedCount[t.InfectedCount.Count() - 1].ToString(); lblInfected.Text = (t.InfectedPeoples.Count - 1).ToString();
lblImmunes.Text = t.ImmuneCount[t.ImmuneCount.Count() - 1].ToString(); lblImmunes.Text = (t.ImmunesPeoples.Count - 1).ToString();
lblSain.Text = t.SainCount[t.SainCount.Count() - 1].ToString(); lblSain.Text = (t.SainPeoples.Count - 1).ToString();
lblDeaths.Text = t.DeadCount[t.DeadCount.Count() - 1].ToString(); lblDeaths.Text = (t.DeadPeoples.Count - 1).ToString();
} }
private double GetMemoryUsage() private double GetMemoryUsage()
+41 -41
View File
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace PropagationRemasteredBeta namespace PropagationRemasteredBeta
{ {
public class Human:ICloneable public class Human : ICloneable
{ {
//State values //State values
public Color SAIN_COLOR = Color.Green; public Color SAIN_COLOR = Color.Green;
@@ -34,8 +34,9 @@ namespace PropagationRemasteredBeta
{ {
get { return _state; } get { return _state; }
//We set the counter of infection whenever we set it to infected //We set the counter of infection whenever we set it to infected
set { set
_state = value; {
_state = value;
if (_state == INFECTED) { _InfectedTimeCounter = 1; } if (_state == INFECTED) { _InfectedTimeCounter = 1; }
switch (_state) 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 //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; SAIN_COLOR = sainColor;
IMMUNE_COLOR = immuneColor; IMMUNE_COLOR = immuneColor;
@@ -81,91 +82,90 @@ namespace PropagationRemasteredBeta
INFECTED_COLOR = infectedColor; INFECTED_COLOR = infectedColor;
} }
public void Propagate(Human[,] previousTerrain, Human[,] nextTerrain, int infectiosity, int deathRate, int cureTime, Random rnd) public void Propagate(Terrain terrain)
{ {
Human target; Human target;
Point location; Point location;
//target = previousTerrain[Position.X, Position.Y];
LifeTimeCounter++; LifeTimeCounter++;
InfectedTimeCounter++;
if (this.State == INFECTED) if (terrain.Rnd.Next(0, 100) <= terrain.DeathRate)
{ {
InfectedTimeCounter++; this.State = DEAD;
if (rnd.Next(0, 100) <= deathRate) terrain.InfectedPeoples.Remove(this);
{ terrain.DeadPeoples.Add(this);
this.State = DEAD; }
nextTerrain[this.Position.X, this.Position.Y] = this; else
} {
if (LifeTimeCounter >= cureTime) if (LifeTimeCounter >= terrain.CureTime)
{ {
this.State = IMMUNE; this.State = IMMUNE;
terrain.ImmunesPeoples.Add(this);
terrain.InfectedPeoples.Remove(this);
} }
else else
{ {
//we need to check if we are not in a corner //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 < (terrain.TerrainSize.Width - 1) && Position.Y < (terrain.TerrainSize.Height - 1))
{ {
//check top left //check top left
location = new Point(Position.X - 1, Position.Y + 1); location = new Point(Position.X - 1, Position.Y + 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check top //check top
location = new Point(Position.X, Position.Y + 1); location = new Point(Position.X, Position.Y + 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check top left //check top left
location = new Point(Position.X + 1, Position.Y + 1); location = new Point(Position.X + 1, Position.Y + 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check left //check left
location = new Point(Position.X - 1, Position.Y); location = new Point(Position.X - 1, Position.Y);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check right //check right
location = new Point(Position.X + 1, Position.Y); location = new Point(Position.X + 1, Position.Y);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom left //check bottom left
location = new Point(Position.X - 1, Position.Y - 1); location = new Point(Position.X - 1, Position.Y - 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom //check bottom
location = new Point(Position.X, Position.Y - 1); location = new Point(Position.X, Position.Y - 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom right //check bottom right
location = new Point(Position.X + 1, Position.Y - 1); location = new Point(Position.X + 1, Position.Y - 1);
target = previousTerrain[location.X, location.Y]; target = terrain.Population[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
} }
} }
} }
} }
private void CheckInfection(Human[,] nextTerrain, Human target, int infectiosity, int deathRate, Random rnd) private void CheckInfection(Terrain terrain, Human target, int infectiosity, Random rnd)
{ {
if (target.State == SAIN) //if (terrain.OldSainPeoples.Contains(target) && rnd.Next(0, 100) <= infectiosity)
if(target.State == Human.SAIN && rnd.Next(0, 100) <= infectiosity)
{ {
if (rnd.Next(0, 100) <= infectiosity) target.State = INFECTED;
{ terrain.InfectedPeoples.Add(target);
target.State = INFECTED; terrain.SainPeoples.Remove(target);
}
} }
nextTerrain[target.Position.X, target.Position.Y] = target;
} }
public object Clone() public object Clone()
{ {
Human newHuman = new Human(Position,State); Human newHuman = new Human(Position, State);
newHuman.HumanSize = HumanSize; newHuman.HumanSize = HumanSize;
newHuman.InfectedTimeCounter = InfectedTimeCounter; newHuman.InfectedTimeCounter = InfectedTimeCounter;
newHuman.LifeTimeCounter = LifeTimeCounter; newHuman.LifeTimeCounter = LifeTimeCounter;
+107 -82
View File
@@ -28,20 +28,24 @@ namespace PropagationRemasteredBeta
private int _cureTime; private int _cureTime;
private Bitmap _render; private Bitmap _render;
private Human[,] oldTerrain; private Human[,] Grid;
private Human[,] newTerrain;
private List<int> _sainCount; private List<Human> _oldSainPeoples;
private List<int> _infectedCount; private List<Human> _oldInfectedPeoples;
private List<int> _immuneCount; private List<Human> _oldImmunesPeoples;
private List<int> _deadCount; private List<Human> _oldDeadPeoples;
private List<Human> _sainPeoples;
private List<Human> _infectedPeoples;
private List<Human> _immunesPeoples;
private List<Human> _deadPeoples;
private int _simulationDuration; private int _simulationDuration;
/*Used for debugging*/ /*Used for debugging*/
public int DRAWED_ELEMENTS; public int DRAWED_ELEMENTS;
private Random rnd; private Random _rnd;
public Human[,] Population { get => _population; set => _population = value; } public Human[,] Population { get => _population; set => _population = value; }
public Size TerrainSize { get => _terrainSize; private set => _terrainSize = value; } public Size TerrainSize { get => _terrainSize; private set => _terrainSize = value; }
public int InfectedProportion { get => _infectedProportion; private set => _infectedProportion = value; } public int InfectedProportion { get => _infectedProportion; private set => _infectedProportion = value; }
@@ -50,12 +54,16 @@ namespace PropagationRemasteredBeta
public int InfectionRate { get => _infectionRate; private set => _infectionRate = value; } public int InfectionRate { get => _infectionRate; private set => _infectionRate = value; }
public int CureTime { get => _cureTime; set => _cureTime = value; } public int CureTime { get => _cureTime; set => _cureTime = value; }
public Bitmap Render { get => _render; set => _render = value; } public Bitmap Render { get => _render; set => _render = value; }
public List<Human> SainPeoples { get => _sainPeoples; set => _sainPeoples = value; }
public List<int> SainCount { get => _sainCount; set => _sainCount = value; } public List<Human> InfectedPeoples { get => _infectedPeoples; set => _infectedPeoples = value; }
public List<int> InfectedCount { get => _infectedCount; set => _infectedCount = value; } public List<Human> ImmunesPeoples { get => _immunesPeoples; set => _immunesPeoples = value; }
public List<int> ImmuneCount { get => _immuneCount; set => _immuneCount = value; } public List<Human> DeadPeoples { get => _deadPeoples; set => _deadPeoples = value; }
public List<int> DeadCount { get => _deadCount; set => _deadCount = value; }
public int SimulationDuration { get => _simulationDuration; set => _simulationDuration = value; } public int SimulationDuration { get => _simulationDuration; set => _simulationDuration = value; }
public Random Rnd { get => _rnd; set => _rnd = value; }
public List<Human> OldSainPeoples { get => _oldSainPeoples; set => _oldSainPeoples = value; }
public List<Human> OldInfectedPeoples { get => _oldInfectedPeoples; set => _oldInfectedPeoples = value; }
public List<Human> OldImmunesPeoples { get => _oldImmunesPeoples; set => _oldImmunesPeoples = value; }
public List<Human> OldDeadPeoples { get => _oldDeadPeoples; set => _oldDeadPeoples = value; }
public Terrain(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime) public Terrain(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime)
{ {
@@ -66,17 +74,19 @@ namespace PropagationRemasteredBeta
DeathRate = deathRate; DeathRate = deathRate;
InfectionRate = infectionRate; InfectionRate = infectionRate;
CureTime = cureTime; CureTime = cureTime;
rnd = new Random(); Rnd = new Random();
oldTerrain = null; Grid = null;
newTerrain = null;
//all of this is for stats purposes SainPeoples = new List<Human>();
InfectedPeoples = new List<Human>();
ImmunesPeoples = new List<Human>();
DeadPeoples = new List<Human>();
SainCount = new List<int>(); OldSainPeoples = new List<Human>();
InfectedCount = new List<int>(); OldInfectedPeoples = new List<Human>();
ImmuneCount = new List<int>(); OldImmunesPeoples = new List<Human>();
DeadCount = new List<int>(); OldDeadPeoples = new List<Human>();
SimulationDuration = -1; SimulationDuration = -1;
@@ -96,19 +106,19 @@ namespace PropagationRemasteredBeta
state = Human.SAIN; state = Human.SAIN;
if (rnd.Next(0, 100) < InfectedProportion) if (Rnd.Next(0, 100) < InfectedProportion)
{ {
state = Human.INFECTED; state = Human.INFECTED;
} }
else else
{ {
if (rnd.Next(0, 100) < ImmuneProportion) if (Rnd.Next(0, 100) < ImmuneProportion)
{ {
state = Human.IMMUNE; state = Human.IMMUNE;
} }
} }
Population[width, height] = new Human(new Point(width, height), state); AddHuman(new Point(width, height), state);
} }
} }
} }
@@ -118,70 +128,87 @@ namespace PropagationRemasteredBeta
{ {
for (int height = 0; height < TerrainSize.Height; height += 1) for (int height = 0; height < TerrainSize.Height; height += 1)
{ {
int state; int state;
state = Human.SAIN; if (Rnd.Next(0, 100) < ImmuneProportion)
if (rnd.Next(0, 100) < ImmuneProportion)
{ {
state = Human.IMMUNE; state = Human.IMMUNE;
} }
else
{
Population[width, height] = new Human(new Point(width, height), state); state = Human.SAIN;
}
AddHuman(new Point(width, height), state);
} }
} }
//we generate a single infected in a random location //we generate a single infected in a random location
int x = rnd.Next(0, TerrainSize.Width); int x = Rnd.Next(0, TerrainSize.Width);
int y = rnd.Next(0, TerrainSize.Height); int y = Rnd.Next(0, TerrainSize.Height);
AddHuman(new Point(x, y), Human.INFECTED);
Population[x, y].State = Human.INFECTED; }
public void AddHuman(Point position,int state)
{
//filling population
Population[position.X, position.Y] = new Human(new Point(position.X, position.Y), state);
switch (state)
{
case Human.SAIN:
SainPeoples.Add(Population[position.X, position.Y]);
break;
case Human.IMMUNE:
ImmunesPeoples.Add(Population[position.X, position.Y]);
break;
case Human.INFECTED:
InfectedPeoples.Add(Population[position.X, position.Y]);
break;
case Human.DEAD:
DeadPeoples.Add(Population[position.X, position.Y]);
break;
default:
SainPeoples.Add(Population[position.X, position.Y]);
break;
}
}
public List<Human> CopyPopulations(List<Human> ListToCopy)
{
List<Human> ListToCopyInto = new List<Human>(ListToCopy.Count);
foreach (Human h in ListToCopy)
{
ListToCopyInto.Add((Human)h.Clone());
}
return ListToCopyInto;
} }
public void Refresh() public void Refresh()
{ {
OldDeadPeoples = CopyPopulations(DeadPeoples);
OldInfectedPeoples = CopyPopulations(InfectedPeoples);
OldSainPeoples = CopyPopulations(SainPeoples);
OldImmunesPeoples = CopyPopulations(ImmunesPeoples);
DeadPeoples = new List<Human>(OldDeadPeoples.Count);
ImmunesPeoples = new List<Human>(OldImmunesPeoples.Count);
SainPeoples = new List<Human>(OldSainPeoples.Count);
InfectedPeoples = new List<Human>(OldInfectedPeoples.Count);
//used for stats and curing
SimulationDuration++; SimulationDuration++;
SainCount.Add(0); foreach (Human individual in OldInfectedPeoples)
ImmuneCount.Add(0);
InfectedCount.Add(0);
DeadCount.Add(0);
oldTerrain = Population;
newTerrain = oldTerrain;
for (int width = 0; width < TerrainSize.Width; width += 1)
{ {
for (int height = 0; height < TerrainSize.Height; height += 1) InfectedPeoples.Add(individual);
{ individual.Propagate(this);
//we also send the random so if one day we want to add a seed feature it will also affect the transmission }
if (Population[width, height].State != Human.SAIN && Population[width, height].State != Human.DEAD && Population[width, height].State != Human.IMMUNE) foreach (Human individual in OldImmunesPeoples)
{ {
Population[width, height].Propagate(oldTerrain, newTerrain, InfectionRate, DeathRate, CureTime, rnd); ImmunesPeoples.Add(individual);
} }
else foreach (Human individual in OldSainPeoples)
{ {
newTerrain[width, height] = Population[width, height]; SainPeoples.Add(individual);
} }
//only for stats purposes foreach (Human individual in OldDeadPeoples)
switch (Population[width, height].State) {
{ DeadPeoples.Add(individual);
case Human.SAIN:
SainCount[SimulationDuration] += 1;
break;
case Human.IMMUNE:
ImmuneCount[SimulationDuration] += 1;
break;
case Human.INFECTED:
InfectedCount[SimulationDuration] += 1;
break;
case Human.DEAD:
DeadCount[SimulationDuration] += 1;
break;
}
}
} }
Population = newTerrain;
} }
public Bitmap Display() public Bitmap Display()
@@ -193,12 +220,12 @@ namespace PropagationRemasteredBeta
//this is an attempt to save time, we display the dominant color in the all bitmap and only change the others. //this is an attempt to save time, we display the dominant color in the all bitmap and only change the others.
int dominantState = Human.SAIN; int dominantState = Human.SAIN;
//we check that it is not the first frame and by default we expect the first frame to be dominantly sain people //we check that it is not the first frame and by default we expect the first frame to be dominantly sain people
if (InfectedCount.Count() > 0) if (InfectedPeoples.Count() > 0)
{ {
int infecteds = InfectedCount[InfectedCount.Count() - 1]; int infecteds = InfectedPeoples.Count() - 1;
int sain = SainCount[SainCount.Count() - 1]; int sain = SainPeoples.Count() - 1;
int immune = ImmuneCount[ImmuneCount.Count() - 1]; int immune = ImmunesPeoples.Count() - 1;
int deaths = DeadCount[DeadCount.Count() - 1]; int deaths = DeadPeoples.Count() - 1;
if (infecteds > sain && infecteds > immune && infecteds > deaths) if (infecteds > sain && infecteds > immune && infecteds > deaths)
{ {
@@ -236,7 +263,6 @@ namespace PropagationRemasteredBeta
gr.FillRectangle(new SolidBrush(sample.SAIN_COLOR), new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height))); gr.FillRectangle(new SolidBrush(sample.SAIN_COLOR), new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
break; break;
} }
for (int width = 0; width < TerrainSize.Width; width += 1) for (int width = 0; width < TerrainSize.Width; width += 1)
{ {
for (int height = 0; height < TerrainSize.Height; height += 1) for (int height = 0; height < TerrainSize.Height; height += 1)
@@ -248,7 +274,6 @@ namespace PropagationRemasteredBeta
gr.FillRectangle(new SolidBrush(c), new Rectangle(individual.Position, individual.HumanSize)); gr.FillRectangle(new SolidBrush(c), new Rectangle(individual.Position, individual.HumanSize));
DRAWED_ELEMENTS++; DRAWED_ELEMENTS++;
} }
} }
} }
} }