Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
        }