[Tux4kids-commits] r24 - in tuxmath/trunk: data/missions docs src
dbruce at alioth.debian.org
dbruce at alioth.debian.org
Thu Mar 8 21:05:36 CET 2007
Author: dbruce
Date: 2006-09-05 20:54:36 +0000 (Tue, 05 Sep 2006)
New Revision: 24
Modified:
tuxmath/trunk/data/missions/options
tuxmath/trunk/docs/changelog
tuxmath/trunk/src/fileops.c
tuxmath/trunk/src/mathcards.c
tuxmath/trunk/src/mathcards.h
tuxmath/trunk/src/setup.c
tuxmath/trunk/src/setup.h
Log:
operation-specific question formats
Modified: tuxmath/trunk/data/missions/options
===================================================================
--- tuxmath/trunk/data/missions/options 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/data/missions/options 2006-09-05 20:54:36 UTC (rev 24)
@@ -84,9 +84,13 @@
# #
# General Math Options #
# #
-# If 'play_through_list' selected, Tuxmath will ask each #
-# question in the defined list. The game ends when no #
-# questions remain. Default is 1 (i.e. 'true' or 'yes'). #
+# If 'play_through_list' is true, Tuxmath will ask each #
+# question in an internally-generated list. The list is #
+# generated based on the question ranges selected below. #
+# The game ends when no questions remain. #
+# If 'play_through_list' is false, the game continues #
+# until all cities are destroyed. #
+# Default is 1 (i.e. 'true' or 'yes'). #
# #
# 'question_copies' is the number of times each question #
# will be asked. It can be 1 to 10 - Default is 1. #
@@ -110,23 +114,35 @@
copies_repeated_wrongs = 1
############################################################
-# 'format_answer_last' (, _first, middle) control the #
+# The 'format_<op>_answer_<place> options control #
# generation of questions with the answer in different #
# places in the equation. i.e.: #
# #
-# format_answer_last: 2 + 2 = ? #
-# format_answer_first: ? + 2 = 4 #
-# format_answer_middle: 2 + ? = 4 #
+# format_add_answer_last: 2 + 2 = ? #
+# format_add_answer_first: ? + 2 = 4 #
+# format_add_answer_middle: 2 + ? = 4 #
# #
# By default, 'format_answer_first' is enabled and the #
# other two formats are disabled. Note that the options #
# are not mutually exclusive - the question list may #
# contain questions with different formats. #
+# #
+# The formats are set independently for each of the four #
+# math operations. #
############################################################
-format_answer_last = 1
-format_answer_first = 0
-format_answer_middle = 0
+format_add_answer_last = 1
+format_add_answer_first = 0
+format_add_answer_middle = 0
+format_sub_answer_last = 1
+format_sub_answer_first = 0
+format_sub_answer_middle = 0
+format_mult_answer_last = 1
+format_mult_answer_first = 0
+format_mult_answer_middle = 0
+format_div_answer_last = 1
+format_div_answer_first = 0
+format_div_answer_middle = 0
############################################################
# 'allow_negatives' allows or disallows use of negative #
Modified: tuxmath/trunk/docs/changelog
===================================================================
--- tuxmath/trunk/docs/changelog 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/docs/changelog 2006-09-05 20:54:36 UTC (rev 24)
@@ -1,5 +1,19 @@
changelog for "tuxmath"
+2006.Sep.03 (https://svn.tux4kids.net/tuxmath/ - revision 22)
+ Version 0.94
+
+ Setup:
+ * Math question formats (answer last, answer first, etc.)
+ are now set independently for each math operation, e.g.
+ "format_add_answer_last", etc.
+ Code:
+ * Mathcards now prints questions in same format as what
+ appears in game (e.g. "2 + 2 = ?"). So far this is
+ only used for debugging output, but soon tuxmath will
+ save lists of questions asked and questions missed to
+ files for post-game review.
+
2006.Sep.03 (https://svn.tux4kids.net/tuxmath/ - revision 21)
Version 0.93
Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/src/fileops.c 2006-09-05 20:54:36 UTC (rev 24)
@@ -548,6 +548,20 @@
MC_SetCopiesRepeatedWrongs(v);
}
+ else if(0 == strcasecmp(parameter, "question_copies"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetQuestionCopies(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "randomize"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetRandomize(v);
+ }
+
else if(0 == strcasecmp(parameter, "format_answer_last"))
{
int v = str_to_bool(value);
@@ -569,28 +583,91 @@
MC_SetFormatAnswerMiddle(v);
}
- else if(0 == strcasecmp(parameter, "format_answer_last"))
+ else if(0 == strcasecmp(parameter, "format_add_answer_last"))
{
int v = str_to_bool(value);
if (v != -1)
- MC_SetFormatAnswerLast(v);
+ MC_SetFormatAddAnswerLast(v);
}
- else if(0 == strcasecmp(parameter, "question_copies"))
+ else if(0 == strcasecmp(parameter, "format_add_answer_first"))
{
int v = str_to_bool(value);
if (v != -1)
- MC_SetQuestionCopies(v);
+ MC_SetFormatAddAnswerFirst(v);
}
- else if(0 == strcasecmp(parameter, "randomize"))
+ else if(0 == strcasecmp(parameter, "format_add_answer_middle"))
{
int v = str_to_bool(value);
if (v != -1)
- MC_SetRandomize(v);
+ MC_SetFormatAddAnswerMiddle(v);
}
+ else if(0 == strcasecmp(parameter, "format_sub_answer_last"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatSubAnswerLast(v);
+ }
+ else if(0 == strcasecmp(parameter, "format_sub_answer_first"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatSubAnswerFirst(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_sub_answer_middle"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatSubAnswerMiddle(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_mult_answer_last"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatMultAnswerLast(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_mult_answer_first"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatMultAnswerFirst(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_mult_answer_middle"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatMultAnswerMiddle(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_div_answer_last"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatDivAnswerLast(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_div_answer_first"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatDivAnswerFirst(v);
+ }
+
+ else if(0 == strcasecmp(parameter, "format_div_answer_middle"))
+ {
+ int v = str_to_bool(value);
+ if (v != -1)
+ MC_SetFormatDivAnswerMiddle(v);
+ }
+
+
/* Set the allowed math operations: */
Modified: tuxmath/trunk/src/mathcards.c
===================================================================
--- tuxmath/trunk/src/mathcards.c 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/src/mathcards.c 2006-09-05 20:54:36 UTC (rev 24)
@@ -54,15 +54,16 @@
static int sane_value(int i);
static int abs_value(int i);
+static void print_list(FILE* fp,MC_MathQuestion* list);
+static void print_node(FILE* fp, MC_MathQuestion* ptr);
+
/* these functions are dead code unless compiling with debug turned on: */
#ifdef MC_DEBUG
-static void print_node(MC_MathQuestion* ptr);
static void print_card(MC_FlashCard card);
static void print_counters(void);
static MC_MathQuestion* create_node_copy(MC_MathQuestion* other);
static int copy_node(MC_MathQuestion* original, MC_MathQuestion* copy);
static MC_FlashCard* create_card_from_node(MC_MathQuestion* node);
-static void print_list(MC_MathQuestion* list);
#endif
/* MC_Initialize() sets up the struct containing all of */
@@ -112,11 +113,22 @@
math_opts->allow_negatives = DEFAULT_ALLOW_NEGATIVES;
math_opts->max_answer = DEFAULT_MAX_ANSWER;
math_opts->max_questions = DEFAULT_MAX_QUESTIONS;
- math_opts->format_answer_last = DEFAULT_FORMAT_ANSWER_LAST;
- math_opts->format_answer_first = DEFAULT_FORMAT_ANSWER_FIRST;
- math_opts->format_answer_middle = DEFAULT_FORMAT_ANSWER_MIDDLE;
math_opts->question_copies = DEFAULT_QUESTION_COPIES;
math_opts->randomize = DEFAULT_RANDOMIZE;
+ /* set question formats: */
+ math_opts->format_add_answer_last = DEFAULT_FORMAT_ADD_ANSWER_LAST;
+ math_opts->format_add_answer_first = DEFAULT_FORMAT_ADD_ANSWER_FIRST;
+ math_opts->format_add_answer_middle = DEFAULT_FORMAT_ADD_ANSWER_MIDDLE;
+ math_opts->format_sub_answer_last = DEFAULT_FORMAT_SUB_ANSWER_LAST;
+ math_opts->format_sub_answer_first = DEFAULT_FORMAT_SUB_ANSWER_FIRST;
+ math_opts->format_sub_answer_middle = DEFAULT_FORMAT_SUB_ANSWER_MIDDLE;
+ math_opts->format_mult_answer_last = DEFAULT_FORMAT_MULT_ANSWER_LAST;
+ math_opts->format_mult_answer_first = DEFAULT_FORMAT_MULT_ANSWER_FIRST;
+ math_opts->format_mult_answer_middle = DEFAULT_FORMAT_MULT_ANSWER_MIDDLE;
+ math_opts->format_div_answer_last = DEFAULT_FORMAT_DIV_ANSWER_LAST;
+ math_opts->format_div_answer_first = DEFAULT_FORMAT_DIV_ANSWER_FIRST;
+ math_opts->format_div_answer_middle = DEFAULT_FORMAT_DIV_ANSWER_MIDDLE;
+
/* set addition options */
math_opts->addition_allowed = DEFAULT_ADDITION_ALLOWED;
math_opts->min_augend = DEFAULT_MIN_AUGEND;
@@ -278,7 +290,7 @@
#ifdef MC_DEBUG
print_counters();
- print_list(question_list);
+ print_list(stdout, question_list);
printf("\nLeaving MC_StartGameUsingWrongs()\n");
#endif
@@ -646,6 +658,8 @@
math_opts->copies_repeated_wrongs = copies;
}
+
+
/*NOTE - list can contain more than one format */
void MC_SetFormatAnswerLast(int opt) /* Enable questions like: a + b = ? */
{
@@ -654,7 +668,11 @@
fprintf(stderr, "\nMC_SetFormatAnswerLast(): math_opts not valid!\n");
return;
}
- math_opts->format_answer_last = int_to_bool(opt);
+
+ MC_SetFormatAddAnswerLast(opt);
+ MC_SetFormatSubAnswerLast(opt);
+ MC_SetFormatMultAnswerLast(opt);
+ MC_SetFormatDivAnswerLast(opt);
}
@@ -665,7 +683,11 @@
fprintf(stderr, "\nMC_SetFormatAnswerFirst(): math_opts not valid!\n");
return;
}
- math_opts->format_answer_first = int_to_bool(opt);
+
+ MC_SetFormatAddAnswerFirst(opt);
+ MC_SetFormatSubAnswerFirst(opt);
+ MC_SetFormatMultAnswerFirst(opt);
+ MC_SetFormatDivAnswerFirst(opt);
}
@@ -676,10 +698,154 @@
fprintf(stderr, "\nMC_SetFormatAnswerMiddle(): math_opts not valid!\n");
return;
}
- math_opts->format_answer_middle = int_to_bool(opt);
+
+ MC_SetFormatAddAnswerMiddle(opt);
+ MC_SetFormatSubAnswerMiddle(opt);
+ MC_SetFormatMultAnswerMiddle(opt);
+ MC_SetFormatDivAnswerMiddle(opt);
}
+
+/* Addition-specific question formats: */
+void MC_SetFormatAddAnswerLast(int opt) /* Enable questions like: a + b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatAddAnswerLast(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_add_answer_last = int_to_bool(opt);
+}
+
+
+void MC_SetFormatAddAnswerFirst(int opt) /* Enable questions like: ? + b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatAddAnswerFirst(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_add_answer_first = int_to_bool(opt);
+}
+
+
+void MC_SetFormatAddAnswerMiddle(int opt) /* Enable questions like: a + ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatAddAnswerMiddle(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_add_answer_middle = int_to_bool(opt);
+}
+
+
+
+/* Subtraction-specific question formats: */
+void MC_SetFormatSubAnswerLast(int opt) /* Enable questions like: a - b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatSubAnswerLast(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_sub_answer_last = int_to_bool(opt);
+}
+
+
+void MC_SetFormatSubAnswerFirst(int opt) /* Enable questions like: ? - b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatSubAnswerFirst(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_sub_answer_first = int_to_bool(opt);
+}
+
+
+void MC_SetFormatSubAnswerMiddle(int opt) /* Enable questions like: a - ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatSubAnswerMiddle(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_sub_answer_middle = int_to_bool(opt);
+}
+
+
+
+/* Multiplication-specific question formats: */
+void MC_SetFormatMultAnswerLast(int opt) /* Enable questions like: a * b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatMultAnswerLast(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_mult_answer_last = int_to_bool(opt);
+}
+
+
+void MC_SetFormatMultAnswerFirst(int opt) /* Enable questions like: ? * b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatMultAnswerFirst(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_mult_answer_first = int_to_bool(opt);
+}
+
+
+void MC_SetFormatMultAnswerMiddle(int opt) /* Enable questions like: a * ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatMultAnswerMiddle(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_mult_answer_middle = int_to_bool(opt);
+}
+
+
+/* Division-specific question formats: */
+void MC_SetFormatDivAnswerLast(int opt) /* Enable questions like: a / b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatDivAnswerLast(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_div_answer_last = int_to_bool(opt);
+}
+
+
+void MC_SetFormatDivAnswerFirst(int opt) /* Enable questions like: ? / b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatDivAnswerFirst(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_div_answer_first = int_to_bool(opt);
+}
+
+
+void MC_SetFormatDivAnswerMiddle(int opt) /* Enable questions like: a / ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_SetFormatDivAnswerMiddle(): math_opts not valid!\n");
+ return;
+ }
+ math_opts->format_div_answer_middle = int_to_bool(opt);
+}
+
+
+
void MC_SetQuestionCopies(int copies) /* how many times each question is put in list */
{
if (!math_opts)
@@ -1056,39 +1222,140 @@
}
-int MC_FormatAnswerLast(void) /* a + b = ? */
+
+
+int MC_FormatAddAnswerLast(void) /* a + b = ? */
{
if (!math_opts)
{
- fprintf(stderr, "\nMC_FormatAnswerLast(): math_opts not valid!\n");
+ fprintf(stderr, "\nMC_FormatAddAnswerLast(): math_opts not valid!\n");
return MC_MATH_OPTS_INVALID;
}
- return math_opts->format_answer_last;
+ return math_opts->format_add_answer_last;
}
-int MC_FormatAnswerFirst(void) /* ? + b = c NOTE - list can contain more than one format */
+int MC_FormatAddAnswerFirst(void) /* ? + b = c */
{
if (!math_opts)
{
- fprintf(stderr, "\nMC_FormatAnswerFirst(): math_opts not valid!\n");
+ fprintf(stderr, "\nMC_FormatAddAnswerFirst(): math_opts not valid!\n");
return MC_MATH_OPTS_INVALID;
}
- return math_opts->format_answer_first;
+ return math_opts->format_add_answer_first;
}
-int MC_FormatAnswerMiddle(void) /* a + ? = c */
+int MC_FormatAddAnswerMiddle(void) /* a + ? = c */
{
if (!math_opts)
{
+ fprintf(stderr, "\nMC_FormatAddAnswerMiddle(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_add_answer_middle;
+}
+
+
+int MC_FormatSubAnswerLast(void) /* a - b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatSubAnswerLast(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_sub_answer_last;
+}
+
+
+int MC_FormatSubAnswerFirst(void) /* ? - b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatSubAnswerFirst(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_sub_answer_first;
+}
+
+
+int MC_FormatSubAnswerMiddle(void) /* a - ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatSubAnswerMiddle(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_sub_answer_middle;
+}
+
+int MC_FormatMultAnswerLast(void) /* a * b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatMultAnswerLast(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_mult_answer_last;
+}
+
+
+int MC_FormatMultAnswerFirst(void) /* ? * b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatMultAnswerFirst(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_mult_answer_first;
+}
+
+
+int MC_FormatMultAnswerMiddle(void) /* a * ? = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatMultAnswerMiddle(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_mult_answer_middle;
+}
+
+
+int MC_FormatDivAnswerLast(void) /* a / b = ? */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatDivAnswerLast(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_div_answer_last;
+}
+
+
+int MC_FormatDivAnswerFirst(void) /* ? / b = c */
+{
+ if (!math_opts)
+ {
+ fprintf(stderr, "\nMC_FormatDivAnswerFirst(): math_opts not valid!\n");
+ return MC_MATH_OPTS_INVALID;
+ }
+ return math_opts->format_div_answer_first;
+}
+
+
+int MC_FormatDivAnswerMiddle(void) /* a / ? = c */
+{
+ if (!math_opts)
+ {
fprintf(stderr, "\nMC_FormatAnswerMiddle(): math_opts not valid!\n");
return MC_MATH_OPTS_INVALID;
}
- return math_opts->format_answer_middle;
+ return math_opts->format_add_answer_middle;
}
+
int MC_QuestionCopies(void) /* how many times each question is put in list */
{
if (!math_opts)
@@ -1427,7 +1694,7 @@
/* put in questions in each selected format: */
/* questions like num1 + num2 = ? */
- if (math_opts->format_answer_last)
+ if (math_opts->format_add_answer_last)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1440,7 +1707,7 @@
}
/* questions like num1 + ? = num3 */
- if (math_opts->format_answer_middle)
+ if (math_opts->format_add_answer_middle)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1453,7 +1720,7 @@
}
/* questions like ? + num2 = num3 */
- if (math_opts->format_answer_first)
+ if (math_opts->format_add_answer_first)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1486,7 +1753,7 @@
/* put in questions in each selected format: */
/* questions like num1 - num2 = ? */
- if (math_opts->format_answer_last)
+ if (math_opts->format_sub_answer_last)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1499,7 +1766,7 @@
}
/* questions like num1 - ? = num3 */
- if (math_opts->format_answer_middle)
+ if (math_opts->format_sub_answer_middle)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1512,7 +1779,7 @@
}
/* questions like ? - num2 = num3 */
- if (math_opts->format_answer_first)
+ if (math_opts->format_sub_answer_first)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1545,7 +1812,7 @@
/* put in questions in each selected format: */
/* questions like num1 x num2 = ? */
- if (math_opts->format_answer_last)
+ if (math_opts->format_mult_answer_last)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1559,7 +1826,7 @@
/* questions like num1 x ? = num3 */
/* (no questions like 0 x ? = 0) because answer indeterminate */
- if ((math_opts->format_answer_middle)
+ if ((math_opts->format_mult_answer_middle)
&& (i != 0))
{
/* make sure max_questions not exceeded */
@@ -1574,7 +1841,7 @@
/* questions like ? x num2 = num3 */
/* (no questions like ? X 0 = 0) because answer indeterminate */
- if ((math_opts->format_answer_first)
+ if ((math_opts->format_mult_answer_first)
&& (j != 0))
{
/* make sure max_questions not exceeded */
@@ -1610,7 +1877,7 @@
/* put in questions in each selected format: */
/* questions like num1 / num2 = ? */
- if (math_opts->format_answer_last)
+ if (math_opts->format_div_answer_last)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1623,7 +1890,7 @@
}
/* questions like num1 / ? = num3 */
- if (math_opts->format_answer_middle)
+ if (math_opts->format_div_answer_middle)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1636,7 +1903,7 @@
}
/* questions like ? / num2 = num3 */
- if (math_opts->format_answer_first)
+ if (math_opts->format_div_answer_first)
{
/* make sure max_questions not exceeded */
if (length < math_opts->max_questions)
@@ -1933,23 +2200,35 @@
if (verbose)
{
fprintf (fp, "\n############################################################\n"
- "# 'format_answer_last' (, _first, middle) control the #\n"
+ "# The 'format_<op>_answer_<place> options control #\n"
"# generation of questions with the answer in different #\n"
"# places in the equation. i.e.: #\n"
"# #\n"
- "# format_answer_last: 2 + 2 = ? #\n"
- "# format_answer_first: ? + 2 = 4 #\n"
- "# format_answer_middle: 2 + ? = 4 #\n"
+ "# format_add_answer_last: 2 + 2 = ? #\n"
+ "# format_add_answer_first: ? + 2 = 4 #\n"
+ "# format_add_answer_middle: 2 + ? = 4 #\n"
"# #\n"
"# By default, 'format_answer_first' is enabled and the #\n"
"# other two formats are disabled. Note that the options #\n"
"# are not mutually exclusive - the question list may #\n"
"# contain questions with different formats. #\n"
+ "# #\n"
+ "# The formats are set independently for each of the four #\n"
+ "# math operations. #\n"
"############################################################\n\n");
}
- fprintf (fp, "format_answer_last = %d\n", math_opts->format_answer_last);
- fprintf (fp, "format_answer_first = %d\n", math_opts->format_answer_first);
- fprintf (fp, "format_answer_middle = %d\n", math_opts->format_answer_middle);
+ fprintf (fp, "format_add_answer_last = %d\n", math_opts->format_add_answer_last);
+ fprintf (fp, "format_add_answer_first = %d\n", math_opts->format_add_answer_first);
+ fprintf (fp, "format_add_answer_middle = %d\n", math_opts->format_add_answer_middle);
+ fprintf (fp, "format_sub_answer_last = %d\n", math_opts->format_sub_answer_last);
+ fprintf (fp, "format_sub_answer_first = %d\n", math_opts->format_sub_answer_first);
+ fprintf (fp, "format_sub_answer_middle = %d\n", math_opts->format_sub_answer_middle);
+ fprintf (fp, "format_mult_answer_last = %d\n", math_opts->format_mult_answer_last);
+ fprintf (fp, "format_mult_answer_first = %d\n", math_opts->format_mult_answer_first);
+ fprintf (fp, "format_mult_answer_middle = %d\n", math_opts->format_mult_answer_middle);
+ fprintf (fp, "format_div_answer_last = %d\n", math_opts->format_div_answer_last);
+ fprintf (fp, "format_div_answer_first = %d\n", math_opts->format_div_answer_first);
+ fprintf (fp, "format_div_answer_middle = %d\n", math_opts->format_div_answer_middle);
if (verbose)
{
@@ -2052,37 +2331,107 @@
}
-#ifdef MC_DEBUG
-void print_list(MC_MathQuestion* list)
+void print_list(FILE* fp, MC_MathQuestion* list)
{
if (!list)
{
- printf("\nprint_list(): list empty or pointer invalid\n");
+ fprintf(fp, "\nprint_list(): list empty or pointer invalid\n");
return;
}
MC_MathQuestion* ptr = list;
- printf("\nprint_list() printing list:");
- printf("\nlist_length():\t%d", list_length(list));
+ fprintf(fp, "\nprint_list() printing list:");
+ fprintf(fp, "\nlist_length():\t%d", list_length(list));
while (ptr)
{
- print_node(ptr);
+ print_node(fp, ptr);
ptr = ptr->next;
}
}
-#endif
-void print_node(MC_MathQuestion* ptr)
+/* convert node info into an (easily) human-readable string */
+/* and print it, taking question format into account. */
+void print_node(FILE* fp, MC_MathQuestion* ptr)
{
- if (ptr)
- printf("\n%d, %d \tOper %d \tAnswer %d",
- ptr->card.num1,
- ptr->card.num2,
- ptr->card.operation,
- ptr->card.num3);
-}
+ char str[MC_FORMULA_LEN];
+ char op;
+
+ if (!ptr)
+ {
+ return;
+ }
+ /* find out correct operation character */
+ switch (ptr->card.operation)
+ {
+ case MC_OPER_ADD:
+ {
+ op = '+';
+ break;
+ }
+ case MC_OPER_SUB:
+ {
+ op = '-';
+ break;
+ }
+ case MC_OPER_MULT:
+ {
+ op = '*';
+ break;
+ }
+ case MC_OPER_DIV:
+ {
+ op = '/';
+ break;
+ }
+ default:
+ {
+ fprintf(stderr, "\nIn print_node(): invalid math operation\n");
+ return;
+ }
+ }
+ switch (ptr->card.format)
+ {
+ case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
+ {
+ snprintf(str, MC_FORMULA_LEN,"%d %c %d = ?",
+ ptr->card.num1,
+ op,
+ ptr->card.num2);
+ break;
+ }
+
+ case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
+ {
+ snprintf(str, MC_FORMULA_LEN,"%d %c ? = %d",
+ ptr->card.num1,
+ op,
+ ptr->card.num3);
+ break;
+ }
+
+ case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
+ {
+ snprintf(str, MC_FORMULA_LEN,"? %c %d = %d",
+ op,
+ ptr->card.num2,
+ ptr->card.num3);
+ break;
+ }
+
+ default: /* should not get to here if MathCards behaves correctly */
+ {
+ fprintf(stderr, "\nprint_node() - invalid question format\n");
+ return;
+ }
+ }
+
+ /* Now simply print string: */
+ fprintf(fp, "\n%s", str);
+}
+
+
#ifdef MC_DEBUG
void print_card(MC_FlashCard card)
{
@@ -2141,9 +2490,9 @@
printf("\nEntering randomize_list()");
printf("\nBefore randomization:");
printf("\nPrinting old_list:");
- print_list(old_list);
+ print_list(stdout, old_list);
printf("\nPrinting new_list:");
- print_list(new_list);
+ print_list(stdout, new_list);
#endif
@@ -2165,9 +2514,9 @@
printf("\nUnexpected exit!");
printf("\nAfter randomization:");
printf("\nPrinting old_list:");
- print_list(old_list);
+ print_list(stdout, old_list);
printf("\nPrinting new_list:");
- print_list(new_list);
+ print_list(stdout, new_list);
printf("\nLeaving randomize_list()");
#endif
@@ -2178,9 +2527,9 @@
#ifdef MC_DEBUG
printf("\nAfter randomization:");
printf("\nPrinting old_list:");
- print_list(old_list);
+ print_list(stdout, old_list);
printf("\nPrinting new_list:");
- print_list(new_list);
+ print_list(stdout, new_list);
printf("\nLeaving randomize_list()");
#endif
Modified: tuxmath/trunk/src/mathcards.h
===================================================================
--- tuxmath/trunk/src/mathcards.h 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/src/mathcards.h 2006-09-05 20:54:36 UTC (rev 24)
@@ -16,6 +16,7 @@
#define MATHCARDS_H
//#define MC_DEBUG
+#define MC_FORMULA_LEN 14
#include <stdio.h>
#include <stdlib.h>
@@ -47,11 +48,24 @@
int allow_negatives;
int max_answer;
int max_questions;
- int format_answer_last; /* a + b = ? */
- int format_answer_first; /* ? + b = c NOTE - list can contain more than one format */
- int format_answer_middle; /* a + ? = c */
int question_copies; /* how many times each question is put in list */
int randomize; /* whether to shuffle cards */
+
+ /* math question formats: NOTE - list can contain more than one format*/
+ /* operation-specific question formats: */
+ int format_add_answer_last; /* a + b = ? */
+ int format_add_answer_first; /* ? + b = c */
+ int format_add_answer_middle; /* a + ? = c */
+ int format_sub_answer_last; /* a - b = ? */
+ int format_sub_answer_first; /* ? - b = c */
+ int format_sub_answer_middle; /* a - ? = c */
+ int format_mult_answer_last; /* a * b = ? */
+ int format_mult_answer_first; /* ? * b = c */
+ int format_mult_answer_middle; /* a * ? = c */
+ int format_div_answer_last; /* a / b = ? */
+ int format_div_answer_first; /* ? / b = c */
+ int format_div_answer_middle; /* a / ? = c */
+
/* addition options */
int addition_allowed;
int min_augend; /* the "augend" is the first addend i.e. "a" in "a + b = c" */
@@ -90,36 +104,52 @@
#define DEFAULT_ALLOW_NEGATIVES 0
#define DEFAULT_MAX_ANSWER 144
#define DEFAULT_MAX_QUESTIONS 5000
+#define DEFAULT_QUESTION_COPIES 1 /* how many times each question is put in list */
+#define DEFAULT_RANDOMIZE 1 /* whether to shuffle cards */
+
#define DEFAULT_FORMAT_ANSWER_LAST 1 /* question format is: a + b = ? */
#define DEFAULT_FORMAT_ANSWER_FIRST 0 /* question format is: ? + b = c */
#define DEFAULT_FORMAT_ANSWER_MIDDLE 0 /* question format is: a + ? = c */
-#define DEFAULT_QUESTION_COPIES 1 /* how many times each question is put in list */
-#define DEFAULT_RANDOMIZE 1 /* whether to shuffle cards */
+#define DEFAULT_FORMAT_ADD_ANSWER_LAST 1 /* addition-specific default formats: */
+#define DEFAULT_FORMAT_ADD_ANSWER_FIRST 0
+#define DEFAULT_FORMAT_ADD_ANSWER_MIDDLE 0
+#define DEFAULT_FORMAT_SUB_ANSWER_LAST 1 /* subtraction-specific default formats: */
+#define DEFAULT_FORMAT_SUB_ANSWER_FIRST 0
+#define DEFAULT_FORMAT_SUB_ANSWER_MIDDLE 0
+#define DEFAULT_FORMAT_MULT_ANSWER_LAST 1 /* multiplication-specific default formats: */
+#define DEFAULT_FORMAT_MULT_ANSWER_FIRST 0
+#define DEFAULT_FORMAT_MULT_ANSWER_MIDDLE 0
+#define DEFAULT_FORMAT_DIV_ANSWER_LAST 1 /* division-specific default formats: */
+#define DEFAULT_FORMAT_DIV_ANSWER_FIRST 0
+#define DEFAULT_FORMAT_DIV_ANSWER_MIDDLE 0
#define DEFAULT_ADDITION_ALLOWED 1
+#define DEFAULT_SUBTRACTION_ALLOWED 1
+#define DEFAULT_MULTIPLICATION_ALLOWED 1
+#define DEFAULT_DIVISION_ALLOWED 1
+
#define DEFAULT_MIN_AUGEND 0 /* augend + addend = sum */
#define DEFAULT_MAX_AUGEND 12
#define DEFAULT_MIN_ADDEND 0
#define DEFAULT_MAX_ADDEND 12
-#define DEFAULT_SUBTRACTION_ALLOWED 1 /* minuend - subtrahend = difference */
-#define DEFAULT_MIN_MINUEND 0
+#define DEFAULT_MIN_MINUEND 0 /* minuend - subtrahend = difference */
#define DEFAULT_MAX_MINUEND 12
#define DEFAULT_MIN_SUBTRAHEND 0
#define DEFAULT_MAX_SUBTRAHEND 12
-#define DEFAULT_MULTIPLICATION_ALLOWED 1
#define DEFAULT_MIN_MULTIPLIER 0 /* multiplier * multiplicand = product */
#define DEFAULT_MAX_MULTIPLIER 12
#define DEFAULT_MIN_MULTIPLICAND 0
#define DEFAULT_MAX_MULTIPLICAND 12
-#define DEFAULT_DIVISION_ALLOWED 1 /* dividend/divisor = quotient */
-#define DEFAULT_MIN_DIVISOR 0 /* note - generate_list() will prevent */
-#define DEFAULT_MAX_DIVISOR 12 /* questions with division by zero. */
-#define DEFAULT_MIN_QUOTIENT 0
+#define DEFAULT_MIN_DIVISOR 0 /* dividend/divisor = quotient */
+#define DEFAULT_MAX_DIVISOR 12 /* note - generate_list() will prevent */
+#define DEFAULT_MIN_QUOTIENT 0 /* questions with division by zero. */
#define DEFAULT_MAX_QUOTIENT 12
+
+
/* struct for individual "flashcard" */
typedef struct MC_FlashCard {
int num1;
@@ -224,13 +254,30 @@
void MC_SetQuestionCopies(int copies); /* how many times each question is put in list */
void MC_SetCopiesRepeatedWrongs(int copies);
void MC_SetMaxAnswer(int max);
-void MC_SetMaxQuestions(int max);
+void MC_SetMaxQuestions(int max);
void MC_SetAllowNegatives(int opt);
-void MC_SetFormatAnswerLast(int opt); /* a + b = ? */
-void MC_SetFormatAnswerFirst(int opt); /* ? + b = c NOTE - list can contain more than one format */
-void MC_SetFormatAnswerMiddle(int opt); /* a + ? = c */
void MC_SetRandomize(int opt);
+/* Set question formats for all operations: */
+/* NOTE - list can contain more than one format */
+/* Use these to set format the same for all four operations: */
+void MC_SetFormatAnswerLast(int opt); /* a + b = ?, a - b = ?, a * b = ?, a / b = ? */
+void MC_SetFormatAnswerFirst(int opt); /* ? + b = c, etc */
+void MC_SetFormatAnswerMiddle(int opt); /* a + ? = c, etc */
+/* Uset these to set operation-specific question formats: */
+void MC_SetFormatAddAnswerLast(int opt); /* a + b = ? */
+void MC_SetFormatAddAnswerFirst(int opt); /* ? + b = c */
+void MC_SetFormatAddAnswerMiddle(int opt); /* a + ? = c */
+void MC_SetFormatSubAnswerLast(int opt); /* a - b = ? */
+void MC_SetFormatSubAnswerFirst(int opt); /* ? - b = c */
+void MC_SetFormatSubAnswerMiddle(int opt); /* a - ? = c */
+void MC_SetFormatMultAnswerLast(int opt); /* a * b = ? */
+void MC_SetFormatMultAnswerFirst(int opt); /* ? * b = c */
+void MC_SetFormatMultAnswerMiddle(int opt); /* a * ? = c */
+void MC_SetFormatDivAnswerLast(int opt); /* a / b = ? */
+void MC_SetFormatDivAnswerFirst(int opt); /* ? / b = c */
+void MC_SetFormatDivAnswerMiddle(int opt); /* a / ? = c */
+
/* Set the allowed math operations: */
void MC_SetAddAllowed(int opt);
void MC_SetSubAllowed(int opt);
@@ -278,12 +325,24 @@
int MC_CopiesRepeatedWrongs(void);
int MC_MaxAnswer(void);
int MC_AllowNegatives(void);
-int MC_FormatAnswerLast(void); /* a + b = ? */
-int MC_FormatAnswerFirst(void); /* ? + b = c NOTE - list can contain more than one format */
-int MC_FormatAnswerMiddle(void); /* a + ? = c */
int MC_QuestionCopies(void); /* how many times each question is put in list */
int MC_Randomize(void);
+
+int MC_FormatAddAnswerLast(void); /* a + b = ? */
+int MC_FormatAddAnswerFirst(void); /* ? + b = c */
+int MC_FormatAddAnswerMiddle(void); /* a + ? = c */
+int MC_FormatSubAnswerLast(void); /* a - b = ? */
+int MC_FormatSubAnswerFirst(void); /* ? - b = c */
+int MC_FormatSubAnswerMiddle(void); /* a - ? = c */
+int MC_FormatMultAnswerLast(void); /* a * b = ? */
+int MC_FormatMultAnswerFirst(void); /* ? * b = c */
+int MC_FormatMultAnswerMiddle(void); /* a * ? = c */
+int MC_FormatDivAnswerLast(void); /* a / b = ? */
+int MC_FormatDivAnswerFirst(void); /* ? / b = c */
+int MC_FormatDivAnswerMiddle(void); /* a / ? = c */
+
+
/* Query the allowed math operations: */
int MC_AddAllowed(void);
int MC_SubAllowed(void);
Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/src/setup.c 2006-09-05 20:54:36 UTC (rev 24)
@@ -38,6 +38,7 @@
#include <SDL_image.h>
+
#include "tuxmath.h"
#include "mathcards.h"
#include "setup.h"
Modified: tuxmath/trunk/src/setup.h
===================================================================
--- tuxmath/trunk/src/setup.h 2006-09-03 16:37:34 UTC (rev 23)
+++ tuxmath/trunk/src/setup.h 2006-09-05 20:54:36 UTC (rev 24)
@@ -7,7 +7,7 @@
All code involving file I/O has been moved to fileops.h/fileops.c
and is called from the main setup function.
- Some globals are declared in setup.c - all globals throught tuxmath
+ Some globals are declared in setup.c - all globals throughout tuxmath
are now extern'd in the same place in tuxmath.h
by Bill Kendrick
More information about the Tux4kids-commits
mailing list