Imagination boosts strategy learning in artificial and human agents