[Tux4kids-commits] r1169 - tuxmath/branches/lan/server
David Bruce
dbruce-guest at alioth.debian.org
Thu Jul 9 21:23:31 UTC 2009
Author: dbruce-guest
Date: 2009-07-09 21:23:31 +0000 (Thu, 09 Jul 2009)
New Revision: 1169
Modified:
tuxmath/branches/lan/server/mathcards.c
Log:
updated MC_NotAnsweredCorrectly() to use active_quests list
Modified: tuxmath/branches/lan/server/mathcards.c
===================================================================
--- tuxmath/branches/lan/server/mathcards.c 2009-07-09 21:01:38 UTC (rev 1168)
+++ tuxmath/branches/lan/server/mathcards.c 2009-07-09 21:23:31 UTC (rev 1169)
@@ -546,16 +546,17 @@
return 0;
}
+ if(!active_quests) // No questions currently "in play" - something is wrong:
+ {
+ fprintf(stderr, "MC_AnsweredCorrectly() - active_quests empty\n");
+ return 0;
+ }
+
#ifdef MC_DEBUG
printf("\nQuestion was:");
print_card(*fc);
#endif
- if(!active_quests) // Means we didn't find matching card - something is wrong:
- {
- fprintf(stderr, "MC_AnsweredCorrectly() - active_quests empty\n");
- return 0;
- }
//First take the question out of the active_quests list
quest = active_quests;
@@ -577,6 +578,8 @@
//main question list in a random location, or delete it:
active_quests = remove_node(active_quests, quest);
questions_pending--; //the length of the 'active_quests' list
+
+
answered_correctly++;
if (!math_opts->iopts[PLAY_THROUGH_LIST])
@@ -639,6 +642,8 @@
return MC_AnsweredCorrectly(fc);
}
+
+
/* MC_NotAnsweredCorrectly() is how the user interface */
/* tells MathCards that the player failed to answer the */
/* question correctly. Returns 1 if no errors. */
@@ -648,6 +653,8 @@
{
mcdprintf("\nEntering MC_NotAnsweredCorrectly()");
+ MC_MathQuestion* quest = NULL;
+
if (!fc)
{
fprintf(stderr, "\nMC_NotAnsweredCorrectly() passed invalid pointer as argument!\n");
@@ -658,44 +665,67 @@
return 0;
}
+ if(!active_quests) // No questions currently "in play" - something is wrong:
+ {
+ fprintf(stderr, "MC_NotAnsweredCorrectly() - active_quests empty\n");
+ return 0;
+ }
+
#ifdef MC_DEBUG
printf("\nQuestion was:");
print_card(*fc);
#endif
- answered_wrong++;
- questions_pending--;
- /* add question to wrong_quests list: */
+ //First take the question out of the active_quests list
+ quest = active_quests;
+ // Loop until quest is NULL or we find card with same id:
+ while(quest && (fc->question_id != quest->card.question_id))
+ quest = quest->next;
+ if(!quest) // Means we didn't find matching card - something is wrong:
+ {
+ fprintf(stderr, "MC_NotAnsweredCorrectly() - matching question not found!\n");
+ return 0;
+ }
+ #ifdef MC_DEBUG
+ printf("\nMatching question is:");
+ print_card(quest->card);
+ #endif
- MC_MathQuestion* ptr1;
- MC_MathQuestion* ptr2;
+ //We found a matching question, now we take it out of the
+ //"active_quests" list and either put it back into the
+ //main question list in a random location, or delete it:
+ active_quests = remove_node(active_quests, quest);
+ questions_pending--; //the length of the 'active_quests' list
- ptr1 = create_node_from_card(fc);
+ answered_wrong++;
- if (!already_in_list(wrong_quests, ptr1)) /* avoid duplicates */
+ /* add question to wrong_quests list: */
+ if (!already_in_list(wrong_quests, quest)) /* avoid duplicates */
{
mcdprintf("\nAdding to wrong_quests list");
- wrong_quests = append_node(wrong_quests, ptr1);
+ wrong_quests = append_node(wrong_quests, quest);
}
else /* avoid memory leak */
{
- free(ptr1);
+ free(quest);
}
/* if desired, put question back in list so student sees it again */
if (math_opts->iopts[REPEAT_WRONGS])
{
int i;
+ MC_MathQuestion* quest_copy;
+ MC_MathQuestion* rand_loc;
mcdprintf("\nAdding %d copies to question_list:", math_opts->iopts[COPIES_REPEATED_WRONGS]);
/* can put in more than one copy (to drive the point home!) */
for (i = 0; i < math_opts->iopts[COPIES_REPEATED_WRONGS]; i++)
{
- ptr1 = create_node_from_card(fc);
- ptr2 = pick_random(quest_list_length, question_list);
- question_list = insert_node(question_list, ptr2, ptr1);
+ quest_copy = create_node_from_card(fc);
+ rand_loc = pick_random(quest_list_length, question_list);
+ question_list = insert_node(question_list, rand_loc, quest_copy);
quest_list_length++;
}
/* unanswered stays the same if a single copy recycled or */
@@ -736,6 +766,7 @@
}
}
+
/* Returns number of questions left (either in list */
/* or "in play") */
int MC_TotalQuestionsLeft(void)
More information about the Tux4kids-commits
mailing list