One piece at a time: Learning complex rules through self-directed sampling