Ejemplo n.º 1
0
// opDivide: spawn a new organism in neighboring cell with same bytecode
// and energy fraction described by A/256.
func opDivide(o *org.Organism, c *Cpu) error {
	lenc := len(c.Code)
	if err := o.Discharge(lenc); err != nil {
		return err
	}
	nc := c.Copy()
	if rand.Float64() < MutationRate {
		nc.Mutate()
	}
	n, err := o.Divide(nc, float64(c.R[0])/256.0)
	if err == org.ErrNotEmpty {
		return nil
	}
	if err != nil {
		return err
	}
	go nc.Run(n)
	return nil
}