Skip to content

Commit

Permalink
Added max vertical drop parameter and fixed roomers not spawning prop…
Browse files Browse the repository at this point in the history
…erly on tunneler death
  • Loading branch information
1upD committed Apr 30, 2018
1 parent 6765c1e commit 346eab7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion Alife/Agents/Roomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Roomer : BaseAgent
private int _x2;
private int _y1;
private int _y2;
private int _dz;
public int Height;
public string Style;
public int MaxWidth;
Expand Down
16 changes: 7 additions & 9 deletions Alife/Agents/Tunneler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Tunneler : BaseAgent
public AlifeDirection Direction;
public bool SpawnRoomerOnDeath;
public int LifetimeDecayRate;
public int MaxVerticalDrop;

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Expand All @@ -57,6 +58,7 @@ public Tunneler()
this.MinHeightDecayRate = 0;
this.MaxWidthDecayRate = 0;
this.MinWidthDecayRate = 0;
this.MaxVerticalDrop = 1;
this.ProbSpawnRoomer = 0.0f;
this.SpawnRoomerOnDeath = true;
this.LifetimeDecayRate = 1;
Expand All @@ -72,7 +74,7 @@ public Tunneler(string style = "", int x = 0, int y = 0, int z = 0,
int width = 1, int height = 2,
int lifetime = 1, int maxLifetime = 1,
float probReproduce = 0.0f, float probTurn = 0.0f, float probAscend = 0.0f,
AlifeDirection direction = AlifeDirection.East, int MaxHeighDecayRate = 0, int MinHeightDecayRate = 0, int MaxWidthDecayRate = 0, int MinWidthDecayRate = 0, float ProbSpawnRoomer = 0.0f, bool spawnRoomerOnDeath = true, int LifeTimeDecayRate = 1)
AlifeDirection direction = AlifeDirection.East, int MaxHeighDecayRate = 0, int MinHeightDecayRate = 0, int MaxWidthDecayRate = 0, int MinWidthDecayRate = 0, float ProbSpawnRoomer = 0.0f, bool spawnRoomerOnDeath = true, int LifeTimeDecayRate = 1, int maxVerticalDrop = 2)
{
this.X = x;
this.Y = y;
Expand All @@ -89,6 +91,7 @@ public Tunneler(string style = "", int x = 0, int y = 0, int z = 0,
this.ProbSpawnRoomer = ProbSpawnRoomer;
this.SpawnRoomerOnDeath = spawnRoomerOnDeath;
this.LifetimeDecayRate = 1;
this.MaxVerticalDrop = 1;

log.Debug(string.Format("Tunneler spawned at {0}, {1}, {2}.", this.X, this.Y, this.Z));
}
Expand Down Expand Up @@ -119,9 +122,6 @@ public override int GetTurnsLeft()
public override void Step(AlifeMap map)
{
try {
// Check if agent is still alive
if (this.Lifetime > 0)
{
int seed = this.X + this.Y + this.Z + (int)this.Direction + this.Height + this.Width + (int)System.DateTime.Now.Ticks;

// Get random number
Expand Down Expand Up @@ -167,7 +167,8 @@ public override void Step(AlifeMap map)
if (sample < this.ProbAscend)
{
sample = random.NextDouble();
int polarity = sample > 0.5 ? this.Height : -this.Height;
int verticalDistance = random.Next(1, Math.Min(this.Height, this.MaxVerticalDrop));
int polarity = sample > 0.5 ? verticalDistance : -verticalDistance;
this.Z += polarity;
}
else
Expand Down Expand Up @@ -212,16 +213,13 @@ public override void Step(AlifeMap map)
}
}

}
else if (this.SpawnRoomerOnDeath)
if (this.Lifetime == 1 && this.SpawnRoomerOnDeath)
{
log.Debug(string.Format("Tunneler died at {0}, {1}, {2}.", this.X, this.Y, this.Z));

// Add a roomer
Roomer child = new Roomer(x: this.X, y: this.Y, z: this.Z, style: this.Style, height: Math.Max(this.Height, 2), maxWidth: Math.Min(this.Width * 2, 3));
map.Agents.Add(child);


}

this.Lifetime--;
Expand Down

0 comments on commit 346eab7

Please sign in to comment.