public void LifeCicle() { for (Int32 i = 0; i < 10; i++) { if (Dish.Validate(Vector.Add(Direction, CurrentPoint), this)) { CurrentPoint = Vector.Add(Direction, CurrentPoint); DivisionCounter--; if (DivisionCounter == 0) { DivisionCounter = GetDivisionCounter(); Bacterium child = new Bacterium(this); Dish.AddNewBacterium(child); } break; } else { Direction = NewDirection(); DirectionCounter = GetDirectionCounter(); } } Counter++; DirectionCounter--; LifeCounter--; if (DirectionCounter == 0) { Direction = NewDirection(); DirectionCounter = GetDirectionCounter(); } }
public Bacterium[] GetNearestBacteria(Point p) { Int32 i = (Int32)Math.Truncate(p.X / ClusterDimension); Int32 j = (Int32)Math.Truncate(p.Y / ClusterDimension); Int32 mFrom = i - 1 < 0 ? 0 : i - 1; Int32 mTo = i + 1 >= CntCluster ? CntCluster - 1 : i + 1; Int32 nFrom = j - 1 < 0 ? 0 : j - 1; Int32 nTo = j + 1 >= CntCluster ? CntCluster - 1 : j + 1; Bacterium[] output = new Bacterium[0]; for (Int32 m = mFrom; m <= mTo; m++) { for (Int32 n = nFrom; n <= nTo; n++) { if (Storage[m, n] == null) { continue; } Int32 c = output.Length; Array.Resize(ref output, output.Length + Storage[m, n].Length); for (Int32 k = 0; k <= Storage[m, n].Length - 1; k++) { output[c + k] = Storage[m, n][k]; } } } return(output); }
public void MoveCluster(Bacterium b, Point p) { Int32 i1 = (Int32)Math.Truncate(b.CurrentPoint.X / ClusterDimension); Int32 j1 = (Int32)Math.Truncate(b.CurrentPoint.Y / ClusterDimension); Int32 i2 = (Int32)Math.Truncate(p.X / ClusterDimension); Int32 j2 = (Int32)Math.Truncate(p.Y / ClusterDimension); if ((i1 == i2) && (j1 == j2)) { return; } else { Storage[i1, j1] = Storage[i1, j1].Where(x => x != b).ToArray(); if (Storage[i2, j2] == null) { Array.Resize(ref Storage[i2, j2], 1); } else { Array.Resize(ref Storage[i2, j2], Storage[i2, j2].Length + 1); } Storage[i2, j2][Storage[i2, j2].Length - 1] = b; } }
public void Distribute(Bacterium b) { Int32 i = (Int32)Math.Truncate(b.CurrentPoint.X / ClusterDimension); Int32 j = (Int32)Math.Truncate(b.CurrentPoint.Y / ClusterDimension); if (Storage[i, j] == null) { Storage[i, j] = new Bacterium[] { b }; } else { Array.Resize(ref Storage[i, j], Storage[i, j].Length + 1); Storage[i, j][Storage[i, j].Length - 1] = b; } }
public Bacterium(Bacterium parent) : this(parent.CurrentPoint, parent.Speed, parent.Dish) { Generation = parent.Generation++; }