]> git.cworth.org Git - mnemon/blobdiff - mnemon.c
Fix to not pull from bin with score 0 when there are no items to introduce.
[mnemon] / mnemon.c
index 9f28dfeb7a88dce584484c5648fafa0b75e49f6e..72c5174cd7e1ba067b3dcabb79cd5397f35c5ab8 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -627,14 +627,15 @@ mnemon_select_item (mnemon_t       *mnemon,
 
 static void
 mnemon_do_challenges (mnemon_t *mnemon,
-                     int       to_introduce)
+                     int       to_introduce,
+                     int       to_master)
 {
     bin_t *bin;
     int item_index;
     item_t *item;
     char *response;
     bool_t correct;
-    int unlearned;
+    int unlearned, mastered = 0;
     int i;
 
     /* Count the number of items with negative scores. */
@@ -650,6 +651,13 @@ mnemon_do_challenges (mnemon_t *mnemon,
     if (to_introduce < 0)
        to_introduce = 0;
 
+    /* Get rid of bin with score of 0 if we aren't going to be
+     * introducing anything from it. */
+    if (to_introduce == 0) {
+       bin = mnemon_get_bin (mnemon, 0);
+       mnemon_remove_bin (mnemon, bin);        
+    }
+
     if (unlearned) {
        printf ("You've got %d items to learn already. ", unlearned);
        if (to_introduce)
@@ -708,14 +716,20 @@ mnemon_do_challenges (mnemon_t *mnemon,
        } else {
            printf ("  %s is the correct answer.",
                    item->response);
-           if (item->score >= 0)
-               unlearned++;
-           item->score--;
            /* Penalize an incorrect response by forcing the score
             * negative. */
            if (item->score >= 0) {
-               item->score = -1;
-               printf ( " Oops, you knew that, right?\n ");
+               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--;
            }
        }
 
@@ -726,20 +740,28 @@ mnemon_do_challenges (mnemon_t *mnemon,
            printf (" ");
        if (unlearned)
            printf ("%d still unlearned.", unlearned);
-       if (to_introduce == 0 && unlearned == 0)
-           printf ("Great job!");
+       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 (unlearned || to_introduce);
+    } while (mastered <= to_master);
 }
 
 int
 main (int argc, char *argv[])
 {
     mnemon_t mnemon;
+    int to_introduce   = 3;
+    int to_master      = 10;
 
     srand (time (NULL));
 
@@ -747,7 +769,9 @@ main (int argc, char *argv[])
 
     mnemon_load (&mnemon);
 
-    mnemon_do_challenges (&mnemon, 10);
+    mnemon_do_challenges (&mnemon,
+                         to_introduce,
+                         to_master);
 
     mnemon_save (&mnemon);