[Tux4kids-commits] r645 - tuxmath/trunk/src

cheezmeister-guest at alioth.debian.org cheezmeister-guest at alioth.debian.org
Mon Aug 18 01:45:15 UTC 2008


Author: cheezmeister-guest
Date: 2008-08-18 01:45:13 +0000 (Mon, 18 Aug 2008)
New Revision: 645

Modified:
   tuxmath/trunk/src/mathcards.c
   tuxmath/trunk/src/mathcards.h
   tuxmath/trunk/src/multiplayer.c
   tuxmath/trunk/src/titlescreen.c
Log:
Final polish for GSoC: minor bug/stability fixes and comments added

Modified: tuxmath/trunk/src/mathcards.c
===================================================================
--- tuxmath/trunk/src/mathcards.c	2008-08-17 16:59:28 UTC (rev 644)
+++ tuxmath/trunk/src/mathcards.c	2008-08-18 01:45:13 UTC (rev 645)
@@ -242,7 +242,7 @@
 static void copy_card(const MC_FlashCard* src, MC_FlashCard* dest); //deep copy a flashcard
 static MC_MathQuestion* allocate_node(void); //allocate space for a node
 static int compare_card(const MC_FlashCard* a, const MC_FlashCard* b); //test for identical cards
-static int find_divisor(int a);
+static int find_divisor(int a); //return a random positive divisor of a
 static MC_MathQuestion* add_all_valid(MC_ProblemType pt, MC_MathQuestion* list, MC_MathQuestion* end_of_list);
 static MC_MathQuestion* find_node(MC_MathQuestion* list, int num);
 
@@ -1914,13 +1914,17 @@
 int find_divisor(int a)
 {
   int div = 1; //the divisor to return
+  int realisticpasses = 3; //reasonable time after which a minimum should be met
   int i;
-  for (i = 0; i < NPRIMES; ++i) //test each prime
-    if (a % smallprimes[i] == 0)  //if it is a prime factor,
-      if (rand() % (i + 1) == 0) //maybe we'll keep it
-        if (div * smallprimes[i] <= MC_GetOpt(MAX_DIVISOR) ) //if we can,
-          div *= smallprimes[i]; //update our real divisor
-  //FIXME ensure div meets minimum divisor if possible (it might not be)
+  do
+    for (i = 0; i < NPRIMES; ++i) //test each prime
+      if (a % smallprimes[i] == 0)  //if it is a prime factor,
+        if (rand() % (i + 1) == 0) //maybe we'll keep it
+          if (div * smallprimes[i] <= MC_GetOpt(MAX_DIVISOR) ) //if we can,
+            div *= smallprimes[i]; //update our real divisor
+  //keep going if the divisor is too small
+  while (div < MC_GetOpt(MIN_DIVISOR) && --realisticpasses); 
+  
   return div;
 }
 
@@ -1933,9 +1937,11 @@
 
   mcdprintf("Entering add_all_valid(%d)\n", pt);
 
+  //make sure this problem type is actually allowed
   if (!MC_GetOpt(pt + TYPING_PRACTICE_ALLOWED) )
     return list;
 
+  //add all typing questions in range
   if (pt == MC_PT_TYPING)
   {
     mcdprintf("Adding typing...\n");
@@ -1949,6 +1955,7 @@
       end_of_list = tnode;
     }
   }
+  //add all allowed arithmetic questions
   else if (MC_PT_ARITHMETIC)
   {
     mcdprintf("Adding arithmetic...\n");
@@ -2019,6 +2026,7 @@
       }
     }
   }
+  //add all comparison questions (TODO implement them!)
   else if (pt == MC_PT_COMPARISON)
   {
     for (i = MC_GetOpt(MIN_COMPARATOR); i < MC_GetOpt(MAX_COMPARATOR); ++i)
@@ -2027,6 +2035,10 @@
       {
         tnode = allocate_node();
         snprintf(tnode->card.formula_string, max_formula_size, "%d ? %d", i,j);
+        snprintf(tnode->card.answer_string, max_formula_size,
+                 i < j ? "<" : 
+                 i > j ? ">" : 
+                         "=");
         list = insert_node(list, end_of_list, tnode);
         end_of_list = tnode;
       }
@@ -2042,6 +2054,7 @@
     list = list->next;
   return list;
 }
