+ printf ("\n");
+
+ do {
+ mnemon_select_item (mnemon, &bin, &item_index);
+
+ if (bin->score == 0)
+ to_introduce--;
+
+ item = bin->items[item_index];
+
+ printf ("%s\n", item->challenge);
+
+ response = readline ("> ");
+ if (response == NULL) {
+ printf ("\n");
+ break;
+ }
+
+ correct = (strcmp (response, item->response) == 0);
+
+ bin_remove_item (bin, item_index);
+
+ /* If the bin is now empty, we must remove it. Also if we just
+ * picked the last word we'll ever pick from the bin with
+ * score 0, then we can remove that as well. */
+ if (bin->num_items == 0 ||
+ (bin->score == 0 && to_introduce == 0))
+ {
+ mnemon_remove_bin (mnemon, bin);
+ }
+
+ if (correct) {
+ item->score++;
+ /* We reserve an item score of 0 for an item that has
+ * never been asked. */
+ if (item->score == 0) {
+ item->score = 1;
+ unlearned--;
+ printf ("You got it!");
+ } else if (item->score < 0) {
+ printf ("Yes---just give me %d more.",
+ - item->score);
+ } else if (item->score == 1) {
+ printf ("On your first try, no less!");
+ } else {
+ printf ("Masterful (%dx).", item->score);
+ }
+ } else {
+ printf (" %s is the correct answer.",
+ item->response);
+ /* Penalize an incorrect response by forcing the score
+ * negative. */
+ if (item->score >= 0) {
+ if (item->score > 0)
+ printf ( " Oops, you knew that, right?\n ");
+ unlearned++;
+ mastered = 0;
+ /* We go to -2 to force a little extra reinforcement
+ * when re-learning an item, (otherwise, it will often
+ * get asked again immediately where it is easy to get
+ * a correct response without any learning). */
+ item->score = -2;
+ } else {
+ item->score--;
+ }
+ }
+
+ printf (" (");
+ if (to_introduce)
+ printf ("%d to come.", to_introduce);
+ if (to_introduce && unlearned)
+ printf (" ");
+ if (unlearned)
+ printf ("%d still unlearned.", unlearned);
+ if (to_introduce == 0 && unlearned == 0) {
+ if (mastered < to_master)
+ printf ("%d items to master",
+ to_master - mastered);
+ else
+ printf ("Great job!");
+ mastered++;
+ }
+ printf (")\n\n");
+
+ bin = mnemon_get_bin (mnemon, item->score);
+
+ bin_add_item (bin, item);
+ } while (mastered <= to_master);