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)
{
//t.Refresh();
stopwatch.Start();
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
{
@@ -97,7 +96,10 @@ namespace PropagationRemasteredBeta
}
if (infecteds > 0)
{
//MessageBox.Show("total humans : " + (t.DeadPeoples.Count + t.InfectedPeoples.Count + t.SainPeoples.Count + t.ImmunesPeoples.Count).ToString());
t.Refresh();
//MessageBox.Show("total humans : " + (t.DeadPeoples.Count + t.InfectedPeoples.Count + t.SainPeoples.Count + t.ImmunesPeoples.Count).ToString());
}
else
{
@@ -107,10 +109,10 @@ namespace PropagationRemasteredBeta
//refresh all the stats
lblMemory.Text = GetMemoryUsage().ToString() + " Mb";
lblelementsCounter.Text = t.DRAWED_ELEMENTS.ToString();
lblInfected.Text = t.InfectedCount[t.InfectedCount.Count() - 1].ToString();
lblImmunes.Text = t.ImmuneCount[t.ImmuneCount.Count() - 1].ToString();
lblSain.Text = t.SainCount[t.SainCount.Count() - 1].ToString();
lblDeaths.Text = t.DeadCount[t.DeadCount.Count() - 1].ToString();
lblInfected.Text = (t.InfectedPeoples.Count - 1).ToString();
lblImmunes.Text = (t.ImmunesPeoples.Count - 1).ToString();
lblSain.Text = (t.SainPeoples.Count - 1).ToString();
lblDeaths.Text = (t.DeadPeoples.Count - 1).ToString();
}
private double GetMemoryUsage()
+41 -41
View File
@@ -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,90 @@ namespace PropagationRemasteredBeta
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;
Point location;
//target = previousTerrain[Position.X, Position.Y];
LifeTimeCounter++;
InfectedTimeCounter++;
if (this.State == INFECTED)
if (terrain.Rnd.Next(0, 100) <= terrain.DeathRate)
{
InfectedTimeCounter++;
if (rnd.Next(0, 100) <= deathRate)
{
this.State = DEAD;
nextTerrain[this.Position.X, this.Position.Y] = this;
}
if (LifeTimeCounter >= cureTime)
this.State = DEAD;
terrain.InfectedPeoples.Remove(this);
terrain.DeadPeoples.Add(this);
}
else
{
if (LifeTimeCounter >= terrain.CureTime)
{
this.State = IMMUNE;
terrain.ImmunesPeoples.Add(this);
terrain.InfectedPeoples.Remove(this);
}
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 < (terrain.TerrainSize.Width - 1) && Position.Y < (terrain.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 = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check top
location = new Point(Position.X, Position.Y + 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//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 = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check left
location = new Point(Position.X - 1, Position.Y);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check right
location = new Point(Position.X + 1, Position.Y);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//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 = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom
location = new Point(Position.X, Position.Y - 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//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 = terrain.Population[location.X, location.Y];
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;
}
target.State = INFECTED;
terrain.InfectedPeoples.Add(target);
terrain.SainPeoples.Remove(target);
}
nextTerrain[target.Position.X, target.Position.Y] = target;
}
public object Clone()
{
Human newHuman = new Human(Position,State);
Human newHuman = new Human(Position, State);
newHuman.HumanSize = HumanSize;
newHuman.InfectedTimeCounter = InfectedTimeCounter;
newHuman.LifeTimeCounter = LifeTimeCounter;
+107 -82
View File
@@ -28,20 +28,24 @@ namespace PropagationRemasteredBeta
private int _cureTime;
private Bitmap _render;
private Human[,] oldTerrain;
private Human[,] newTerrain;
private Human[,] Grid;
private List<int> _sainCount;
private List<int> _infectedCount;
private List<int> _immuneCount;
private List<int> _deadCount;
private List<Human> _oldSainPeoples;
private List<Human> _oldInfectedPeoples;
private List<Human> _oldImmunesPeoples;
private List<Human> _oldDeadPeoples;
private List<Human> _sainPeoples;
private List<Human> _infectedPeoples;
private List<Human> _immunesPeoples;
private List<Human> _deadPeoples;
private int _simulationDuration;
/*Used for debugging*/
public int DRAWED_ELEMENTS;
private Random rnd;
private Random _rnd;
public Human[,] Population { get => _population; set => _population = value; }
public Size TerrainSize { get => _terrainSize; private set => _terrainSize = 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 CureTime { get => _cureTime; set => _cureTime = value; }
public Bitmap Render { get => _render; set => _render = value; }
public List<int> SainCount { get => _sainCount; set => _sainCount = value; }
public List<int> InfectedCount { get => _infectedCount; set => _infectedCount = value; }
public List<int> ImmuneCount { get => _immuneCount; set => _immuneCount = value; }
public List<int> DeadCount { get => _deadCount; set => _deadCount = value; }
public List<Human> SainPeoples { get => _sainPeoples; set => _sainPeoples = value; }
public List<Human> InfectedPeoples { get => _infectedPeoples; set => _infectedPeoples = value; }
public List<Human> ImmunesPeoples { get => _immunesPeoples; set => _immunesPeoples = value; }
public List<Human> DeadPeoples { get => _deadPeoples; set => _deadPeoples = 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)
{
@@ -66,17 +74,19 @@ namespace PropagationRemasteredBeta
DeathRate = deathRate;
InfectionRate = infectionRate;
CureTime = cureTime;
rnd = new Random();
Rnd = new Random();
oldTerrain = null;
newTerrain = null;
Grid = 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>();
InfectedCount = new List<int>();
ImmuneCount = new List<int>();
DeadCount = new List<int>();
OldSainPeoples = new List<Human>();
OldInfectedPeoples = new List<Human>();
OldImmunesPeoples = new List<Human>();
OldDeadPeoples = new List<Human>();
SimulationDuration = -1;
@@ -96,19 +106,19 @@ namespace PropagationRemasteredBeta
state = Human.SAIN;
if (rnd.Next(0, 100) < InfectedProportion)
if (Rnd.Next(0, 100) < InfectedProportion)
{
state = Human.INFECTED;
}
else
{
if (rnd.Next(0, 100) < ImmuneProportion)
if (Rnd.Next(0, 100) < ImmuneProportion)
{
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)
{
int state;
state = Human.SAIN;
if (rnd.Next(0, 100) < ImmuneProportion)
int state;
if (Rnd.Next(0, 100) < ImmuneProportion)
{
state = Human.IMMUNE;
}
Population[width, height] = new Human(new Point(width, height), state);
else
{
state = Human.SAIN;
}
AddHuman(new Point(width, height), state);
}
}
//we generate a single infected in a random location
int x = rnd.Next(0, TerrainSize.Width);
int y = rnd.Next(0, TerrainSize.Height);
Population[x, y].State = Human.INFECTED;
int x = Rnd.Next(0, TerrainSize.Width);
int y = Rnd.Next(0, TerrainSize.Height);
AddHuman(new Point(x, y), 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()
{
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++;
SainCount.Add(0);
ImmuneCount.Add(0);
InfectedCount.Add(0);
DeadCount.Add(0);
oldTerrain = Population;
newTerrain = oldTerrain;
for (int width = 0; width < TerrainSize.Width; width += 1)
foreach (Human individual in OldInfectedPeoples)
{
for (int height = 0; height < TerrainSize.Height; height += 1)
{
//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)
{
Population[width, height].Propagate(oldTerrain, newTerrain, InfectionRate, DeathRate, CureTime, rnd);
}
else
{
newTerrain[width, height] = Population[width, height];
}
//only for stats purposes
switch (Population[width, height].State)
{
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;
}
}
InfectedPeoples.Add(individual);
individual.Propagate(this);
}
foreach (Human individual in OldImmunesPeoples)
{
ImmunesPeoples.Add(individual);
}
foreach (Human individual in OldSainPeoples)
{
SainPeoples.Add(individual);
}
foreach (Human individual in OldDeadPeoples)
{
DeadPeoples.Add(individual);
}
Population = newTerrain;
}
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.
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
if (InfectedCount.Count() > 0)
if (InfectedPeoples.Count() > 0)
{
int infecteds = InfectedCount[InfectedCount.Count() - 1];
int sain = SainCount[SainCount.Count() - 1];
int immune = ImmuneCount[ImmuneCount.Count() - 1];
int deaths = DeadCount[DeadCount.Count() - 1];
int infecteds = InfectedPeoples.Count() - 1;
int sain = SainPeoples.Count() - 1;
int immune = ImmunesPeoples.Count() - 1;
int deaths = DeadPeoples.Count() - 1;
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)));
break;
}
for (int width = 0; width < TerrainSize.Width; width += 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));
DRAWED_ELEMENTS++;
}
}
}
}