[Tux4kids-commits] r564 - tuxmath/branches/mathcards_newarch/src

cheezmeister-guest at alioth.debian.org cheezmeister-guest at alioth.debian.org
Mon Jul 7 00:45:49 UTC 2008


Author: cheezmeister-guest
Date: 2008-07-07 00:45:49 +0000 (Mon, 07 Jul 2008)
New Revision: 564

Modified:
   tuxmath/branches/mathcards_newarch/src/game.c
   tuxmath/branches/mathcards_newarch/src/mathcards.c
   tuxmath/branches/mathcards_newarch/src/mathcards.h
   tuxmath/branches/mathcards_newarch/src/titlescreen.c
   tuxmath/branches/mathcards_newarch/src/titlescreen.h
Log:
Fixed a bug with multiple-digit negative answers.



Modified: tuxmath/branches/mathcards_newarch/src/game.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/game.c	2008-07-06 17:49:30 UTC (rev 563)
+++ tuxmath/branches/mathcards_newarch/src/game.c	2008-07-07 00:45:49 UTC (rev 564)
@@ -1076,7 +1076,7 @@
 */
   /* negative answer support DSB */
   
-  ans[0] = '-'; //this is replaced for a positive answer
+  ans[0] = '-'; //for math questions only, this is just replaced.
   for (i = 0; i < MAX_DIGITS - 1 && !digits[i]; ++i); //skip leading 0s
   for (j = neg_answer_picked ? 1 : 0; i < MAX_DIGITS; ++i, ++j)
     ans[j] = digits[i] + '0';

Modified: tuxmath/branches/mathcards_newarch/src/mathcards.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.c	2008-07-06 17:49:30 UTC (rev 563)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.c	2008-07-07 00:45:49 UTC (rev 564)
@@ -337,7 +337,7 @@
   max_formula_size = MC_GetOpt(MAX_FORMULA_NUMS)
                    * ((int)(log10f(MC_GLOBAL_MAX) ) + 4) //sign/operator/spaces
                    + 1; //question mark for answer
-  max_answer_size = (int)(log10f(MC_GLOBAL_MAX) ) + 1; //negative sign
+  max_answer_size = (int)(log10f(MC_GLOBAL_MAX) ) + 2; //negative sign + digit
   
   mcdprintf("max answer, formula size: %d, %d\n", 
             max_answer_size, max_formula_size);
@@ -451,7 +451,7 @@
 int MC_NextQuestion(MC_FlashCard* fc)
 {
   #ifdef MC_DEBUG
-  printf("\nEntering MC_NextQuestion()");
+  printf("\nEntering MC_NextQuestion()\n");
   #endif
 
   /* (so we can free the node after removed from list:) */
@@ -481,18 +481,13 @@
 
     return 0;
   }
-  copy_card(&question_list->card, fc);
-//  fc->num1 = question_list->card.num1;
-//  fc->num2 = question_list->card.num2;
-//  fc->num3 = question_list->card.num3;
-//  fc->operation = question_list->card.operation;
-//  fc->format = question_list->card.format;
-//  strncpy(fc->formula_string, question_list->card.formula_string, MC_FORMULA_LEN);  
-//  strncpy(fc->answer_string, question_list->card.answer_string, MC_ANSWER_LEN);  
+  
+  /* 'draw' - copy over the first question */
+  copy_card(&question_list->card, fc); 
 
-  /* take first question node out of list and free it:   */
+  /* 'discard' - take first question node out of list and free it */
   question_list = remove_node(question_list, question_list);
-  free(ptr);
+  free_node(ptr);
   quest_list_length--;
   questions_pending++;
 
@@ -500,7 +495,7 @@
   printf("\nnext question is:");
   print_card(*fc);
   print_counters();
-  printf("\nLeaving MC_NextQuestion()\n");
+  printf("\n\nLeaving MC_NextQuestion()\n");
   #endif
 
   return 1;
@@ -2010,6 +2005,7 @@
   mcdprintf("copying '%s' to '%s'\n", src->answer_string, dest->answer_string);
   strncpy(dest->formula_string, src->formula_string, max_formula_size);
   strncpy(dest->answer_string, src->answer_string, max_answer_size);
+  mcdprintf("Card is: '%s', '%s'\n", dest->formula_string, dest->answer_string);
   dest->answer = src->answer;
   dest->difficulty = src->difficulty;
 }
