Skip to content

Commit cbd7d59

Browse files
committed
Cells are now correctly Removed from the List and Added in a way that they dont get evaluated in the same round. Also Fixed a Bug in the Cell itself
1 parent dcd3d18 commit cbd7d59

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

CellSimulator/Logic/CellOverseer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@ public void AddCell(ICell cell)
2828

2929
public void SimulateNext()
3030
{
31-
for (int i = 0; i < CellList.Count; i++)
31+
List<ICell> CellsToRemove = new List<ICell>();
32+
int cellCount = CellList.Count; // Might get bigger during for-Loop, but New Cells should only be Evaluated in next run
33+
for (int i = 0; i < cellCount; i++)
3234
{
3335
ICell cell = CellList[i];
3436
cell.PerformAction();
3537
if (!cell.IsAlive)
3638
{
37-
CellList.Remove(cell);
39+
CellsToRemove.Add(cell);
3840
}
3941
else if (cell.LastAction == Enums.CellActionEnum.SuccessSplit)
4042
{
4143
AddCell();
4244
}
4345
}
46+
foreach(ICell cell in CellsToRemove)
47+
{
48+
CellList.Remove(cell);
49+
}
4450
}
4551
}
4652
}

CellSimulator/Models/Cell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void PerformAction()
7676
{
7777
LastAction = CellActionEnum.FailSplit;
7878
}
79-
Energy -= FOOD_REQUIRED_FOR_TRY_SPLIT;
79+
Food -= FOOD_REQUIRED_FOR_TRY_SPLIT;
8080
}
8181
else
8282
{

0 commit comments

Comments
 (0)