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
+46 -48
View File
@@ -71,7 +71,7 @@ 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))
{
}
@@ -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);
+379
View File
@@ -0,0 +1,379 @@
namespace PropagationRemasteredBeta
{
partial class MainVue
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblTitle = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.chkbxSaveFiles = new System.Windows.Forms.CheckBox();
this.tbxSaveFilePath = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.nupPopulationSize = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.lblPopulationSizePrediction = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.nupInfectiosity = new System.Windows.Forms.NumericUpDown();
this.nupMortality = new System.Windows.Forms.NumericUpDown();
this.label4 = new System.Windows.Forms.Label();
this.nupImmunes = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.nupInfecteds = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
this.comboModes = new System.Windows.Forms.ComboBox();
this.label7 = new System.Windows.Forms.Label();
this.nupCureTime = new System.Windows.Forms.NumericUpDown();
this.label8 = new System.Windows.Forms.Label();
this.btnRunSimulation = new System.Windows.Forms.Button();
this.btnOpenSimViewer = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nupPopulationSize)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupInfectiosity)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupMortality)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupImmunes)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupInfecteds)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupCureTime)).BeginInit();
this.SuspendLayout();
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.Font = new System.Drawing.Font("Verdana", 20F);
this.lblTitle.Location = new System.Drawing.Point(12, 9);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(537, 41);
this.lblTitle.TabIndex = 0;
this.lblTitle.Text = "Propagation Remastered 2022";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.chkbxSaveFiles);
this.groupBox1.Controls.Add(this.tbxSaveFilePath);
this.groupBox1.Font = new System.Drawing.Font("Verdana", 12F);
this.groupBox1.Location = new System.Drawing.Point(15, 66);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(534, 108);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "General Settings";
//
// chkbxSaveFiles
//
this.chkbxSaveFiles.AutoSize = true;
this.chkbxSaveFiles.Checked = true;
this.chkbxSaveFiles.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkbxSaveFiles.Location = new System.Drawing.Point(14, 69);
this.chkbxSaveFiles.Name = "chkbxSaveFiles";
this.chkbxSaveFiles.Size = new System.Drawing.Size(236, 29);
this.chkbxSaveFiles.TabIndex = 6;
this.chkbxSaveFiles.Text = "Save the simulation";
this.chkbxSaveFiles.UseVisualStyleBackColor = true;
//
// tbxSaveFilePath
//
this.tbxSaveFilePath.Font = new System.Drawing.Font("Verdana", 12F);
this.tbxSaveFilePath.Location = new System.Drawing.Point(14, 31);
this.tbxSaveFilePath.Name = "tbxSaveFilePath";
this.tbxSaveFilePath.Size = new System.Drawing.Size(514, 32);
this.tbxSaveFilePath.TabIndex = 5;
this.tbxSaveFilePath.Text = "./Saves/";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.nupCureTime);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.comboModes);
this.groupBox2.Controls.Add(this.nupImmunes);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.nupInfecteds);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.nupMortality);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.nupInfectiosity);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.lblPopulationSizePrediction);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.nupPopulationSize);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Font = new System.Drawing.Font("Verdana", 12F);
this.groupBox2.Location = new System.Drawing.Point(15, 180);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(534, 342);
this.groupBox2.TabIndex = 7;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Simulation Settings";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 41);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Size :";
//
// nupPopulationSize
//
this.nupPopulationSize.Location = new System.Drawing.Point(14, 69);
this.nupPopulationSize.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nupPopulationSize.Name = "nupPopulationSize";
this.nupPopulationSize.Size = new System.Drawing.Size(514, 32);
this.nupPopulationSize.TabIndex = 1;
this.nupPopulationSize.Value = new decimal(new int[] {
400,
0,
0,
0});
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 104);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(245, 25);
this.label2.TabIndex = 2;
this.label2.Text = "Simulated individuals :";
//
// lblPopulationSizePrediction
//
this.lblPopulationSizePrediction.AutoSize = true;
this.lblPopulationSizePrediction.Location = new System.Drawing.Point(260, 104);
this.lblPopulationSizePrediction.Name = "lblPopulationSizePrediction";
this.lblPopulationSizePrediction.Size = new System.Drawing.Size(95, 25);
this.lblPopulationSizePrediction.TabIndex = 3;
this.lblPopulationSizePrediction.Text = "160\'000";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(9, 143);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(187, 25);
this.label3.TabIndex = 4;
this.label3.Text = "Infectiosity (%) :";
//
// nupInfectiosity
//
this.nupInfectiosity.Location = new System.Drawing.Point(14, 171);
this.nupInfectiosity.Name = "nupInfectiosity";
this.nupInfectiosity.Size = new System.Drawing.Size(236, 32);
this.nupInfectiosity.TabIndex = 5;
this.nupInfectiosity.Value = new decimal(new int[] {
20,
0,
0,
0});
//
// nupMortality
//
this.nupMortality.Location = new System.Drawing.Point(292, 171);
this.nupMortality.Name = "nupMortality";
this.nupMortality.Size = new System.Drawing.Size(236, 32);
this.nupMortality.TabIndex = 7;
this.nupMortality.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(287, 143);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(158, 25);
this.label4.TabIndex = 6;
this.label4.Text = "Mortality (%):";
//
// nupImmunes
//
this.nupImmunes.Location = new System.Drawing.Point(292, 234);
this.nupImmunes.Name = "nupImmunes";
this.nupImmunes.Size = new System.Drawing.Size(236, 32);
this.nupImmunes.TabIndex = 11;
this.nupImmunes.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(287, 206);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(169, 25);
this.label5.TabIndex = 10;
this.label5.Text = "Immunes (%) :";
//
// nupInfecteds
//
this.nupInfecteds.Location = new System.Drawing.Point(14, 234);
this.nupInfecteds.Name = "nupInfecteds";
this.nupInfecteds.Size = new System.Drawing.Size(236, 32);
this.nupInfecteds.TabIndex = 9;
this.nupInfecteds.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(9, 206);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(167, 25);
this.label6.TabIndex = 8;
this.label6.Text = "Infecteds (%) :";
//
// comboModes
//
this.comboModes.FormattingEnabled = true;
this.comboModes.Items.AddRange(new object[] {
"Classic",
"One for all"});
this.comboModes.Location = new System.Drawing.Point(292, 297);
this.comboModes.Name = "comboModes";
this.comboModes.Size = new System.Drawing.Size(236, 33);
this.comboModes.TabIndex = 12;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(287, 269);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(81, 25);
this.label7.TabIndex = 13;
this.label7.Text = "Mode :";
//
// nupCureTime
//
this.nupCureTime.Location = new System.Drawing.Point(14, 297);
this.nupCureTime.Name = "nupCureTime";
this.nupCureTime.Size = new System.Drawing.Size(236, 32);
this.nupCureTime.TabIndex = 15;
this.nupCureTime.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(9, 269);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(128, 25);
this.label8.TabIndex = 14;
this.label8.Text = "Cure time :";
//
// btnRunSimulation
//
this.btnRunSimulation.Font = new System.Drawing.Font("Verdana", 12F);
this.btnRunSimulation.Location = new System.Drawing.Point(15, 528);
this.btnRunSimulation.Name = "btnRunSimulation";
this.btnRunSimulation.Size = new System.Drawing.Size(534, 83);
this.btnRunSimulation.TabIndex = 8;
this.btnRunSimulation.Text = "Run the simulation";
this.btnRunSimulation.UseVisualStyleBackColor = true;
this.btnRunSimulation.Click += new System.EventHandler(this.btnRunSimulation_Click);
//
// btnOpenSimViewer
//
this.btnOpenSimViewer.Font = new System.Drawing.Font("Verdana", 12F);
this.btnOpenSimViewer.Location = new System.Drawing.Point(15, 617);
this.btnOpenSimViewer.Name = "btnOpenSimViewer";
this.btnOpenSimViewer.Size = new System.Drawing.Size(534, 83);
this.btnOpenSimViewer.TabIndex = 9;
this.btnOpenSimViewer.Text = "Open SimViewer";
this.btnOpenSimViewer.UseVisualStyleBackColor = true;
//
// MainVue
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(558, 710);
this.Controls.Add(this.btnOpenSimViewer);
this.Controls.Add(this.btnRunSimulation);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.lblTitle);
this.Font = new System.Drawing.Font("Verdana", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "MainVue";
this.Text = "MainVue";
this.Load += new System.EventHandler(this.MainVue_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nupPopulationSize)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupInfectiosity)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupMortality)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupImmunes)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupInfecteds)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupCureTime)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblTitle;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.CheckBox chkbxSaveFiles;
private System.Windows.Forms.TextBox tbxSaveFilePath;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblPopulationSizePrediction;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown nupPopulationSize;
private System.Windows.Forms.NumericUpDown nupImmunes;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.NumericUpDown nupInfecteds;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.NumericUpDown nupMortality;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown nupInfectiosity;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ComboBox comboModes;
private System.Windows.Forms.NumericUpDown nupCureTime;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Button btnRunSimulation;
private System.Windows.Forms.Button btnOpenSimViewer;
}
}
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PropagationRemasteredBeta
{
public partial class MainVue : Form
{
public Size terrainSize;
public int infectedProportion;
public int resistantProportion;
public int deathRate;
public int infectionRate;
public int cureTime;
public MainVue()
{
InitializeComponent();
}
private void MainVue_Load(object sender, EventArgs e)
{
}
private void btnRunSimulation_Click(object sender, EventArgs e)
{
terrainSize = new Size(Convert.ToInt32(nupPopulationSize.Value),Convert.ToInt32(nupPopulationSize.Value));
infectedProportion = Convert.ToInt32(nupInfecteds.Value);
resistantProportion = Convert.ToInt32(nupImmunes.Value);
deathRate = Convert.ToInt32(nupMortality.Value);
infectionRate = Convert.ToInt32(nupInfectiosity.Value);
cureTime = Convert.ToInt32(nupCureTime.Value);
SimulationVue sm = new SimulationVue(terrainSize,infectedProportion,resistantProportion,deathRate,infectionRate,cureTime);
sm.Closed += (s, args) => this.Show();
sm.Show();
this.Hide();
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -16,7 +16,8 @@ namespace PropagationRemasteredBeta
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainVue());
//Application.Run(new SimulationVue());
}
}
}
@@ -21,7 +21,7 @@
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<WarningLevel>0</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>PropagationRemasteredBeta.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -46,18 +49,27 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="MainVue.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="MainVue.Designer.cs">
<DependentUpon>MainVue.cs</DependentUpon>
</Compile>
<Compile Include="SimulationVue.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SimulationVue.Designer.cs">
<DependentUpon>SimulationVue.cs</DependentUpon>
</Compile>
<Compile Include="Human.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Terrain.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="MainVue.resx">
<DependentUpon>MainVue.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="SimulationVue.resx">
<DependentUpon>SimulationVue.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@@ -1,6 +1,6 @@
namespace PropagationRemasteredBeta
{
partial class Form1
partial class SimulationVue
{
/// <summary>
/// Variable nécessaire au concepteur.
@@ -31,32 +31,34 @@
this.components = new System.ComponentModel.Container();
this.btnStartNormal = new System.Windows.Forms.Button();
this.pbxTerrain = new System.Windows.Forms.PictureBox();
this.label4 = new System.Windows.Forms.Label();
this.tmrTick = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.lblMemory = new System.Windows.Forms.Label();
this.lblelementsCounter = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.lblelementsCounter = new System.Windows.Forms.Label();
this.lblFrameCount = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.lblTotalTime = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.lblDeaths = new System.Windows.Forms.Label();
this.lblTotalTime = new System.Windows.Forms.Label();
this.lbl6 = new System.Windows.Forms.Label();
this.lblSain = new System.Windows.Forms.Label();
this.lblDeaths = new System.Windows.Forms.Label();
this.lbl5 = new System.Windows.Forms.Label();
this.lblImmunes = new System.Windows.Forms.Label();
this.lblSain = new System.Windows.Forms.Label();
this.lbl4 = new System.Windows.Forms.Label();
this.lblInfected = new System.Windows.Forms.Label();
this.lblImmunes = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.lblInfected = new System.Windows.Forms.Label();
this.btnStartOneForAll = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pbxTerrain)).BeginInit();
this.SuspendLayout();
//
// btnStartNormal
//
this.btnStartNormal.Location = new System.Drawing.Point(818, 294);
this.btnStartNormal.Location = new System.Drawing.Point(1091, 362);
this.btnStartNormal.Margin = new System.Windows.Forms.Padding(4);
this.btnStartNormal.Name = "btnStartNormal";
this.btnStartNormal.Size = new System.Drawing.Size(105, 51);
this.btnStartNormal.Size = new System.Drawing.Size(140, 63);
this.btnStartNormal.TabIndex = 0;
this.btnStartNormal.Text = "Start classic";
this.btnStartNormal.UseVisualStyleBackColor = true;
@@ -64,176 +66,208 @@
//
// pbxTerrain
//
this.pbxTerrain.Location = new System.Drawing.Point(12, 12);
this.pbxTerrain.Location = new System.Drawing.Point(16, 15);
this.pbxTerrain.Margin = new System.Windows.Forms.Padding(4);
this.pbxTerrain.Name = "pbxTerrain";
this.pbxTerrain.Size = new System.Drawing.Size(800, 800);
this.pbxTerrain.Size = new System.Drawing.Size(1067, 985);
this.pbxTerrain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pbxTerrain.TabIndex = 1;
this.pbxTerrain.TabStop = false;
this.pbxTerrain.Click += new System.EventHandler(this.pbxTerrain_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(1091, 108);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 17);
this.label4.TabIndex = 6;
this.label4.Text = "Frames";
//
// tmrTick
//
this.tmrTick.Interval = 10;
this.tmrTick.Tick += new System.EventHandler(this.tmrTick_Tick);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(818, 12);
this.label1.Location = new System.Drawing.Point(1091, 15);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(78, 13);
this.label1.Size = new System.Drawing.Size(103, 17);
this.label1.TabIndex = 2;
this.label1.Text = "Memory Usage";
//
// lblMemory
//
this.lblMemory.AutoSize = true;
this.lblMemory.Location = new System.Drawing.Point(818, 25);
this.lblMemory.Location = new System.Drawing.Point(1091, 31);
this.lblMemory.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblMemory.Name = "lblMemory";
this.lblMemory.Size = new System.Drawing.Size(29, 13);
this.lblMemory.Size = new System.Drawing.Size(36, 17);
this.lblMemory.TabIndex = 3;
this.lblMemory.Text = "NaN";
//
// lblelementsCounter
//
this.lblelementsCounter.AutoSize = true;
this.lblelementsCounter.Location = new System.Drawing.Point(818, 61);
this.lblelementsCounter.Name = "lblelementsCounter";
this.lblelementsCounter.Size = new System.Drawing.Size(29, 13);
this.lblelementsCounter.TabIndex = 5;
this.lblelementsCounter.Text = "NaN";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(818, 48);
this.label3.Location = new System.Drawing.Point(1091, 59);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(84, 13);
this.label3.Size = new System.Drawing.Size(110, 17);
this.label3.TabIndex = 4;
this.label3.Text = "Drawed Elemets";
//
// lblelementsCounter
//
this.lblelementsCounter.AutoSize = true;
this.lblelementsCounter.Location = new System.Drawing.Point(1091, 75);
this.lblelementsCounter.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblelementsCounter.Name = "lblelementsCounter";
this.lblelementsCounter.Size = new System.Drawing.Size(36, 17);
this.lblelementsCounter.TabIndex = 5;
this.lblelementsCounter.Text = "NaN";
//
// lblFrameCount
//
this.lblFrameCount.AutoSize = true;
this.lblFrameCount.Location = new System.Drawing.Point(818, 101);
this.lblFrameCount.Location = new System.Drawing.Point(1091, 124);
this.lblFrameCount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblFrameCount.Name = "lblFrameCount";
this.lblFrameCount.Size = new System.Drawing.Size(29, 13);
this.lblFrameCount.Size = new System.Drawing.Size(36, 17);
this.lblFrameCount.TabIndex = 7;
this.lblFrameCount.Text = "NaN";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(818, 88);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(41, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Frames";
//
// lblTotalTime
//
this.lblTotalTime.AutoSize = true;
this.lblTotalTime.Location = new System.Drawing.Point(818, 136);
this.lblTotalTime.Name = "lblTotalTime";
this.lblTotalTime.Size = new System.Drawing.Size(29, 13);
this.lblTotalTime.TabIndex = 9;
this.lblTotalTime.Text = "NaN";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(818, 123);
this.label5.Location = new System.Drawing.Point(1091, 151);
this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(85, 13);
this.label5.Size = new System.Drawing.Size(115, 17);
this.label5.TabIndex = 8;
this.label5.Text = "Total Time (ms) :";
//
// lblDeaths
// lblTotalTime
//
this.lblDeaths.AutoSize = true;
this.lblDeaths.Location = new System.Drawing.Point(818, 278);
this.lblDeaths.Name = "lblDeaths";
this.lblDeaths.Size = new System.Drawing.Size(29, 13);
this.lblDeaths.TabIndex = 11;
this.lblDeaths.Text = "NaN";
this.lblTotalTime.AutoSize = true;
this.lblTotalTime.Location = new System.Drawing.Point(1091, 167);
this.lblTotalTime.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblTotalTime.Name = "lblTotalTime";
this.lblTotalTime.Size = new System.Drawing.Size(36, 17);
this.lblTotalTime.TabIndex = 9;
this.lblTotalTime.Text = "NaN";
//
// lbl6
//
this.lbl6.AutoSize = true;
this.lbl6.Location = new System.Drawing.Point(818, 265);
this.lbl6.Location = new System.Drawing.Point(1091, 326);
this.lbl6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbl6.Name = "lbl6";
this.lbl6.Size = new System.Drawing.Size(44, 13);
this.lbl6.Size = new System.Drawing.Size(57, 17);
this.lbl6.TabIndex = 10;
this.lbl6.Text = "Deads :";
//
// lblSain
// lblDeaths
//
this.lblSain.AutoSize = true;
this.lblSain.Location = new System.Drawing.Point(818, 242);
this.lblSain.Name = "lblSain";
this.lblSain.Size = new System.Drawing.Size(29, 13);
this.lblSain.TabIndex = 13;
this.lblSain.Text = "NaN";
this.lblDeaths.AutoSize = true;
this.lblDeaths.Location = new System.Drawing.Point(1091, 342);
this.lblDeaths.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblDeaths.Name = "lblDeaths";
this.lblDeaths.Size = new System.Drawing.Size(36, 17);
this.lblDeaths.TabIndex = 11;
this.lblDeaths.Text = "NaN";
//
// lbl5
//
this.lbl5.AutoSize = true;
this.lbl5.Location = new System.Drawing.Point(818, 229);
this.lbl5.Location = new System.Drawing.Point(1091, 282);
this.lbl5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbl5.Name = "lbl5";
this.lbl5.Size = new System.Drawing.Size(39, 13);
this.lbl5.Size = new System.Drawing.Size(51, 17);
this.lbl5.TabIndex = 12;
this.lbl5.Text = "Sains :";
//
// lblImmunes
// lblSain
//
this.lblImmunes.AutoSize = true;
this.lblImmunes.Location = new System.Drawing.Point(818, 207);
this.lblImmunes.Name = "lblImmunes";
this.lblImmunes.Size = new System.Drawing.Size(29, 13);
this.lblImmunes.TabIndex = 15;
this.lblImmunes.Text = "NaN";
this.lblSain.AutoSize = true;
this.lblSain.Location = new System.Drawing.Point(1091, 298);
this.lblSain.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblSain.Name = "lblSain";
this.lblSain.Size = new System.Drawing.Size(36, 17);
this.lblSain.TabIndex = 13;
this.lblSain.Text = "NaN";
//
// lbl4
//
this.lbl4.AutoSize = true;
this.lbl4.Location = new System.Drawing.Point(818, 194);
this.lbl4.Location = new System.Drawing.Point(1091, 239);
this.lbl4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbl4.Name = "lbl4";
this.lbl4.Size = new System.Drawing.Size(55, 13);
this.lbl4.Size = new System.Drawing.Size(72, 17);
this.lbl4.TabIndex = 14;
this.lbl4.Text = "Immunes :";
//
// lblInfected
// lblImmunes
//
this.lblInfected.AutoSize = true;
this.lblInfected.Location = new System.Drawing.Point(818, 172);
this.lblInfected.Name = "lblInfected";
this.lblInfected.Size = new System.Drawing.Size(29, 13);
this.lblInfected.TabIndex = 17;
this.lblInfected.Text = "NaN";
this.lblImmunes.AutoSize = true;
this.lblImmunes.Location = new System.Drawing.Point(1091, 255);
this.lblImmunes.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblImmunes.Name = "lblImmunes";
this.lblImmunes.Size = new System.Drawing.Size(36, 17);
this.lblImmunes.TabIndex = 15;
this.lblImmunes.Text = "NaN";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(818, 159);
this.label12.Location = new System.Drawing.Point(1091, 196);
this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(57, 13);
this.label12.Size = new System.Drawing.Size(73, 17);
this.label12.TabIndex = 16;
this.label12.Text = "Infecteds :";
//
// lblInfected
//
this.lblInfected.AutoSize = true;
this.lblInfected.Location = new System.Drawing.Point(1091, 212);
this.lblInfected.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblInfected.Name = "lblInfected";
this.lblInfected.Size = new System.Drawing.Size(36, 17);
this.lblInfected.TabIndex = 17;
this.lblInfected.Text = "NaN";
//
// btnStartOneForAll
//
this.btnStartOneForAll.Location = new System.Drawing.Point(818, 351);
this.btnStartOneForAll.Location = new System.Drawing.Point(1091, 432);
this.btnStartOneForAll.Margin = new System.Windows.Forms.Padding(4);
this.btnStartOneForAll.Name = "btnStartOneForAll";
this.btnStartOneForAll.Size = new System.Drawing.Size(105, 51);
this.btnStartOneForAll.Size = new System.Drawing.Size(140, 63);
this.btnStartOneForAll.TabIndex = 18;
this.btnStartOneForAll.Text = "Start oneForAll";
this.btnStartOneForAll.UseVisualStyleBackColor = true;
this.btnStartOneForAll.Click += new System.EventHandler(this.btnStartOneForAll_Click);
//
// Form1
// button1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.button1.Location = new System.Drawing.Point(1091, 503);
this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(140, 63);
this.button1.TabIndex = 19;
this.button1.Text = "Close";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// SimulationVue
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(929, 814);
this.ClientSize = new System.Drawing.Size(1239, 1002);
this.Controls.Add(this.button1);
this.Controls.Add(this.btnStartOneForAll);
this.Controls.Add(this.lblInfected);
this.Controls.Add(this.label12);
@@ -253,8 +287,9 @@
this.Controls.Add(this.label1);
this.Controls.Add(this.pbxTerrain);
this.Controls.Add(this.btnStartNormal);
this.Name = "Form1";
this.Text = "Form1";
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "SimulationVue";
this.Text = "Simulation";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
((System.ComponentModel.ISupportInitialize)(this.pbxTerrain)).EndInit();
this.ResumeLayout(false);
@@ -266,24 +301,25 @@
private System.Windows.Forms.Button btnStartNormal;
private System.Windows.Forms.PictureBox pbxTerrain;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Timer tmrTick;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblMemory;
private System.Windows.Forms.Label lblelementsCounter;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label lblelementsCounter;
private System.Windows.Forms.Label lblFrameCount;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label lblTotalTime;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label lblDeaths;
private System.Windows.Forms.Label lblTotalTime;
private System.Windows.Forms.Label lbl6;
private System.Windows.Forms.Label lblSain;
private System.Windows.Forms.Label lblDeaths;
private System.Windows.Forms.Label lbl5;
private System.Windows.Forms.Label lblImmunes;
private System.Windows.Forms.Label lblSain;
private System.Windows.Forms.Label lbl4;
private System.Windows.Forms.Label lblInfected;
private System.Windows.Forms.Label lblImmunes;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label lblInfected;
private System.Windows.Forms.Button btnStartOneForAll;
private System.Windows.Forms.Button button1;
}
}
@@ -11,7 +11,7 @@ using System.Windows.Forms;
namespace PropagationRemasteredBeta
{
public partial class Form1 : Form
public partial class SimulationVue : Form
{
Terrain t;
Bitmap BufferImage;
@@ -19,12 +19,26 @@ namespace PropagationRemasteredBeta
bool started = false;
Stopwatch stopwatch;
double totalTime;
public Form1()
public Size terrainSize;
public int infectedProportion;
public int resistantProportion;
public int deathRate;
public int infectionRate;
public int cureTime;
public SimulationVue(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime)
{
InitializeComponent();
t = new Terrain();
this.terrainSize = terrainSize;
this.infectedProportion = infectedProportion;
this.resistantProportion = resistantProportion;
this.deathRate = deathRate;
this.infectionRate = infectionRate;
this.cureTime = cureTime;
frameCount = 0;
BufferImage = new Bitmap(t.TerrainSize.Width, t.TerrainSize.Height);
BufferImage = new Bitmap(terrainSize.Width,terrainSize.Height);
stopwatch = new Stopwatch();
totalTime = 0;
}
@@ -52,7 +66,7 @@ namespace PropagationRemasteredBeta
btnStartNormal.Text = "Stop";
btnStartOneForAll.Text = "Stop";
tmrTick.Start();
t = new Terrain();
t = new Terrain(terrainSize,infectedProportion,resistantProportion,deathRate,infectionRate,cureTime);
frameCount = 0;
switch (mode)
@@ -72,6 +86,7 @@ namespace PropagationRemasteredBeta
{
if (started)
{
/*
BufferImage = t.Display();
pbxTerrain.Image = BufferImage;
stopwatch.Stop();
@@ -79,11 +94,13 @@ namespace PropagationRemasteredBeta
frameCount++;
lblFrameCount.Text = frameCount.ToString();
lblTotalTime.Text = totalTime.ToString();
*/
}
}
private void tmrTick_Tick(object sender, EventArgs e)
{
tmrTick.Stop();
//t.Refresh();
stopwatch.Start();
int infecteds;
@@ -102,8 +119,21 @@ namespace PropagationRemasteredBeta
else
{
StartStop(1);
//to do a last display after finished
BufferImage = t.Display();
pbxTerrain.Image = BufferImage;
}
this.Invalidate();
//this.Invalidate();
BufferImage = t.Display();
pbxTerrain.Image = BufferImage;
stopwatch.Stop();
totalTime = stopwatch.ElapsedMilliseconds;
frameCount++;
lblFrameCount.Text = frameCount.ToString();
lblTotalTime.Text = totalTime.ToString();
//refresh all the stats
lblMemory.Text = GetMemoryUsage().ToString() + " Mb";
lblelementsCounter.Text = t.DRAWED_ELEMENTS.ToString();
@@ -111,6 +141,8 @@ namespace PropagationRemasteredBeta
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();
tmrTick.Start();
}
private double GetMemoryUsage()
@@ -130,5 +162,15 @@ namespace PropagationRemasteredBeta
btnStartNormal.Enabled = false;
StartStop(2);
}
private void pbxTerrain_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
this.Close();
}
}
}
+16 -10
View File
@@ -11,7 +11,7 @@ namespace PropagationRemasteredBeta
{
public class Terrain
{
const int DEFAULT_SIZE = 1000;
const int DEFAULT_SIZE = 200;
const int DEFAULT_INFECTED_PROPORTION = 10;
const int DEFAULT_IMMUNE_PROPORTION = 10;
const int DEFAULT_DEATH_RATE = 5;
@@ -26,6 +26,7 @@ namespace PropagationRemasteredBeta
private Human[,] _population;
private ConcurrentBag<Human> _peopleToCheck;
private ConcurrentBag<Human> _infectedsToCheck;
private Size _terrainSize;
private int _infectedProportion;
@@ -62,6 +63,7 @@ namespace PropagationRemasteredBeta
public int SimulationDuration { get => _simulationDuration; set => _simulationDuration = value; }
public Random Rnd { get => rnd; set => rnd = value; }
public ConcurrentBag<Human> PeopleToCheck { get => _peopleToCheck; set => _peopleToCheck = value; }
public ConcurrentBag<Human> InfectedsToCheck { get => _infectedsToCheck; set => _infectedsToCheck = value; }
public Terrain(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime)
{
@@ -157,21 +159,22 @@ namespace PropagationRemasteredBeta
DeadCount.Add(0);
PeopleToCheck = new ConcurrentBag<Human>();
InfectedsToCheck = new ConcurrentBag<Human>();
//Parallel.For(0, TerrainSize.Width, width =>
for (int width = 0; width < TerrainSize.Width; width += 1)
Parallel.For(0, TerrainSize.Width, width =>
//for (int width = 0; width < TerrainSize.Width; width += 1)
{
//Parallel.For(0, TerrainSize.Height, height =>
for (int height = 0; height < TerrainSize.Height; height += 1)
Parallel.For(0, TerrainSize.Height, height =>
//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
switch (Population[width, height].State)
{
case Human.INFECTED:
Population[width, height] = Population[width, height].Propagate(this);
Population[width, height].Propagate(this);
break;
default:
//nothing to do
//nothing to do for now
break;
}
@@ -191,14 +194,17 @@ namespace PropagationRemasteredBeta
DeadCount[SimulationDuration] += 1;
break;
}
}//);
}//);
});
});
foreach (Human target in PeopleToCheck)
{
Population[target.Position.X,target.Position.Y] = target.CheckInfection(InfectionRate,Rnd);
}
foreach (Human target in InfectedsToCheck)
{
Population[target.Position.X, target.Position.Y] = target.CheckDeath(DeathRate,CureTime,Rnd);
}
}
public Bitmap Display()