@@ -2063,15 +2059,16 @@
   {
     mcdprintf("Generating typing question\n");
     ret = MC_AllocateFlashcard();
-    num = rand() % (MC_GetOpt(MAX_TYPING_NUM) - MC_GetOpt(MIN_TYPING_NUM) )
-                + MC_GetOpt(MIN_TYPING_NUM);
+    num = rand() % (MC_GetOpt(MAX_TYPING_NUM)-MC_GetOpt(MIN_TYPING_NUM) + 1) - 1
+                  + MC_GetOpt(MIN_TYPING_NUM);
     snprintf(ret.formula_string, max_formula_size, "%d", num);
     snprintf(ret.answer_string, max_answer_size, "%d", num);
     ret.difficulty = 10;
   }
   else //if (pt == MC_PT_ARITHMETIC)
   {
-    length = rand() % (MC_GetOpt(MAX_FORMULA_NUMS)-MC_GetOpt(MIN_FORMULA_NUMS) )
+    length = rand() % (MC_GetOpt(MAX_FORMULA_NUMS) -
+                       MC_GetOpt(MIN_FORMULA_NUMS) + 1) - 1 //avoid div by 0
                     +  MC_GetOpt(MIN_FORMULA_NUMS);
     mcdprintf("Generating question of length %d", length);
     ret = generate_random_ooo_card_of_length(length);
@@ -2136,7 +2133,8 @@
       mcdprintf("Invalid operator: value %d\n", op);
  
     mcdprintf("Constructing answer_string\n");     
-    snprintf(ret.answer_string, max_answer_size, "%d", ans);
+    snprintf(ret.answer_string, max_answer_size+1, "%d", ans);
+    mcdprintf("'%s' vs '%d'\n", ret.answer_string, ans);
     mcdprintf("Constructing formula_string\n");
     snprintf(ret.formula_string, max_formula_size, "%d %c %d", 
              r1, operchars[op], r2);

Modified: tuxmath/branches/mathcards_newarch/src/mathcards.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.h	2008-07-06 17:49:30 UTC (rev 563)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.h	2008-07-07 00:45:49 UTC (rev 564)
@@ -15,7 +15,7 @@
 #ifndef MATHCARDS_H
 #define MATHCARDS_H
 
-//#define MC_DEBUG
+#define MC_DEBUG
 #ifdef MC_DEBUG
 #define mcdprintf(...) printf(__VA_ARGS__)
 #else

Modified: tuxmath/branches/mathcards_newarch/src/titlescreen.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/titlescreen.c	2008-07-06 17:49:30 UTC (rev 563)
+++ tuxmath/branches/mathcards_newarch/src/titlescreen.c	2008-07-07 00:45:49 UTC (rev 564)
@@ -1111,7 +1111,7 @@
 /* (the function returns the index for the selected menu item)  */
 /* -1 indicates that the user pressed escape                    */
 /****************************************************************/
-int choose_menu_item(const unsigned char **menu_text, sprite **menu_sprites, int n_menu_entries, menu_options* custom_mo, void (*set_custom_menu_opts)(menu_options*) )
+int choose_menu_item(const char **menu_text, sprite **menu_sprites, int n_menu_entries, menu_options* custom_mo, void (*set_custom_menu_opts)(menu_options*) )
 {
   // Pixel renderings of menu text choices
   SDL_Surface **menu_item_unselected = NULL;

Modified: tuxmath/branches/mathcards_newarch/src/titlescreen.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/titlescreen.h	2008-07-06 17:49:30 UTC (rev 563)
+++ tuxmath/branches/mathcards_newarch/src/titlescreen.h	2008-07-07 00:45:49 UTC (rev 564)
@@ -157,7 +157,11 @@
 /*In titlescreen.c */
 void TitleScreen(void);
 int ChooseMission(void);  //FIXME really should be in fileops.c
-int choose_menu_item(const unsigned char**, sprite**, int, menu_options*, void (*)(menu_options*) );
+int choose_menu_item(const char **menu_text, 
+                     sprite **menu_sprites, 
+                     int n_menu_entries, 
+                     menu_options* custom_mo, 
+                     void (*set_custom_menu_opts)(menu_options*) );
 void set_default_menu_options(menu_options *);
 
 
@@ -167,7 +171,9 @@
 Mix_Chunk   *LoadSound( char* datafile );
 SDL_Surface *LoadImage( char* datafile, int mode );
 SDL_Surface* LoadBkgd(char* datafile);
-int          LoadBothBkgds(char* datafile, SDL_Surface** fs_bkgd, SDL_Surface** win_bkgd);
+int          LoadBothBkgds(char* datafile, 
+                           SDL_Surface** fs_bkgd, 
+                           SDL_Surface** win_bkgd);
 sprite      *LoadSprite( char* name, int MODE );
 sprite      *FlipSprite( sprite* in, int X, int Y );
 void         FreeSprite( sprite* gfx );




More information about the Tux4kids-commits mailing list