private IAction? WithRandomUnoccupiedCell(IOrganismEnvironment environment, UnoccupiedCellMapper unoccupiedCellMapper) { var unoccupiedNeighbours = environment.GetFreeNeighbours().ToList(); if (unoccupiedNeighbours.Count == 0) { return null; } var destination = RandomElementPicker.PickRandomElement(unoccupiedNeighbours); return unoccupiedCellMapper(destination); }
private IAction?Reproduce(OrganismKind ownKind, IOrganismEnvironment environment) { var unoccupiedNeighbours = environment.GetFreeNeighbours().ToList(); if (unoccupiedNeighbours.Count == 0) { return(null); } var destination = RandomElementPicker.PickRandomElement(unoccupiedNeighbours); var clone = Organism.Clone(); return(new Copy(destination, clone, ownKind)); }