|
using System.Collections.Generic;
using System.Linq;
using gameOfLife.Framework;
namespace gameOfLife.Transition
{
public class Spawn : ITransition
{
public void Apply(ITransitive cellContainer)
{
var neighbouringDeadCells = GetNeighbouringDeadCells(cellContainer.Cells).
Where((cell) => CanBeMadeAlive(cellContainer.Cells, cell)).ToList();
foreach (var cell in neighbouringDeadCells)
{
cellContainer.Cells.Add(cell);
}
}
private bool CanBeMadeAlive(IList<Cell> otherCells, Cell cell)
{
return cell.NeighbouringLocations.Match(otherCells).Count == 3;
}
private IList<Cell> GetNeighbouringDeadCells(IList<Cell> cells)
{
IList<Cell> result = new List<Cell>();
foreach (var cell in cells)
{
if (cell.IsAlive)
{
foreach (var temp in cell.NeighbouringLocations.Filter(cells))
{
if (!result.Contains(temp))
{
result.Add(new Cell(temp.X, temp.Y));
// cannot add proxy cells in the pattern. Thus creating a real cell object
}
}
}
}
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
is a poor software developer and thinker. Presently working on a theory of "complementary perception". It's a work in progress.