"""
Artificial life: biomorphs and L-system plants
==============================================

Richard Dawkins' biomorphs (1986) — recursive trees whose genes set branch
lengths and angles — started interactive evolution; the user acts as the
selective environment. Lindenmayer systems (Prusinkiewicz and Lindenmayer,
1990) rewrite strings into plant architectures; here the genes set the
branching angle, the rewriting rules and the colours.
"""

# %%
# Breeding plants with comments
# -----------------------------
import matplotlib.pyplot as plt

import easyiec as ei
from easyiec.problems import Biomorph, LSystemPlant
from easyiec.strategies import InteractiveGA, Watchmaker

problem = LSystemPlant()
print(sorted(problem.semantic_axes))
user = ei.SimulatedUser(problem, target="random", noise=0.03, comments=0.7, seed=4)
result = ei.run(problem, InteractiveGA(pop_size=8), user, generations=10, seed=4)
print([r.feedback.comment for r in result.log.records if r.feedback.comment])
ei.viz.plot_history(result.log, problem, steps=[0, 4, 9], max_items=8, size=1.0)

# %%
# Biomorphs in the Watchmaker scheme
# ----------------------------------
problem = Biomorph()
user = ei.SimulatedUser(problem, target="random", noise=0.03, seed=9)
res = ei.run(problem, Watchmaker(pop_size=9), user, generations=20, seed=9)
ei.viz.plot_lineage(res.log, problem, size=0.9)
plt.show()