+
 void reformat_arithmetic(MC_FlashCard* card, MC_Format f)
 {
   int i, j;
@@ -2051,7 +2064,7 @@
   char nformula[max_formula_size + max_answer_size]; //gets a bit larger than usual in the meantime
   
   {
-    snprintf(nans, max_answer_size, "%s", card->answer_string);
+    //snprintf(nans, max_answer_size, "%s", card->answer_string);
    
     //insert old answer where question mark was
     for (i = 0, j = 0; card->formula_string[j] != '?'; ++i, ++j)

Modified: tuxmath/trunk/src/mathcards.h
===================================================================
--- tuxmath/trunk/src/mathcards.h	2008-08-17 16:59:28 UTC (rev 644)
+++ tuxmath/trunk/src/mathcards.h	2008-08-18 01:45:13 UTC (rev 645)
@@ -24,6 +24,7 @@
 
 #define MC_USE_NEWARC
 
+/* different classes of problems TuxMath will ask */
 typedef enum _MC_ProblemType {
   MC_PT_TYPING,
   MC_PT_ARITHMETIC,
@@ -123,8 +124,8 @@
   RANDOMIZE                 , /* whether to shuffle cards */
 
   COMPREHENSIVE             , /* whether to generate all questions 'in order' */
-  AVG_LIST_LENGTH           ,
-  VARY_LIST_LENGTH          ,
+  AVG_LIST_LENGTH           , /* the average number of questions in a list */
+  VARY_LIST_LENGTH          , /* whether to randomly adjust list length */
 
   NOPTS
 };
@@ -145,8 +146,7 @@
 typedef struct _MC_Options
 {
   int iopts[NOPTS];
-  //float fraction_to_keep; //being a float, we can't keep this in the same array
-} MC_Options;             //it'll stay a special case, unless more float options
+} MC_Options;
 
 #ifndef MC_USE_NEWARC
 /* struct for individual "flashcard" */
@@ -280,14 +280,14 @@
 int MC_GetOpt(unsigned int index);
 void MC_SetOp(const char* param, int val); //access by text, for config reading
 int MC_GetOp(const char* param);
-void MC_SetFractionToKeep(float val);
-float MC_GetFractionToKeep(void);
 int MC_VerifyOptionListSane(void);
-int MC_MaxFormulaSize(void);
+int MC_MaxFormulaSize(void); //amount of memory needed to safely hold strings
 int MC_MaxAnswerSize(void);
 MC_FlashCard MC_AllocateFlashcard();
 void MC_FreeFlashcard(MC_FlashCard* fc);
-void MC_ResetFlashCard(MC_FlashCard* fc);
+void MC_ResetFlashCard(MC_FlashCard* fc); //empty flashcard of strings & values
 int MC_FlashCardGood(const MC_FlashCard* fc); //verifies a flashcard is valid
+/* Reorganize formula_string and answer_string to render the same equation
+   in a different format */
 void reformat_arithmetic(MC_FlashCard* card, MC_Format f);
 #endif

Modified: tuxmath/trunk/src/multiplayer.c
===================================================================
--- tuxmath/trunk/src/multiplayer.c	2008-08-17 16:59:28 UTC (rev 644)
+++ tuxmath/trunk/src/multiplayer.c	2008-08-18 01:45:13 UTC (rev 645)
@@ -57,12 +57,12 @@
     return;
   }
 
-
-  if (params[MODE] == ELIMINATION)
+  //cycle through players until all but one has lost
+  if (params[MODE] == ELIMINATION) 
   {
     while(!done)
     {
-
+      //TODO maybe gradually increase difficulty
       game_set_start_message(pnames[currentplayer], "Go!", "", "");
       result = game();
 
@@ -73,7 +73,7 @@
         winners[--activeplayers] = currentplayer;
       }
             
-      do
+      do //move to the next player
       {
         ++currentplayer;
         currentplayer %= params[PLAYERS];
@@ -90,6 +90,7 @@
       }
     }
   }
+  //players take turns, accumulating score, and the highest score wins
   else if (params[MODE] == SCORE_SWEEP)
   {
     int hiscore = 0;
@@ -178,11 +179,13 @@
 
   while (box.h < screen->h || box.w < screen->w)
   {
+    //expand black box
     box.x -= boxspeed;
     box.y -= boxspeed;
     box.h += boxspeed * 2;
     box.w += boxspeed * 2;
 
+    //reveal text specifying the winner
     SDL_FillRect(screen, &box, 0);
     draw_text(text, center);
     SDL_UpdateRect(screen, box.x, box.y, box.w, box.h);
@@ -194,11 +197,11 @@
       break;
     SDL_Delay(50);
   }
-
+  //in case we've skipped, cover the whole screen
   SDL_FillRect(screen, NULL, 0);
   draw_text(text, center);
   SDL_Flip(screen);
-  WaitForEvent(SDL_KEYDOWNMASK);
+  WaitForEvent(SDL_KEYDOWNMASK | SDL_MOUSEBUTTONDOWNMASK);
 }
 
 int initMP()
@@ -232,13 +235,17 @@
   for (i = 0; i < nplayers; ++i)
     pnames[i] = malloc((1 + 3 * HIGH_SCORE_NAME_LENGTH) * sizeof(char) );
   for (i = 0; i < nplayers; ++i)
+  {
     if (pnames[i])
       NameEntry(pnames[i], "Who is playing?", "Enter your name:");
     else
-      {
-        printf("Can't allocate name %d!\n", i);
-        return 1;
-      }
+    {
+      printf("Can't allocate name %d!\n", i);
+      return 1;
+    }
+  }
+  
+  //enter how many rounds
   if (params[MODE] == SCORE_SWEEP)
   {
     while (params[ROUNDS] <= 0)

Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c	2008-08-17 16:59:28 UTC (rev 644)
+++ tuxmath/trunk/src/titlescreen.c	2008-08-18 01:45:13 UTC (rev 645)
@@ -350,7 +350,7 @@
       SDL_BlitSurface(images[IMG_MENU_TITLE], NULL, screen, &Titledest);
       SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
 
-      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h + TuxPixSkip);
+      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
       SDL_UpdateRect(screen, Titledest.x, Titledest.y, Titledest.w + TitlePixSkip, Titledest.h);
       SDL_UpdateRect(screen, stopRect.x, stopRect.y, stopRect.w, stopRect.h);
 




More information about the Tux4kids-commits mailing list