private void EndDeadFuctionality(EntitiesCellResult result) { if (result.CellAliveReal_ForNewBorn == 3) { this._isAlive = true; } }
public override void OnEnd() { if (this._isNewBorn) { return; } this._parent.CheckCellScope(this, 1); EntitiesCellResult result = this.NumberOfCellNeighbours(this._positionX, this._positionY); if (this._isAlive) { EndAliveFuctionality(result); } else { EndDeadFuctionality(result); } if (!this._isAlive) { this._isDeletable = true; } }
public EntitiesCellResult NumberOfCellNeighbours(int posX, int posY, bool countNewBornCells = false) { EntitiesCellResult result = new EntitiesCellResult(); if (posX == 2 && posY == 2) { result.CellsAlive = 0; } foreach (Entity e in this._list) { if (e.Type != EntityType.Cell) { continue; } Cell cell = e as Cell; if (cell.PositionX == posX && cell.PositionY == posY) { result.CellLocated = cell; continue; } //if (!cell.IsAlive) // continue; if (!countNewBornCells && cell.IsNewBorn) { continue; } int difx = posX - cell.PositionX; int dify = posY - cell.PositionY; if (difx >= -1 && difx <= 1 && dify >= -1 && dify <= 1) { if (cell.IsAlive) { result.CellsAlive++; } else { result.CellsDead++; } if (cell.IsNewBorn) { result.CellNewBorns++; } } } return(result); }
public void CheckCellScope(Cell original, int depth) { if (!original.IsAlive || original.IsNewBorn) { return; } for (int y = original.PositionY - depth; y <= original.PositionY + depth; y++) { if (y < 0 || y > this._xyLimit) { y++; continue; } for (int x = original.PositionX - depth; x <= original.PositionX + depth; x++) { if (x < 0 || x > this._xyLimit) { x++; continue; } if (original.PositionX == x && original.PositionY == y) { continue; } EntitiesCellResult result = this.NumberOfCellNeighbours(x, y); if (result.CellsAlive == 0 && result.CellsDead == 0) { continue; } if (result.CellAliveReal_ForNewBorn == 3) { if (result.CellLocated == null) { // Cell newCell = new Cell(x, y, this); newCell.IsNewBorn = true; // this._list.Add(newCell); // Console.WriteLine("New cell is born " + x + "x" + y); this.AddNewCell(x, y, true, false, false); } else if (!result.CellLocated.IsAlive) { result.CellLocated.IsNewBorn = true; result.CellLocated.SetAlive(true); } } } } }
private void EndAliveFuctionality(EntitiesCellResult result) { if (result.CellAliveReal_ForNewBorn < 2) { this._isAlive = false; } else if (result.CellAliveReal_ForNewBorn >= 2 && result.CellAliveReal_ForNewBorn <= 3) { return; } else if (result.CellAliveReal_ForNewBorn > 3) { this._isAlive = false; } }