Skip to content

Commit 9506867

Browse files
committed
Random birth
To fix random deaths (caused by position being taken before opportunity to stay in position), random birth was added to add some depth to the automata
1 parent 1b7b78a commit 9506867

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

Assets/Scenes/MainScene.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ MonoBehaviour:
418418
- {fileID: 11400000, guid: 6c4aad2df26db2946907e2ed9a388e80, type: 2}
419419
- {fileID: 11400000, guid: eac142ef9c8b9c545affdcf5c60cbc77, type: 2}
420420
- {fileID: 11400000, guid: 3d1eea21359521e46b69fd2962059d67, type: 2}
421-
updateInterval: 0.1
422-
Pattern: {fileID: 11400000, guid: 654c1336e7254094a8ea3c323ed84e55, type: 2}
421+
updateInterval: 0.05
422+
Pattern: {fileID: 11400000, guid: 68cb4d1ef7013d74589511cd1006eb36, type: 2}
423423
populationGoal: 1000
424-
wanderChance: 0.9
424+
wanderChance: 0.7
425425
--- !u!1660057539 &9223372036854775807
426426
SceneRoots:
427427
m_ObjectHideFlags: 0

Assets/Scripts/Model/PathPheromoneLife.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using Unity.VisualScripting;
34
using UnityEngine;
45

56
public class PathPheromoneLife : ILife
67
{
78
private DrawGrid drawGrid;
8-
private int xBound = 15;
9-
private int yBound = 15;
9+
private int xBound = 35;
10+
private int yBound = 35;
1011
private System.Random random = new();
1112

1213
public PathPheromoneLife(DrawGrid grid)
@@ -26,7 +27,7 @@ public HashSet<Cell> Step(HashSet<Cell> currentCells)
2627
if (cell.state == CellState.alive)
2728
{
2829
aliveCount++;
29-
Vector3Int nextPosition = new Vector3Int(0, 0, 0);
30+
Vector3Int nextPosition = cell.position;
3031
List<Vector3Int> nextPositions = new List<Vector3Int>(); // best options list
3132
int nextPositionPriority = 0;
3233
List<Vector3Int> availablePositions = GetAvailablePositions(cell.position, takenPositions);
@@ -63,12 +64,12 @@ public HashSet<Cell> Step(HashSet<Cell> currentCells)
6364
nextPosition = nextPositions[randomIndex];
6465
}
6566

66-
// Random chance of wandering to dead/empty space instead
67-
if (!takenPositions.Contains(emptyPosition) && UnityEngine.Random.value > drawGrid.wanderChance)
68-
nextPosition = emptyPosition;
69-
70-
if (nextPosition == new Vector3Int(0, 0, 0))
71-
Debug.Log("nextPosition never changed");
67+
// Random chance of birth (uses wandering chance) to dead/empty space
68+
if (!takenPositions.Contains(emptyPosition) && UnityEngine.Random.value > .99)
69+
{
70+
newCells.Add(new Cell(emptyPosition, CellState.alive));
71+
takenPositions.Add(emptyPosition); // Ensure position isn't taken twice
72+
}
7273

7374
// Move to next position
7475
newCells.Add(new Cell(nextPosition, CellState.alive));
@@ -124,15 +125,15 @@ private int GetPriority(CellState state)
124125

125126
if (state == CellState.alive)
126127
priority = 6;
127-
else if (state == CellState.stage2)
128-
priority = 5;
129128
else if (state == CellState.stage3)
130-
priority = 4;
129+
priority = 5;
131130
else if (state == CellState.stage4)
132-
priority = 3;
131+
priority = 4;
133132
else if (state == CellState.stage5)
134-
priority = 2;
133+
priority = 3;
135134
else if (state == CellState.dead)
135+
priority = 2;
136+
else if (state == CellState.stage2)
136137
priority = 1;
137138
else
138139
priority = 0;

0 commit comments

Comments
 (0)