[Tux4kids-commits] r551 - tuxmath/branches/mathcards_newarch/src
cheezmeister-guest at alioth.debian.org
cheezmeister-guest at alioth.debian.org
Tue Jun 24 01:21:32 UTC 2008
Author: cheezmeister-guest
Date: 2008-06-24 01:21:32 +0000 (Tue, 24 Jun 2008)
New Revision: 551
Modified:
tuxmath/branches/mathcards_newarch/src/fileops.c
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/setup.c
tuxmath/branches/mathcards_newarch/src/titlescreen.h
tuxmath/branches/mathcards_newarch/src/tuxmath.h
Log:
Branch: game now compiles without complaint when using new-style options. There's no gameplay though, because generate_list() isn't implemented\!
Modified: tuxmath/branches/mathcards_newarch/src/fileops.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/fileops.c 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/fileops.c 2008-06-24 01:21:32 UTC (rev 551)
@@ -1380,7 +1380,7 @@
Opts_SetMaxComets(atoi(value));
}
-
+ #ifndef MC_USE_NEWARC
/* Begin setting of math question options (see mathcards.h): */
/* General math options */
@@ -1690,10 +1690,9 @@
}
else
+ #endif
{
- #ifdef TUXMATH_DEBUG
- printf("parameter not recognized: %s\n", parameter);
- #endif
+ MC_SetOp(parameter, atoi(value) ); //automatically handles bad parameters
}
free(parameter);
}
@@ -1747,475 +1746,271 @@
/* human-readable file. */
int write_config_file(FILE *fp, int verbose)
{
- #ifdef TUXMATH_DEBUG
- printf("\nEntering write_config_file()\n");
- #endif
+ int i, vcommentsprimed = 0;
+ static char* vcomments[NOPTS]; //comments when writing out verbose
+ if (!vcommentsprimed) //we only want to initialize these once
+ {
+ vcommentsprimed = 1;
+ for (i = 0; i < NOPTS; ++i)
+ vcomments[i] = NULL;
+ vcomments[PLAY_THROUGH_LIST] =
+ "############################################################\n"
+ "# #\n"
+ "# Tuxmath Configuration File #\n"
+ "# #\n"
+ "# The behavior of Tuxmath can be controlled to a great #\n"
+ "# extent by editing this file with any and saving it in #\n"
+ "# the default options location ($HOME/.tuxmath/options). #\n"
+ "# The file consists of 'NAME = VALUE' pairs, one pair per #\n"
+ "# line. Each option is one of the following types: #\n"
+ "# #\n"
+ "# boolean: 1 (synonyms 'true', 'T', 'yes', 'Y', 'on') #\n"
+ "# or #\n"
+ "# 0 (synonyms 'false, 'F', 'no', 'N', 'off') #\n"
+ "# integer (i.e. non-fractional numbers) #\n"
+ "# float (i.e decimal fractions) #\n"
+ "# #\n"
+ "# Lines beginning with '#' or ';' are ignored as comments. #\n"
+ "# The synonyms for boolean '0' and '1' are accepted as #\n"
+ "# input, but always written as '0' or '1' when Tuxmath #\n"
+ "# writes a config file to disk. #\n"
+ "# The file is organized with the more important options #\n"
+ "# first. #\n"
+ "############################################################\n"
+ "\n"
+ "############################################################\n"
+ "# #\n"
+ "# Game Mode #\n"
+ "# #\n"
+ "# Parameter: play_through_list (Boolean) #\n"
+ "# Default: 1 #\n"
+ "# #\n"
+ "# Tuxmath generates a list of math questions based on #\n"
+ "# parameters set below. By default, (play_through_list = #\n"
+ "# 1) the questions are asked in a random order. #\n"
+ "# Correctly answered questions are removed from the list. #\n"
+ "# If the player fails to correctly answer a question #\n"
+ "# before it hits a city, the question will be reinserted #\n"
+ "# into the list in a random location. #\n"
+ "# The player wins if all questions are answered correctly #\n"
+ "# before the cities are destroyed. #\n"
+ "# #\n"
+ "# Alternatively, Tuxmath can be played in 'Arcade Mode' #\n"
+ "# by setting play_through_list = 0 (i.e. 'false'). If this #\n"
+ "# is done, all questions will be randomly reinserted into #\n"
+ "# the list whether or not they are answered correctly, and #\n"
+ "# the game continues as long as there is a surviving city. #\n"
+ "############################################################\n"
+ "\n";
+
+ vcomments[ADDITION_ALLOWED] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Selecting Math Operations #\n"
+ "# #\n"
+ "# Parameter: addition_allowed (boolean) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: subtraction_allowed (boolean) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: multiplication_allowed (boolean) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: division_allowed (boolean) #\n"
+ "# Default: 1 #\n"
+ "# #\n"
+ "# These options enable questions for each of the four math #\n"
+ "# operations. All are 1 (yes) by default. #\n"
+ "############################################################\n\n";
+ vcomments[TYPING_PRACTICE_ALLOWED] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Typing Practice #\n"
+ "# #\n"
+ "# Parameter: typing_practice_allowed (boolean) #\n"
+ "# Default: 0 #\n"
+ "# #\n"
+ "# This option simply displays numbers for the youngest #\n"
+ "# players to type in to learn the keyboard. #\n"
+ "############################################################\n\n";
+ vcomments[ALLOW_NEGATIVES] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Negative Number Support #\n"
+ "# #\n"
+ "# Parameter: allow_negatives (boolean) #\n"
+ "# Default: 0 #\n"
+ "# #\n"
+ "# 'allow_negatives' allows or disallows use of negative #\n"
+ "# numbers as both operands and answers. Default is 0 #\n"
+ "# (no), which disallows questions like: #\n"
+ "# 2 - 4 = ? #\n"
+ "# Note: this option must be enabled in order to set the #\n"
+ "# operand ranges to include negatives. If it is changed #\n"
+ "# from 1 (yes) to 0 (no), any negative operand limits will #\n"
+ "# be reset to 0. #\n"
+ "############################################################\n\n";
+ vcomments[MIN_AUGEND] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Minimum and Maximum Values for Operand Ranges #\n"
+ "# #\n"
+ "# Parameters: (multiple - all integer type) #\n"
+ "# #\n"
+ "# Operand limits can be set to any integer up to the #\n"
+ "# value of 'max_answer'. Tuxmath will generate questions #\n"
+ "# for every value in the specified range. The maximum must #\n"
+ "# be greater than or equal to the corresponding minimum #\n"
+ "# for any questions to be generated for that operation. #\n"
+ "# Defaults are 0 for minima and 12 for maxima. #\n"
+ "# #\n"
+ "# Note: 'allow_negatives' must be set to 1 for negative #\n"
+ "# values to be accepted (see 'Advanced Options'). #\n"
+ "############################################################\n"
+ "\n# Addition operands:\n"
+ "# augend + addend = sum\n\n";
+ vcomments[MIN_MINUEND] =
+ "\n# Subtraction operands:\n"
+ "# minuend - subtrahend = difference\n\n";
+ vcomments[MIN_MULTIPLIER] =
+ "\n# Multiplication operands:\n"
+ "# multiplier * multiplicand = product\n\n";
+ vcomments[MIN_DIVISOR] =
+ "\n# Division operands:\n"
+ "# dividend / divisor = quotiend\n\n";
+ vcomments[MIN_TYPING_NUM] =
+ "\n# Typing practice:\n";
+ vcomments[QUESTION_COPIES] =
+ "\n\n\n############################################################\n"
+ "# #\n"
+ "# Advanced Options #\n"
+ "# #\n"
+ "# The remaining settings further customize Tuxmath's #\n"
+ "# behavior. Most users will probably not change them. #\n"
+ "############################################################\n\n";
+
+ "\n############################################################\n"
+ "# #\n"
+ "# Advanced Math Question List Options #\n"
+ "# #\n"
+ "# Parameter: question_copies (integer) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: repeat_wrongs (boolean) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: copies_repeated_wrongs (integer) #\n"
+ "# Default: 1 #\n"
+ "# Parameter: fraction_to_keep (float) #\n"
+ "# Default: 1 #\n"
+ "# #\n"
+ "# These settings offer further control over the question #\n"
+ "# list and are generally only useful if 'play_through_list'#\n"
+ "# is enabled (as it is by default). #\n"
+ "# #\n"
+ "# 'question_copies' is the number of times each question #\n"
+ "# is put into the initial list. It can be 1 to 10. #\n"
+ "# #\n"
+ "# 'repeat_wrongs' determines whether questions the player #\n"
+ "# failed to answer correctly will be asked again. #\n"
+ "# #\n"
+ "# 'copies_repeated_wrongs' gives the number of times a #\n"
+ "# missed question will reappear. This can be set anywhere #\n"
+ "# from 1 to 10. #\n"
+ "# #\n"
+ "# 'fraction_to_keep' allows a list to be generated that #\n"
+ "# consists of a randomly-selected subset of the questions #\n"
+ "# fitting the criteria. The parameter is a float that #\n"
+ "# must be greater than 0 and less than or equal to 1. For #\n"
+ "# example, a value of 0.1 means 10%% of the questions #\n"
+ "# meeting the criteria will go into the list. #\n"
+ "# #\n"
+ "# The defaults for these values result in a 'mission' #\n"
+ "# for Tux that is accomplished by answering all #\n"
+ "# questions correctly with at least one surviving city. #\n"
+ "############################################################\n\n";
+ vcomments[FORMAT_ADD_ANSWER_LAST] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Math Question Formats #\n"
+ "# #\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_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. All parameters are type 'boolean'. #\n"
+ "############################################################\n\n";
+ vcomments[MAX_ANSWER] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Parameter: max_answer (integer) #\n"
+ "# Default: 999 #\n"
+ "# #\n"
+ "# 'max_answer' is the largest absolute value allowed in #\n"
+ "# any value in a question (not only the answer). Default #\n"
+ "# is 999, which is as high as it can be set. It can be set #\n"
+ "# lower to fine-tune the list for certain 'lessons'. #\n"
+ "############################################################\n\n";
+ vcomments[MAX_QUESTIONS] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Parameter: max_questions (integer) #\n"
+ "# Default: 5000 #\n"
+ "# #\n"
+ "# 'max_questions' is limit of the length of the question #\n"
+ "# list. Default is 5000 - only severe taskmasters will #\n"
+ "# need to raise it! #\n"
+ "############################################################\n\n";
+ vcomments[RANDOMIZE] =
+ "\n############################################################\n"
+ "# #\n"
+ "# Parameter: randomize (boolean) #\n"
+ "# Default: 1 #\n"
+ "# #\n"
+ "# If 'randomize' selected, the list will be shuffled #\n"
+ "# at the start of the game. Otherwise, the questions #\n"
+ "# appear in the order the program generates them. #\n"
+ "############################################################\n\n";
+
+ }
+
+ tmdprintf("\nEntering write_config_file()\n");
/* get out if file pointer null */
if(!fp)
{
fprintf (stderr, "write_config_file() - file pointer invalid/n");
-
- #ifdef TUXMATH_DEBUG
- printf("Leaving write_config_file()\n");
- #endif
-
+ tmdprintf("Leaving write_config_file()\n");
return 0;
}
-
- if (verbose)
+
+ for (i = 0; i < NOPTS; ++i) //for each option
{
- fprintf(fp,
- "############################################################\n"
- "# #\n"
- "# Tuxmath Configuration File #\n"
- "# #\n"
- "# The behavior of Tuxmath can be controlled to a great #\n"
- "# extent by editing this file with any and saving it in #\n"
- "# the default options location ($HOME/.tuxmath/options). #\n"
- "# The file consists of 'NAME = VALUE' pairs, one pair per #\n"
- "# line. Each option is one of the following types: #\n"
- "# #\n"
- "# boolean: 1 (synonyms 'true', 'T', 'yes', 'Y', 'on') #\n"
- "# or #\n"
- "# 0 (synonyms 'false, 'F', 'no', 'N', 'off') #\n"
- "# integer (i.e. non-fractional numbers) #\n"
- "# float (i.e decimal fractions) #\n"
- "# #\n"
- "# Lines beginning with '#' or ';' are ignored as comments. #\n"
- "# The synonyms for boolean '0' and '1' are accepted as #\n"
- "# input, but always written as '0' or '1' when Tuxmath #\n"
- "# writes a config file to disk. #\n"
- "# The file is organized with the more important options #\n"
- "# first. #\n"
- "############################################################\n"
- "\n"
- );
+ if (verbose && vcomments[i]) //comment goes before
+ fprintf(fp, vcomments[i]);
+ fprintf(fp, "%s = %d\n", MC_OPTION_TEXT[i], MC_GetOpt(i) );
}
-
+
if (verbose)
{
- fprintf(fp,
- "############################################################\n"
- "# #\n"
- "# Game Mode #\n"
- "# #\n"
- "# Parameter: play_through_list (Boolean) #\n"
- "# Default: 1 #\n"
- "# #\n"
- "# Tuxmath generates a list of math questions based on #\n"
- "# parameters set below. By default, (play_through_list = #\n"
- "# 1) the questions are asked in a random order. #\n"
- "# Correctly answered questions are removed from the list. #\n"
- "# If the player fails to correctly answer a question #\n"
- "# before it hits a city, the question will be reinserted #\n"
- "# into the list in a random location. #\n"
- "# The player wins if all questions are answered correctly #\n"
- "# before the cities are destroyed. #\n"
- "# #\n"
- "# Alternatively, Tuxmath can be played in 'Arcade Mode' #\n"
- "# by setting play_through_list = 0 (i.e. 'false'). If this #\n"
- "# is done, all questions will be randomly reinserted into #\n"
- "# the list whether or not they are answered correctly, and #\n"
- "# the game continues as long as there is a surviving city. #\n"
- "############################################################\n"
- "\n"
- );
+ //allow_speedup comment
}
- fprintf (fp, "play_through_list = %d\n", MC_PlayThroughList());
-
-
+ fprintf(fp, "allow_speedup = %d\n", Opts_AllowSpeedup() );
+
if (verbose)
{
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Speed and Number of Comets #\n"
- "# #\n"
- "# Parameter: allow_speedup (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: use_feedback (boolean) #\n"
- "# Default: 0 #\n"
- "# #\n"
- "# By default, the comets become faster and more numerous #\n"
- "# with each succeeding. The increase can be prevented #\n"
- "# by setting 'allow_speedup' to 0. #\n"
- "# #\n"
- "# If 'allow_speedup' is enabled, it is also possible to #\n"
- "# dynamically adjust the speed to the player's performance #\n"
- "# by setting 'use_feedback' to 1. This feature attempts #\n"
- "# to speed the game up if it is too easy for the player, #\n"
- "# and to slow it down if the player is having trouble. #\n"
- "# #\n"
- "# Many additional parameters under 'Advanced Options' can #\n"
- "# be used to fine-tune these behaviors. #\n"
- "############################################################\n\n");
- }
-
- fprintf(fp, "allow_speedup = %d\n", Opts_AllowSpeedup());
- fprintf(fp, "use_feedback = %d\n", Opts_UseFeedback());
-
-
+ //use_sound comment
+ }
+ fprintf(fp, "use_sound = %d\n", Opts_UseSound() );
+
if (verbose)
{
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Selecting Math Operations #\n"
- "# #\n"
- "# Parameter: addition_allowed (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: subtraction_allowed (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: multiplication_allowed (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: division_allowed (boolean) #\n"
- "# Default: 1 #\n"
- "# #\n"
- "# These options enable questions for each of the four math #\n"
- "# operations. All are 1 (yes) by default. #\n"
- "############################################################\n\n");
- }
-
- fprintf(fp, "addition_allowed = %d\n", MC_AddAllowed());
- fprintf(fp, "subtraction_allowed = %d\n", MC_SubAllowed());
- fprintf(fp, "multiplication_allowed = %d\n", MC_MultAllowed());
- fprintf(fp, "division_allowed = %d\n", MC_DivAllowed());
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Typing Practice #\n"
- "# #\n"
- "# Parameter: typing_practice_allowed (boolean) #\n"
- "# Default: 0 #\n"
- "# #\n"
- "# This option simply displays numbers for the youngest #\n"
- "# players to type in to learn the keyboard. #\n"
- "############################################################\n\n");
- }
-
- fprintf(fp, "typing_practice_allowed = %d\n", MC_TypingAllowed());
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Negative Number Support #\n"
- "# #\n"
- "# Parameter: allow_negatives (boolean) #\n"
- "# Default: 0 #\n"
- "# #\n"
- "# 'allow_negatives' allows or disallows use of negative #\n"
- "# numbers as both operands and answers. Default is 0 #\n"
- "# (no), which disallows questions like: #\n"
- "# 2 - 4 = ? #\n"
- "# Note: this option must be enabled in order to set the #\n"
- "# operand ranges to include negatives. If it is changed #\n"
- "# from 1 (yes) to 0 (no), any negative operand limits will #\n"
- "# be reset to 0. #\n"
- "############################################################\n\n");
- }
-
- fprintf (fp, "allow_negatives = %d\n", MC_AllowNegatives());
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Minimum and Maximum Values for Operand Ranges #\n"
- "# #\n"
- "# Parameters: (multiple - all integer type) #\n"
- "# #\n"
- "# Operand limits can be set to any integer up to the #\n"
- "# value of 'max_answer'. Tuxmath will generate questions #\n"
- "# for every value in the specified range. The maximum must #\n"
- "# be greater than or equal to the corresponding minimum #\n"
- "# for any questions to be generated for that operation. #\n"
- "# Defaults are 0 for minima and 12 for maxima. #\n"
- "# #\n"
- "# Note: 'allow_negatives' must be set to 1 for negative #\n"
- "# values to be accepted (see 'Advanced Options'). #\n"
- "############################################################\n");
- }
-
- if (verbose)
- {
- fprintf(fp, "\n# Addition operands:\n"
- "# augend + addend = sum\n\n");
- }
- fprintf(fp, "min_augend = %d\n", MC_AddMinAugend());
- fprintf(fp, "max_augend = %d\n", MC_AddMaxAugend());
- fprintf(fp, "min_addend = %d\n", MC_AddMinAddend());
- fprintf(fp, "max_addend = %d\n", MC_AddMaxAddend());
-
- if (verbose)
- {
- fprintf(fp, "\n# Subtraction operands:"
- "\n# minuend - subtrahend = difference\n\n");
- }
- fprintf(fp, "min_minuend = %d\n", MC_SubMinMinuend());
- fprintf(fp, "max_minuend = %d\n", MC_SubMaxMinuend());
- fprintf(fp, "min_subtrahend = %d\n", MC_SubMinSubtrahend());
- fprintf(fp, "max_subtrahend = %d\n", MC_SubMaxSubtrahend());
-
- if (verbose)
- {
- fprintf(fp, "\n# Multiplication operands:"
- "\n# multiplier * multiplicand = product\n\n");
- }
- fprintf(fp, "min_multiplier = %d\n", MC_MultMinMultiplier());
- fprintf(fp, "max_multiplier = %d\n", MC_MultMaxMultiplier());
- fprintf(fp, "min_multiplicand = %d\n", MC_MultMinMultiplicand());
- fprintf(fp, "max_multiplicand = %d\n", MC_MultMaxMultiplicand());
-
- if (verbose)
- {
- fprintf(fp, "\n# Division operands:"
- "\n# dividend/divisor = quotient\n\n");
- }
- fprintf(fp, "min_divisor = %d\n",MC_DivMinDivisor());
- fprintf(fp, "max_divisor = %d\n", MC_DivMaxDivisor());
- fprintf(fp, "min_quotient = %d\n", MC_DivMinQuotient());
- fprintf(fp, "max_quotient = %d\n", MC_DivMaxQuotient());
-
- if (verbose)
- {
- fprintf(fp, "\n# Typing practice:\n\n");
- }
- fprintf(fp, "min_typing_num = %d\n",MC_TypeMin());
- fprintf(fp, "max_typing_num = %d\n", MC_TypeMax());
-
- if (verbose)
- {
- fprintf (fp, "\n\n############################################################\n"
- "# #\n"
- "# General Game Options #\n"
- "# #\n"
- "# Parameter: use_sound (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: menu_sound (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: menu_music (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: fullscreen (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: demo_mode (boolean) #\n"
- "# Default: 0 #\n"
- "# Parameter: use_keypad (boolean) #\n"
- "# Default: 0 #\n"
- "# Parameter: allow_pause (boolean) #\n"
- "# Default: 0 #\n"
- "# Parameter: use_igloos (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: save_game_summary (boolean) #\n"
- "# Default: 1 #\n"
- "# #\n"
- "# These parameters control various aspects of Tuxmath's #\n"
- "# not directly related to the math question to be asked. #\n"
- "############################################################\n");
-
- }
- if (verbose)
- {
- fprintf (fp, "\n# Use game sounds and background music if possible:\n");
- }
- fprintf(fp, "use_sound = %d\n", Opts_UseSound());
- fprintf(fp, "menu_sound = %d\n", Opts_MenuSound());
- fprintf(fp, "menu_music = %d\n", Opts_MenuMusic());
-
- if (verbose)
- {
- fprintf (fp, "\n# Use fullscreen at 640x480 resolution instead of\n"
- "# 640x480 window. Change to 0 if SDL has trouble with\n"
- "# fullscreen on your system:\n");
- }
- fprintf(fp, "fullscreen = %d\n", Opts_Fullscreen());
-
- if (verbose)
- {
- fprintf (fp, "\n# Display jpg images for background:\n");
- }
- fprintf(fp, "use_bkgd = %d\n", Opts_UseBkgd());
-
- if (verbose)
- {
- fprintf (fp, "\n# Run Tuxmath as demo (i.e. without user input):\n");
- }
- fprintf(fp, "demo_mode = %d\n", Opts_DemoMode());
-
- if (verbose)
- {
- fprintf (fp, "\n# Display onscreen numeric keypad - allows mouse-only\n"
- "# gameplay or use with touchscreens:\n");
- }
- fprintf(fp, "use_keypad = %d\n", Opts_UseKeypad());
-
- if (verbose)
- {
- fprintf (fp, "\n# Allow 'Pause' feature - should disable this\n"
- "# when competing for high scores!\n");
- }
- fprintf(fp, "allow_pause = %d\n", Opts_AllowPause());
-
- if (verbose)
- {
- fprintf (fp, "\n# Use newer graphics where Tux defends igloo-\n"
- "# dwelling penguins (for those who find the older\n"
- "# images of exploding cities to be distasteful)\n");
- }
- fprintf(fp, "use_igloos = %d\n", Opts_UseIgloos());
-
- if (verbose)
- {
- fprintf (fp, "\n# By default, Tuxmath saves summaries of the last\n"
- "# ten games in the user's .tuxmath directory. Set\n"
- "# this parameter to '0' to turn off.\n");
- }
- fprintf(fp, "save_summary = %d\n", Opts_SaveSummary());
-
- if (verbose)
- {
- fprintf (fp, "\n\n\n############################################################\n"
- "# #\n"
- "# Advanced Options #\n"
- "# #\n"
- "# The remaining settings further customize Tuxmath's #\n"
- "# behavior. Most users will probably not change them. #\n"
- "############################################################\n\n");
- }
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Advanced Math Question List Options #\n"
- "# #\n"
- "# Parameter: question_copies (integer) #\n"
- "# Default: 1 #\n"
- "# Parameter: repeat_wrongs (boolean) #\n"
- "# Default: 1 #\n"
- "# Parameter: copies_repeated_wrongs (integer) #\n"
- "# Default: 1 #\n"
- "# Parameter: fraction_to_keep (float) #\n"
- "# Default: 1 #\n"
- "# #\n"
- "# These settings offer further control over the question #\n"
- "# list and are generally only useful if 'play_through_list'#\n"
- "# is enabled (as it is by default). #\n"
- "# #\n"
- "# 'question_copies' is the number of times each question #\n"
- "# is put into the initial list. It can be 1 to 10. #\n"
- "# #\n"
- "# 'repeat_wrongs' determines whether questions the player #\n"
- "# failed to answer correctly will be asked again. #\n"
- "# #\n"
- "# 'copies_repeated_wrongs' gives the number of times a #\n"
- "# missed question will reappear. This can be set anywhere #\n"
- "# from 1 to 10. #\n"
- "# #\n"
- "# 'fraction_to_keep' allows a list to be generated that #\n"
- "# consists of a randomly-selected subset of the questions #\n"
- "# fitting the criteria. The parameter is a float that #\n"
- "# must be greater than 0 and less than or equal to 1. For #\n"
- "# example, a value of 0.1 means 10%% of the questions #\n"
- "# meeting the criteria will go into the list. #\n"
- "# #\n"
- "# The defaults for these values result in a 'mission' #\n"
- "# for Tux that is accomplished by answering all #\n"
- "# questions correctly with at least one surviving city. #\n"
- "############################################################\n\n");
- }
-
- fprintf (fp, "question_copies = %d\n", MC_QuestionCopies());
- fprintf (fp, "repeat_wrongs = %d\n", MC_RepeatWrongs());
- fprintf (fp, "copies_repeated_wrongs = %d\n", MC_CopiesRepeatedWrongs());
- fprintf (fp, "fraction_to_keep = %.2f\n", MC_FractionToKeep());
-
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Math Question Formats #\n"
- "# #\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_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. All parameters are type 'boolean'. #\n"
- "############################################################\n\n");
- }
-
- fprintf (fp, "format_add_answer_last = %d\n", MC_FormatAddAnswerLast());
- fprintf (fp, "format_add_answer_first = %d\n", MC_FormatAddAnswerFirst());
- fprintf (fp, "format_add_answer_middle = %d\n", MC_FormatAddAnswerMiddle());
- fprintf (fp, "format_sub_answer_last = %d\n", MC_FormatSubAnswerLast());
- fprintf (fp, "format_sub_answer_first = %d\n", MC_FormatSubAnswerFirst());
- fprintf (fp, "format_sub_answer_middle = %d\n", MC_FormatSubAnswerMiddle());
- fprintf (fp, "format_mult_answer_last = %d\n", MC_FormatMultAnswerLast());
- fprintf (fp, "format_mult_answer_first = %d\n", MC_FormatMultAnswerFirst());
- fprintf (fp, "format_mult_answer_middle = %d\n", MC_FormatMultAnswerMiddle());
- fprintf (fp, "format_div_answer_last = %d\n", MC_FormatDivAnswerLast());
- fprintf (fp, "format_div_answer_first = %d\n", MC_FormatDivAnswerFirst());
- fprintf (fp, "format_div_answer_middle = %d\n", MC_FormatDivAnswerMiddle());
-
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Parameter: max_answer (integer) #\n"
- "# Default: 999 #\n"
- "# #\n"
- "# 'max_answer' is the largest absolute value allowed in #\n"
- "# any value in a question (not only the answer). Default #\n"
- "# is 999, which is as high as it can be set. It can be set #\n"
- "# lower to fine-tune the list for certain 'lessons'. #\n"
- "############################################################\n\n");
- }
- fprintf (fp, "max_answer = %d\n", MC_MaxAnswer());
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Parameter: max_questions (integer) #\n"
- "# Default: 5000 #\n"
- "# #\n"
- "# 'max_questions' is limit of the length of the question #\n"
- "# list. Default is 5000 - only severe taskmasters will #\n"
- "# need to raise it! #\n"
- "############################################################\n\n");
- }
- fprintf (fp, "max_questions = %d\n", MC_MaxQuestions());
-
- if (verbose)
- {
- fprintf (fp, "\n############################################################\n"
- "# #\n"
- "# Parameter: randomize (boolean) #\n"
- "# Default: 1 #\n"
- "# #\n"
- "# If 'randomize' selected, the list will be shuffled #\n"
- "# at the start of the game. Otherwise, the questions #\n"
- "# appear in the order the program generates them. #\n"
- "############################################################\n\n");
- }
- fprintf (fp, "randomize = %d\n", MC_Randomize());
-
-
- if (verbose)
- {
fprintf (fp, "\n############################################################\n"
"# #\n"
"# Advanced Comet Speed Options #\n"
Modified: tuxmath/branches/mathcards_newarch/src/game.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/game.c 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/game.c 2008-06-24 01:21:32 UTC (rev 551)
@@ -42,8 +42,8 @@
#define FPS 15 /* 15 frames per second */
#define MS_PER_FRAME (1000 / FPS)
-#define CITY_EXPL_START 3 * 5 /* Must be mult. of 5 (number of expl frames) */
-#define ANIM_FRAME_START 4 * 2 /* Must be mult. of 2 (number of tux frames) */
+#define CITY_EXPL_START (3 * 5) /* Must be mult. of 5 (number of expl frames) */
+#define ANIM_FRAME_START (4 * 2) /* Must be mult. of 2 (number of tux frames) */
#define GAMEOVER_COUNTER_START 40
#define LEVEL_START_WAIT_START 20
#define LASER_START 5
@@ -185,7 +185,7 @@
static void game_key_event(SDLKey key);
static void free_on_exit(void);
-static void help_add_comet(int a,int oper,int b,int c);
+static void help_add_comet(const char* formula_str, const char* ans_str);
static int help_renderframe_exit(void);
static void game_recalc_positions(void);
@@ -713,7 +713,7 @@
// Bring in a comet
speed = 2;
- help_add_comet(2,MC_OPER_ADD,1,3);
+ help_add_comet("2 + 1 = ?", "3");
help_controls.laser_enabled = 1;
level_start_wait = 0;
@@ -756,7 +756,7 @@
return;
game_clear_message(&s5);
- help_add_comet(3,MC_OPER_MULT,3,9);
+ help_add_comet("3 * 3 = ?", "9");
comets[0].y = 2*(screen->h)/3; // start it low down
while (!(comets[0].expl) && !(quit_help = help_renderframe_exit())); // wait 3 secs
if (quit_help)
@@ -781,7 +781,7 @@
return;
game_clear_message(&s3);
- help_add_comet(56,MC_OPER_DIV,8,7);
+ help_add_comet("56 / 8 = ?", "7");
comets[0].y = 2*(screen->h)/3; // start it low down
while (comets[0].alive && !(quit_help = help_renderframe_exit()));
if (quit_help)
@@ -794,7 +794,7 @@
help_controls.laser_enabled = 1;
game_set_message(&s1,_("You can fix the igloos"),left_edge,100);
game_set_message(&s2,_("by stopping bonus comets."),left_edge,135);
- help_add_comet(2,MC_OPER_ADD,2,4);
+ help_add_comet("2 + 2 = ?", "4");
comets[0].bonus = 1;
frame_start = frame;
while (comets[0].alive && (frame-frame_start < 50) && !(quit_help = help_renderframe_exit()));
@@ -866,29 +866,30 @@
return (game_status != GAME_IN_PROGRESS);
}
-void help_add_comet(int a,int oper,int b,int c)
+/* explicitly create a comet with a hardcoded problem */
+void help_add_comet(const char* formula_str, const char* ans_str)
{
- char probstr[MC_FORMULA_LEN];
- char ansstr[MC_ANSWER_LEN];
+// char probstr[MC_FORMULA_LEN];
+// char ansstr[MC_ANSWER_LEN];
comets[0].alive = 1;
comets[0].expl = 0;
- comets[0].answer = c;
+ comets[0].answer = atoi(ans_str);
num_comets_alive = 1;
comets[0].city = 0;
comets[0].x = cities[0].x;
comets[0].y = 0;
comets[0].zapped = 0;
comets[0].bonus = 0;
- comets[0].flashcard.num1 = a;
- comets[0].flashcard.num2 = b;
- comets[0].flashcard.num3 = c;
- comets[0].flashcard.operation = oper;
- comets[0].flashcard.format = MC_FORMAT_ANS_LAST;
- snprintf(probstr,MC_FORMULA_LEN,"%d %c %d = ?",a,operchars[oper],b);
- strncpy(comets[0].flashcard.formula_string,probstr,MC_FORMULA_LEN);
- snprintf(ansstr,MC_ANSWER_LEN,"%d",c);
- strncpy(comets[0].flashcard.answer_string,ansstr,MC_ANSWER_LEN);
+// comets[0].flashcard.num1 = a;
+// comets[0].flashcard.num2 = b;
+// comets[0].flashcard.num3 = c;
+// comets[0].flashcard.operation = oper;
+// comets[0].flashcard.format = MC_FORMAT_ANS_LAST;
+// snprintf(probstr,MC_FORMULA_LEN,"%d %c %d = ?",a,operchars[oper],b);
+ strncpy(comets[0].flashcard.formula_string,formula_str,MC_MaxFormulaSize() );
+// snprintf(ansstr,MC_ANSWER_LEN,"%d",c);
+ strncpy(comets[0].flashcard.answer_string,ans_str,MC_MaxAnswerSize() );
}
void game_set_message(game_message *msg,char *txt,int x,int y)
@@ -1137,7 +1138,8 @@
/* [ add = 25, sub = 50, mul = 75, div = 100 ] */
/* [ the higher the better ] */
- add_score(((25 * (comets[lowest].flashcard.operation + 1)) *
+ /* FIXME looks like it might score a bit differently based on screen mode? */
+ add_score(((25 * (comets[lowest].flashcard.difficulty + 1)) *
(screen->h - comets[lowest].y + 1)) /
screen->h);
}
@@ -1739,7 +1741,7 @@
{
/* pick image to draw: */
int keypad_image;
- if (MC_AllowNegatives())
+ if (MC_GetOpt(ALLOW_NEGATIVES) )
{
/* draw regular keypad */
keypad_image = IMG_KEYPAD;
@@ -2060,7 +2062,7 @@
/* If we are playing through a defined list of questions */
/* without "recycling", display number of remaining questions: */
- if (MC_PlayThroughList())
+ if (MC_GetOpt(PLAY_THROUGH_LIST) )
{
draw_question_counter();
}
@@ -2456,32 +2458,33 @@
/* If we make it to here, create a new comet! */
- /* The answer may be num1, num2, or num3, depending on format. */
- switch (comets[found].flashcard.format)
- {
- case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
- {
- comets[found].answer = comets[found].flashcard.num3;
- break;
- }
- case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
- {
- comets[found].answer = comets[found].flashcard.num2;
- break;
- }
- case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
- {
- comets[found].answer = comets[found].flashcard.num1;
- break;
- }
- default: /* should not get to here if MathCards behaves correctly */
- {
- fprintf(stderr, "\nadd_comet() - invalid question format");
- return 0;
- }
- }
+ comets[found].answer = comets[found].flashcard.answer;
+// /* The answer may be num1, num2, or num3, depending on format. */
+// switch (comets[found].flashcard.format)
+// {
+// case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
+// {
+// comets[found].answer = comets[found].flashcard.num3;
+// break;
+// }
+// case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
+// {
+// comets[found].answer = comets[found].flashcard.num2;
+// break;
+// }
+// case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
+// {
+// comets[found].answer = comets[found].flashcard.num1;
+// break;
+// }
+// default: /* should not get to here if MathCards behaves correctly */
+// {
+// fprintf(stderr, "\nadd_comet() - invalid question format");
+// return 0;
+// }
+// }
+
-
comets[found].alive = 1;
num_comets_alive++;
@@ -2912,7 +2915,7 @@
/* begin drawing so as to center display depending on whether minus */
/* sign needed (4 digit slots) or not (3 digit slots) DSB */
- if (MC_AllowNegatives())
+ if (MC_GetOpt(ALLOW_NEGATIVES) )
dest.x = ((screen->w - ((images[IMG_LEDNUMS]->w) / 10) * 4) / 2);
else
dest.x = ((screen->w - ((images[IMG_LEDNUMS]->w) / 10) * 3) / 2);
@@ -2922,7 +2925,7 @@
{
if (-1 == i)
{
- if (MC_AllowNegatives())
+ if (MC_GetOpt(ALLOW_NEGATIVES))
{
if (neg_answer_picked)
src.x = (images[IMG_LED_NEG_SIGN]->w) / 2;
@@ -2993,7 +2996,7 @@
/* make sure keypad image is valid and has non-zero dimensions: */
/* FIXME maybe this checking should be done once at the start */
/* of game() rather than with every mouse click */
- if (MC_AllowNegatives())
+ if (MC_GetOpt(ALLOW_NEGATIVES))
{
if (!images[IMG_KEYPAD])
return;
@@ -3231,14 +3234,14 @@
}
/* support for negative answer input DSB */
else if ((key == SDLK_MINUS || key == SDLK_KP_MINUS)
- && MC_AllowNegatives()) /* do nothing unless neg answers allowed */
+ && MC_GetOpt(ALLOW_NEGATIVES) ) /* do nothing unless neg answers allowed */
{
/* allow player to make answer negative: */
neg_answer_picked = 1;
tux_pressing = 1;
}
else if ((key == SDLK_PLUS || key == SDLK_KP_PLUS)
- && MC_AllowNegatives()) /* do nothing unless neg answers allowed */
+ && MC_GetOpt(ALLOW_NEGATIVES) ) /* do nothing unless neg answers allowed */
{
/* allow player to make answer positive: */
neg_answer_picked = 0;
Modified: tuxmath/branches/mathcards_newarch/src/mathcards.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.c 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.c 2008-06-24 01:21:32 UTC (rev 551)
@@ -20,6 +20,129 @@
#include "mathcards.h"
+/* extern'd constants */
+const char* const MC_OPTION_TEXT[NOPTS+1] = {
+"PLAY_THROUGH_LIST",
+"REPEAT_WRONGS",
+"COPIES_REPEATED_WRONGS",
+"ALLOW_NEGATIVES",
+"MAX_ANSWER",
+"MAX_QUESTIONS",
+"QUESTION_COPIES",
+"MAX_FORMULA_NUMS",
+"MIN_FORMULA_NUMS",
+
+"FORMAT_ANSWER_LAST",
+"FORMAT_ANSWER_FIRST",
+"FORMAT_ANSWER_MIDDLE",
+"FORMAT_ADD_ANSWER_LAST",
+"FORMAT_ADD_ANSWER_FIRST",
+"FORMAT_ADD_ANSWER_MIDDLE",
+"FORMAT_SUB_ANSWER_LAST",
+"FORMAT_SUB_ANSWER_FIRST",
+"FORMAT_SUB_ANSWER_MIDDLE",
+"FORMAT_MULT_ANSWER_LAST",
+"FORMAT_MULT_ANSWER_FIRST",
+"FORMAT_MULT_ANSWER_MIDDLE",
+"FORMAT_DIV_ANSWER_LAST",
+"FORMAT_DIV_ANSWER_FIRST",
+"FORMAT_DIV_ANSWER_MIDDLE",
+
+"ADDITION_ALLOWED",
+"SUBTRACTION_ALLOWED",
+"MULTIPLICATION_ALLOWED",
+"DIVISION_ALLOWED",
+"TYPING_PRACTICE_ALLOWED",
+
+"MIN_AUGEND",
+"MAX_AUGEND",
+"MIN_ADDEND",
+"MAX_ADDEND",
+
+"MIN_MINUEND",
+"MAX_MINUEND",
+"MIN_SUBTRAHEND",
+"MAX_SUBTRAHEND",
+
+"MIN_MULTIPLIER",
+"MAX_MULTIPLIER",
+"MIN_MULTIPLICAND",
+"MAX_MULTIPLICAND",
+
+"MIN_DIVISOR",
+"MAX_DIVISOR",
+"MIN_QUOTIENT",
+"MAX_QUOTIENT",
+
+"MIN_TYPING_NUM",
+"MAX_TYPING_NUM",
+
+"RANDOMIZE",
+
+"END_OF_OPTS"
+};
+
+const int MC_DEFAULTS[] = {
+ 1, //PLAY_THROUGH_LIST
+ 1, //REPEAT_WRONGS
+ 1, //COPIES_REPEATED_WRONGS
+ 0, //ALLOW_NEGATIVES
+ 999, //MAX_ANSWER
+ 5000, //MAX_QUESTIONS
+ 1, //QUESTION_COPIES
+ 2, //MAX_FORMULA_NUMS
+ 5, //MIN_FORMULA_NUMS
+ //
+ 1, //FORMAT_ANSWER_LAST
+ 0, //FORMAT_ANSWER_FIRST
+ 0, //FORMAT_ANSWER_MIDDLE
+ 1, //FORMAT_ADD_ANSWER_LAST
+ 0, //FORMAT_ADD_ANSWER_FIRST
+ 0, //FORMAT_ADD_ANSWER_MIDDLE
+ 1, //FORMAT_SUB_ANSWER_LAST
+ 0, //FORMAT_SUB_ANSWER_FIRST
+ 0, //FORMAT_SUB_ANSWER_MIDDLE
+ 1, //FORMAT_MULT_ANSWER_LAST
+ 0, //FORMAT_MULT_ANSWER_FIRST
+ 0, //FORMAT_MULT_ANSWER_MIDDLE
+ 1, //FORMAT_DIV_ANSWER_LAST
+ 0, //FORMAT_DIV_ANSWER_FIRST
+ 0, //FORMAT_DIV_ANSWER_MIDDLE
+ //
+ 1, //ADDITION_ALLOWED
+ 1, //SUBTRACTION_ALLOWED
+ 1, //MULTIPLICATION_ALLOWED
+ 1, //DIVISION_ALLOWED
+ 0, //TYPING_PRACTICE_ALLOWED
+ //
+ 0, //MIN_AUGEND
+ 12, //MAX_AUGEND
+ 0, //MIN_ADDEND
+ 12, //MAX_ADDEND
+ //
+ 0, //MIN_MINUEND
+ 12, //MAX_MINUEND
+ 0, //MIN_SUBTRAHEND
+ 12, //MAX_SUBTRAHEND
+ //
+ 0, //MIN_MULTIPLIER
+ 12, //MAX_MULTIPLIER
+ 0, //MIN_MULTIPLICAND
+ 12, //MAX_MULTIPLICAND
+ //
+ 0, //MIN_DIVISOR
+ 12, //MAX_DIVISOR
+ 0, //MIN_QUOTIENT
+ 12, //MAX_QUOTIENT
+ //
+ 0, //MIN_TYPING_NUM
+ 12, //MAX_TYPING_NUM
+ //
+ 1 //RANDOMIZE
+};
+
+
+
/* "Globals" for mathcards.c: */
MC_Options* math_opts = 0;
MC_MathQuestion* question_list = 0;
@@ -32,12 +155,16 @@
int questions_pending = 0;
int unanswered = 0;
int starting_length = 0;
+int max_formula_size = 0; //max length in chars of a flashcard's formula
+int max_answer_size = 0; //and of its answer
/* For keeping track of timing data */
float* time_per_question_list = NULL;
int length_time_per_question_list = 0;
int length_alloc_time_per_question_list = 0;
+const MC_FlashCard DEFAULT_CARD = {NULL,NULL,0,0}; //empty card to signal error
+
/* "private" function prototypes: */
/* */
/* these are for internal use by MathCards only - like */
@@ -81,9 +208,13 @@
#endif
/* Functions for new mathcards architecture */
-MC_FlashCard create_flashcard(void); //allocate space for a flashcard
-void free_flashcard(MC_FlashCard* fc); //be sure to free flashcards when done
-void copy_card(const MC_FlashCard* src, MC_FlashCard* dest); //deep copy a flashcard
+static MC_FlashCard allocate_flashcard(void); //allocate space for a flashcard
+static void free_flashcard(MC_FlashCard fc); //be sure to free flashcards when done
+static void free_node(MC_MathQuestion* mq); //wrapper for free() that also frees card
+static MC_FlashCard generate_random_flashcard(void);
+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
/* MC_Initialize() sets up the struct containing all of */
/* settings regarding math questions. It should be */
@@ -121,12 +252,12 @@
fprintf(stderr, "\nUnable to initialize math_options");
return 0;
}
-
+
/* set defaults */
+ math_opts->fraction_to_keep = DEFAULT_FRACTION_TO_KEEP;
for (i = 0; i < NOPTS; ++i)
{
math_opts->iopts[i] = MC_DEFAULTS[i];
- math_opts->fraction_to_keep = DEFAULT_FRACTION_TO_KEEP;
}
/* if no negatives to be used, reset any negatives to 0 */
@@ -192,7 +323,13 @@
length_time_per_question_list = 0;
length_alloc_time_per_question_list = 0;
}
-
+
+ /* determine how much space needed for strings, based on user options */
+ max_formula_size = MC_GetOpt(MAX_FORMULA_NUMS)
+ * ((int)(log10f(MC_GLOBAL_MAX) ) + 4) //sign/operator/spaces
+ + 2; //question mark for answer, and ending '\0'
+ max_answer_size = (int)(log10f(MC_GLOBAL_MAX) ) + 2; //sign and ending '\0'
+
/* set up new list with pointer to top: */
question_list = generate_list();
@@ -475,7 +612,7 @@
{
int i;
- mcdprintf("\nAdding %d copies to question_list:", math_opts->copies_repeated_wrongs);
+ 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++)
@@ -633,7 +770,7 @@
// fprintf(stderr, "\nMC_SetAllowNegatives(): math_opts not valid!\n");
// return;
// }
-// math_opts->allow_negatives = int_to_bool(opt);
+// math_opts->iopts[ALLOW_NEGATIVES] = int_to_bool(opt);
// if (!opt)
// {
// clear_negatives();
@@ -878,7 +1015,7 @@
// copies = 1;
// if (copies > 10)
// copies = 10;
-// math_opts->question_copies = copies;
+// math_opts->iopts[QUESTION_COPIES] = copies;
//}
//
//
@@ -889,7 +1026,7 @@
// fprintf(stderr, "\nMC_SetRandomize(): math_opts not valid!\n");
// return;
// }
-// math_opts->randomize = int_to_bool(opt);
+// math_opts->iopts[RANDOMIZE] = int_to_bool(opt);
//}
//
//void MC_SetFractionToKeep(float fract)
@@ -916,7 +1053,7 @@
// fprintf(stderr, "\nMC_SetAddAllowed(): math_opts not valid!\n");
// return;
// }
-// math_opts->addition_allowed = int_to_bool(opt);
+// math_opts->iopts[ADDITION_ALLOWED] = int_to_bool(opt);
//}
//
//
@@ -927,7 +1064,7 @@
// fprintf(stderr, "\nMC_SetSubAllowed(): math_opts not valid!\n");
// return;
// }
-// math_opts->subtraction_allowed = int_to_bool(opt);
+// math_opts->iopts[SUBTRACTION_ALLOWED] = int_to_bool(opt);
//}
//
//
@@ -938,7 +1075,7 @@
// fprintf(stderr, "\nMC_SetMultAllowed(): math_opts not valid!\n");
// return;
// }
-// math_opts->multiplication_allowed = int_to_bool(opt);
+// math_opts->iopts[MULTIPLICATION_ALLOWED] = int_to_bool(opt);
//}
//
//
@@ -949,7 +1086,7 @@
// fprintf(stderr, "\nMC_SetDivAllowed(): math_opts not valid!\n");
// return;
// }
-// math_opts->division_allowed = int_to_bool(opt);
+// math_opts->iopts[DIVISION_ALLOWED] = int_to_bool(opt);
//}
//
//
@@ -960,7 +1097,7 @@
// fprintf(stderr, "\nMC_SetTypingAllowed(): math_opts not valid!\n");
// return;
// }
-// math_opts->typing_practice_allowed = int_to_bool(opt);
+// math_opts->iopts[TYPING_PRACTICE_ALLOWED] = int_to_bool(opt);
//}
//
//
@@ -980,7 +1117,7 @@
// fprintf(stderr, "\nMC_SetAddMinAugend(): math_opts not valid!\n");
// return;
// }
-// math_opts->min_augend = sane_value(opt);
+// math_opts->iopts[MIN_AUGEND] = sane_value(opt);
//}
//
//
@@ -991,7 +1128,7 @@
// fprintf(stderr, "\nMC_SetAddMinAddend(): math_opts not valid!\n");
// return;
// }
-// math_opts->min_addend = sane_value(opt);
+// math_opts->iopts[MIN_ADDEND] = sane_value(opt);
//}
//
//
@@ -1837,7 +1974,7 @@
"# is 144. It can be set as high as 999. #\n"
"############################################################\n\n");
}
- fprintf (fp, "max_answer = %d\n", math_opts->max_answer);
+ fprintf (fp, "max_answer = %d\n", math_opts->iopts[MAX_ANSWER]);
if (verbose)
{
@@ -1847,7 +1984,7 @@
"# need to raise it. #\n"
"############################################################\n\n");
}
- fprintf (fp, "max_questions = %d\n", math_opts->max_questions);
+ fprintf (fp, "max_questions = %d\n", math_opts->iopts[MAX_QUESTIONS]);
if (verbose)
{
@@ -1856,7 +1993,7 @@
"# at the start of the game. Default is 1 (yes). #\n"
"############################################################\n\n");
}
- fprintf (fp, "randomize = %d\n", math_opts->randomize);
+ fprintf (fp, "randomize = %d\n", math_opts->iopts[RANDOMIZE]);
if (verbose)
{
@@ -1868,10 +2005,10 @@
"# operations. All are 1 (yes) by default. #\n"
"############################################################\n\n");
}
- fprintf(fp, "addition_allowed = %d\n", math_opts->addition_allowed);
- fprintf(fp, "subtraction_allowed = %d\n", math_opts->subtraction_allowed);
- fprintf(fp, "multiplication_allowed = %d\n", math_opts->multiplication_allowed);
- fprintf(fp, "division_allowed = %d\n", math_opts->division_allowed);
+ fprintf(fp, "addition_allowed = %d\n", math_opts->iopts[ADDITION_ALLOWED]);
+ fprintf(fp, "subtraction_allowed = %d\n", math_opts->iopts[SUBTRACTION_ALLOWED]);
+ fprintf(fp, "multiplication_allowed = %d\n", math_opts->iopts[MULTIPLICATION_ALLOWED]);
+ fprintf(fp, "division_allowed = %d\n", math_opts->iopts[DIVISION_ALLOWED]);
if (verbose)
@@ -1890,32 +2027,32 @@
"############################################################\n\n");
}
fprintf(fp, "\n# Addition operands: augend + addend = sum\n");
- fprintf(fp, "min_augend = %d\n", math_opts->min_augend);
- fprintf(fp, "max_augend = %d\n", math_opts->max_augend);
- fprintf(fp, "min_addend = %d\n", math_opts->min_addend);
- fprintf(fp, "max_addend = %d\n", math_opts->max_addend);
+ fprintf(fp, "min_augend = %d\n", math_opts->iopts[MIN_AUGEND]);
+ fprintf(fp, "max_augend = %d\n", math_opts->iopts[MAX_AUGEND]);
+ fprintf(fp, "min_addend = %d\n", math_opts->iopts[MIN_ADDEND]);
+ fprintf(fp, "max_addend = %d\n", math_opts->iopts[MAX_ADDEND]);
fprintf(fp, "\n# Subtraction operands: minuend - subtrahend = difference\n");
- fprintf(fp, "min_minuend = %d\n", math_opts->min_minuend);
- fprintf(fp, "max_minuend = %d\n", math_opts->max_minuend);
- fprintf(fp, "min_subtrahend = %d\n", math_opts->min_subtrahend);
- fprintf(fp, "max_subtrahend = %d\n", math_opts->max_subtrahend);
+ fprintf(fp, "min_minuend = %d\n", math_opts->iopts[MIN_MINUEND]);
+ fprintf(fp, "max_minuend = %d\n", math_opts->iopts[MAX_MINUEND]);
+ fprintf(fp, "min_subtrahend = %d\n", math_opts->iopts[MIN_SUBTRAHEND]);
+ fprintf(fp, "max_subtrahend = %d\n", math_opts->iopts[MAX_SUBTRAHEND]);
fprintf(fp, "\n# Multiplication operands: multiplier * multiplicand = product\n");
- fprintf(fp, "min_multiplier = %d\n", math_opts->min_multiplier);
- fprintf(fp, "max_multiplier = %d\n", math_opts->max_multiplier);
- fprintf(fp, "min_multiplicand = %d\n", math_opts->min_multiplicand);
- fprintf(fp, "max_multiplicand = %d\n", math_opts->max_multiplicand);
+ fprintf(fp, "min_multiplier = %d\n", math_opts->iopts[MIN_MULTIPLIER]);
+ fprintf(fp, "max_multiplier = %d\n", math_opts->iopts[MAX_MULTIPLIER]);
+ fprintf(fp, "min_multiplicand = %d\n", math_opts->iopts[MIN_MULTIPLICAND]);
+ fprintf(fp, "max_multiplicand = %d\n", math_opts->iopts[MAX_MULTIPLICAND]);
fprintf(fp, "\n# Division operands: dividend/divisor = quotient\n");
- fprintf(fp, "min_divisor = %d\n",math_opts->min_divisor);
- fprintf(fp, "max_divisor = %d\n", math_opts->max_divisor);
- fprintf(fp, "min_quotient = %d\n", math_opts->min_quotient);
- fprintf(fp, "max_quotient = %d\n", math_opts->max_quotient);
+ fprintf(fp, "min_divisor = %d\n",math_opts->iopts[MIN_DIVISOR]);
+ fprintf(fp, "max_divisor = %d\n", math_opts->iopts[MAX_DIVISOR]);
+ fprintf(fp, "min_quotient = %d\n", math_opts->iopts[MIN_QUOTIENT]);
+ fprintf(fp, "max_quotient = %d\n", math_opts->iopts[MAX_QUOTIENT]);
fprintf(fp, "\n# Typing practice:\n");
- fprintf(fp, "min_typing_num = %d\n",math_opts->min_typing_num);
- fprintf(fp, "max_typing_num = %d\n",math_opts->max_typing_num);
+ fprintf(fp, "min_typing_num = %d\n",math_opts->iopts[MIN_TYPING_NUM]);
+ fprintf(fp, "max_typing_num = %d\n",math_opts->iopts[MAX_TYPING_NUM]);
#ifdef MC_DEBUG
printf("\nLeaving MC_PrintMathOptions()\n");
@@ -2000,52 +2137,53 @@
/* Resets negative values to zero - used when allow_negatives deselected. */
void clear_negatives(void)
{
- if (math_opts->min_augend < 0)
- math_opts->min_augend = 0;
- if (math_opts->max_augend < 0)
- math_opts->max_augend = 0;
- if (math_opts->min_addend < 0)
- math_opts->min_addend = 0;
- if (math_opts->max_addend < 0)
- math_opts->max_addend = 0;
+ if (math_opts->iopts[MIN_AUGEND ]< 0)
+ math_opts->iopts[MIN_AUGEND ]= 0;
+ if (math_opts->iopts[MAX_AUGEND ]< 0)
+ math_opts->iopts[MAX_AUGEND ]= 0;
+ if (math_opts->iopts[MIN_ADDEND ]< 0)
+ math_opts->iopts[MIN_ADDEND] = 0;
+ if (math_opts->iopts[MAX_ADDEND] < 0)
+ math_opts->iopts[MAX_ADDEND] = 0;
- if (math_opts->min_minuend < 0)
- math_opts->min_minuend = 0;
- if (math_opts->max_minuend < 0)
- math_opts->max_minuend = 0;
- if (math_opts->min_subtrahend < 0)
- math_opts->min_subtrahend = 0;
- if (math_opts->max_subtrahend < 0)
- math_opts->max_subtrahend = 0;
+ if (math_opts->iopts[MIN_MINUEND] < 0)
+ math_opts->iopts[MIN_MINUEND] = 0;
+ if (math_opts->iopts[MAX_MINUEND] < 0)
+ math_opts->iopts[MAX_MINUEND] = 0;
+ if (math_opts->iopts[MIN_SUBTRAHEND] < 0)
+ math_opts->iopts[MIN_SUBTRAHEND] = 0;
+ if (math_opts->iopts[MAX_SUBTRAHEND] < 0)
+ math_opts->iopts[MAX_SUBTRAHEND] = 0;
- if (math_opts->min_multiplier < 0)
- math_opts->min_multiplier = 0;
- if (math_opts->max_multiplier < 0)
- math_opts->max_multiplier = 0;
- if (math_opts->min_multiplicand < 0)
- math_opts->min_multiplicand = 0;
- if (math_opts->max_multiplicand < 0)
- math_opts->max_multiplicand = 0;
+ if (math_opts->iopts[MIN_MULTIPLIER] < 0)
+ math_opts->iopts[MIN_MULTIPLIER] = 0;
+ if (math_opts->iopts[MAX_MULTIPLIER] < 0)
+ math_opts->iopts[MAX_MULTIPLIER] = 0;
+ if (math_opts->iopts[MIN_MULTIPLICAND] < 0)
+ math_opts->iopts[MIN_MULTIPLICAND] = 0;
+ if (math_opts->iopts[MAX_MULTIPLICAND] < 0)
+ math_opts->iopts[MAX_MULTIPLICAND] = 0;
- if (math_opts->min_divisor < 0)
- math_opts->min_divisor = 0;
- if (math_opts->max_divisor < 0)
- math_opts->max_divisor = 0;
- if (math_opts->min_quotient < 0)
- math_opts->min_quotient = 0;
- if (math_opts->max_quotient < 0)
- math_opts->max_quotient = 0;
+ if (math_opts->iopts[MIN_DIVISOR] < 0)
+ math_opts->iopts[MIN_DIVISOR] = 0;
+ if (math_opts->iopts[MAX_DIVISOR] < 0)
+ math_opts->iopts[MAX_DIVISOR] = 0;
+ if (math_opts->iopts[MIN_QUOTIENT] < 0)
+ math_opts->iopts[MIN_QUOTIENT] = 0;
+ if (math_opts->iopts[MAX_QUOTIENT] < 0)
+ math_opts->iopts[MAX_QUOTIENT] = 0;
- if (math_opts->min_typing_num < 0)
- math_opts->min_typing_num = 0;
- if (math_opts->max_typing_num < 0)
- math_opts->max_typing_num = 0;
+ if (math_opts->iopts[MIN_TYPING_NUM] < 0)
+ math_opts->iopts[MIN_TYPING_NUM] = 0;
+ if (math_opts->iopts[MAX_TYPING_NUM] < 0)
+ math_opts->iopts[MAX_TYPING_NUM] = 0;
}
/* using parameters from the mission struct, create linked list of "flashcards" */
/* FIXME should figure out how to proceed correctly if we run out of memory */
/* FIXME very redundant code - figure out way to iterate through different */
/* math operations and question formats */
+#ifndef MC_USE_NEWARC
MC_MathQuestion* generate_list(void)
{
MC_MathQuestion* top_of_list = NULL;
@@ -2066,21 +2204,21 @@
printf("\ngenerating addition questions\n");
#endif
- if (math_opts->addition_allowed)
+ if (math_opts->iopts[ADDITION_ALLOWED])
{
#ifdef MC_DEBUG
printf("\nAddition problems");
#endif
- for (i = math_opts->min_augend; i <= math_opts->max_augend; i++)
+ for (i = math_opts->iopts[MIN_AUGEND]; i <= math_opts->iopts[MAX_AUGEND]; i++)
{
- for (j = math_opts->min_addend; j <= math_opts->max_addend; j++)
+ for (j = math_opts->iopts[MIN_ADDEND]; j <= math_opts->iopts[MAX_ADDEND]; j++)
{
/* check if max_answer exceeded or if question */
/* contains undesired negative values: */
if (validate_question(i, j, i + j))
{
/* put in the desired number of copies: */
- for (k = 0; k < math_opts->question_copies; k++)
+ for (k = 0; k < math_opts->iopts[QUESTION_COPIES]; k++)
{
/* put in questions in each selected format: */
@@ -2089,7 +2227,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_ADD, i + j, MC_FORMAT_ANS_LAST);
@@ -2104,7 +2242,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_ADD, i + j, MC_FORMAT_ANS_MIDDLE);
@@ -2119,7 +2257,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
@@ -2139,21 +2277,21 @@
printf("generating subtraction questions\n");
#endif
- if (math_opts->subtraction_allowed)
+ if (math_opts->iopts[SUBTRACTION_ALLOWED])
{
#ifdef MC_DEBUG
printf("\nSubtraction problems");
#endif
- for (i = math_opts->min_minuend; i <= math_opts->max_minuend; i++)
+ for (i = math_opts->iopts[MIN_MINUEND]; i <= math_opts->iopts[MAX_MINUEND]; i++)
{
- for (j = math_opts->min_subtrahend; j <= math_opts->max_subtrahend; j++)
+ for (j = math_opts->iopts[MIN_SUBTRAHEND]; j <= math_opts->iopts[MAX_SUBTRAHEND]; j++)
{
/* check if max_answer exceeded or if question */
/* contains undesired negative values: */
if (validate_question(i, j, i - j))
{
/* put in the desired number of copies: */
- for (k = 0; k < math_opts->question_copies; k++)
+ for (k = 0; k < math_opts->iopts[QUESTION_COPIES]; k++)
{
/* put in questions in each selected format: */
@@ -2162,7 +2300,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
@@ -2178,7 +2316,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
@@ -2194,7 +2332,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_SUB, i - j, MC_FORMAT_ANS_FIRST);
@@ -2213,21 +2351,21 @@
printf("generating multiplication questions\n");
#endif
- if (math_opts->multiplication_allowed)
+ if (math_opts->iopts[MULTIPLICATION_ALLOWED])
{
#ifdef MC_DEBUG
printf("\nMultiplication problems");
#endif
- for (i = math_opts->min_multiplier; i <= math_opts->max_multiplier; i++)
+ for (i = math_opts->iopts[MIN_MULTIPLIER]; i <= math_opts->iopts[MAX_MULTIPLIER]; i++)
{
- for (j = math_opts->min_multiplicand; j <= math_opts->max_multiplicand; j++)
+ for (j = math_opts->iopts[MIN_MULTIPLICAND]; j <= math_opts->iopts[MAX_MULTIPLICAND]; j++)
{
/* check if max_answer exceeded or if question */
/* contains undesired negative values: */
if (validate_question(i, j, i * j))
{
/* put in the desired number of copies: */
- for (k = 0; k < math_opts->question_copies; k++)
+ for (k = 0; k < math_opts->iopts[QUESTION_COPIES]; k++)
{
/* put in questions in each selected format: */
@@ -2236,7 +2374,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_MULT, i * j, MC_FORMAT_ANS_LAST);
@@ -2253,7 +2391,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_MULT, i * j, MC_FORMAT_ANS_MIDDLE);
@@ -2270,7 +2408,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, j, MC_OPER_MULT, i * j, MC_FORMAT_ANS_FIRST);
@@ -2289,14 +2427,14 @@
printf("generating division questions\n");
#endif
- if (math_opts->division_allowed)
+ if (math_opts->iopts[DIVISION_ALLOWED])
{
#ifdef MC_DEBUG
printf("\nDivision problems");
#endif
- for (i = math_opts->min_quotient; i <= math_opts->max_quotient; i++)
+ for (i = math_opts->iopts[MIN_QUOTIENT]; i <= math_opts->iopts[MAX_QUOTIENT]; i++)
{
- for (j = math_opts->min_divisor; j <= math_opts->max_divisor; j++)
+ for (j = math_opts->iopts[MIN_DIVISOR]; j <= math_opts->iopts[MAX_DIVISOR]; j++)
{
/* check if max_answer exceeded or if question */
/* contains undesired negative values: */
@@ -2305,7 +2443,7 @@
validate_question(i * j, j, i)) /* division problems are generated as multiplication */
{
/* put in the desired number of copies: */
- for (k = 0; k < math_opts->question_copies; k++)
+ for (k = 0; k < math_opts->iopts[QUESTION_COPIES]; k++)
{
/* put in questions in each selected format: */
@@ -2314,7 +2452,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i * j, j, MC_OPER_DIV, i, MC_FORMAT_ANS_LAST);
@@ -2330,7 +2468,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i * j, j, MC_OPER_DIV, i, MC_FORMAT_ANS_MIDDLE);
@@ -2345,7 +2483,7 @@
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i * j, j, MC_OPER_DIV, i, MC_FORMAT_ANS_FIRST);
@@ -2364,23 +2502,23 @@
printf("generating typing practice questions\n");
#endif
- if (math_opts->typing_practice_allowed)
+ if (math_opts->iopts[TYPING_PRACTICE_ALLOWED])
{
#ifdef MC_DEBUG
printf("\nTyping problems");
#endif
- for (i = math_opts->min_typing_num; i <= math_opts->max_typing_num; i++)
+ for (i = math_opts->iopts[MIN_TYPING_NUM]; i <= math_opts->iopts[MAX_TYPING_NUM]; i++)
{
/* check if max_answer exceeded or if question */
/* contains undesired negative values: */
if (validate_question(i, i, i))
{
/* put in the desired number of copies: */
- for (k = 0; k < math_opts->question_copies; k++)
+ for (k = 0; k < math_opts->iopts[QUESTION_COPIES]; k++)
{
/* make sure max_questions not exceeded, */
/* also check if question being randomly kept or discarded: */
- if ((length < math_opts->max_questions)
+ if ((length < math_opts->iopts[MAX_QUESTIONS])
&& randomly_keep())
{
tmp_ptr = create_node(i, i, MC_OPER_TYPING_PRACTICE, i, MC_FORMAT_ANS_LAST);
@@ -2398,7 +2536,7 @@
#endif
/* now shuffle list if desired: */
- if (math_opts->randomize)
+ if (math_opts->iopts[RANDOMIZE])
{
if(!randomize_list(&top_of_list))
{
@@ -2415,22 +2553,22 @@
return top_of_list;
}
+#endif
-
/* this is used by generate_list to see if a possible question */
/* meets criteria to be added to the list or not: */
int validate_question(int n1, int n2, int n3)
{
/* make sure none of values exceeds max_answer using absolute */
/* value comparison: */
- if (abs_value(n1) > abs_value(math_opts->max_answer)
- || abs_value(n2) > abs_value(math_opts->max_answer)
- || abs_value(n3) > abs_value(math_opts->max_answer))
+ if (abs_value(n1) > abs_value(math_opts->iopts[MAX_ANSWER])
+ || abs_value(n2) > abs_value(math_opts->iopts[MAX_ANSWER])
+ || abs_value(n3) > abs_value(math_opts->iopts[MAX_ANSWER]))
{
return 0;
}
/* make sure none of values are negative if negatives not allowed: */
- if (!math_opts->allow_negatives)
+ if (!math_opts->iopts[ALLOW_NEGATIVES])
{
if (n1 < 0 || n2 < 0 || n3 < 0)
{
@@ -2452,99 +2590,101 @@
fprintf(stderr, "create_node() - malloc() failed!\n");
return NULL;
}
-
+/*
ptr->card.num1 = n1;
ptr->card.num2 = n2;
ptr->card.num3 = ans;
ptr->card.operation = op;
ptr->card.format = f;
+*/
+ ptr->card = allocate_flashcard();
ptr->next = NULL;
ptr->previous = NULL;
- /* creating formula_string and answer_string is a little more work: */
- {
- char oper_char;
- /* find out correct operation character */
- switch (op)
- {
- case MC_OPER_ADD:
- {
- oper_char = '+';
- break;
- }
- case MC_OPER_SUB:
- {
- oper_char = '-';
- break;
- }
- case MC_OPER_MULT:
- {
- oper_char = '*';
- break;
- }
- case MC_OPER_DIV:
- {
- oper_char = '/';
- break;
- }
- case MC_OPER_TYPING_PRACTICE:
- {
- snprintf(ptr->card.formula_string, MC_FORMULA_LEN, "%d",ptr->card.num1);
- snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num1);
- return ptr; /* Don't need to look at formats for this case. */
- }
- default:
- {
- fprintf(stderr, "\nIn create_node(): invalid math operation\n");
- free(ptr);
- ptr = 0;
+// /* creating formula_string and answer_string is a little more work: */
+// {
+// char oper_char;
+// /* find out correct operation character */
+// switch (op)
+// {
+// case MC_OPER_ADD:
+// {
+// oper_char = '+';
+// break;
+// }
+// case MC_OPER_SUB:
+// {
+// oper_char = '-';
+// break;
+// }
+// case MC_OPER_MULT:
+// {
+// oper_char = '*';
+// break;
+// }
+// case MC_OPER_DIV:
+// {
+// oper_char = '/';
+// break;
+// }
+// case MC_OPER_TYPING_PRACTICE:
+// {
+// snprintf(ptr->card.formula_string, MC_FORMULA_LEN, "%d",ptr->card.num1);
+// snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num1);
+// return ptr; /* Don't need to look at formats for this case. */
+// }
+// default:
+// {
+// fprintf(stderr, "\nIn create_node(): invalid math operation\n");
+// free(ptr);
+// ptr = 0;
+//
+// return 0;
+// }
+// }
+//
+// switch (f) /* f is format argument */
+// {
+// case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
+// {
+// snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"%d %c %d = ?",
+// ptr->card.num1,
+// oper_char,
+// ptr->card.num2);
+// snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num3);
+// break;
+// }
+// case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
+// {
+// snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"%d %c ? = %d",
+// ptr->card.num1,
+// oper_char,
+// ptr->card.num3);
+// snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num2);
+// break;
+// }
+// case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
+// {
+// snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"? %c %d = %d",
+// oper_char,
+// ptr->card.num2,
+// ptr->card.num3);
+// snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num1);
+// break;
+// }
+// default: /* should not get to here if MathCards behaves correctly */
+// {
+// fprintf(stderr, "\ncreate_node() - invalid question format\n");
+// free(ptr);
+// ptr = 0;
+//
+//
+// return 0;
+// }
+// }
+// }
- return 0;
- }
- }
-
- switch (f) /* f is format argument */
- {
- case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
- {
- snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"%d %c %d = ?",
- ptr->card.num1,
- oper_char,
- ptr->card.num2);
- snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num3);
- break;
- }
- case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
- {
- snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"%d %c ? = %d",
- ptr->card.num1,
- oper_char,
- ptr->card.num3);
- snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num2);
- break;
- }
- case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
- {
- snprintf(ptr->card.formula_string, MC_FORMULA_LEN,"? %c %d = %d",
- oper_char,
- ptr->card.num2,
- ptr->card.num3);
- snprintf(ptr->card.answer_string, MC_ANSWER_LEN, "%d",ptr->card.num1);
- break;
- }
- default: /* should not get to here if MathCards behaves correctly */
- {
- fprintf(stderr, "\ncreate_node() - invalid question format\n");
- free(ptr);
- ptr = 0;
-
-
- return 0;
- }
- }
- }
-
/* ptr should now point to a properly constructed node: */
return ptr;
}
@@ -2555,21 +2695,17 @@
/* FIXME should properly return newly allocated list if more than one node DSB */
MC_MathQuestion* create_node_copy(MC_MathQuestion* other)
{
- return create_node(other->card.num1,
- other->card.num2,
- other->card.operation,
- other->card.num3,
- other->card.format);
+ MC_MathQuestion* ret = create_node();
+ copy_card(&other->card, &ret->card);
+ return ret;
}
#endif
MC_MathQuestion* create_node_from_card(MC_FlashCard* flashcard)
{
- return create_node(flashcard->num1,
- flashcard->num2,
- flashcard->operation,
- flashcard->num3,
- flashcard->format);
+ MC_MathQuestion* ret = allocate_node();
+ copy_card(flashcard, &ret->card);
+ return ret;
}
#ifdef MC_DEBUG
@@ -2580,12 +2716,8 @@
MC_FlashCard* fc;
if (!node)
return 0;
- fc = malloc(sizeof(MC_FlashCard));
- fc->num1 = node->card.num1;
- fc->num2 = node->card.num2;
- fc->num3 = node->card.num3;
- fc->operation = node->card.operation;
- fc->format = node->card.format;
+ fc = create_flashcard();
+ copy_card(&node->card, fc);
return fc;
}
#endif
@@ -2606,17 +2738,8 @@
return 0;
}
- copy->card.num1 = original->card.num1;
- copy->card.num2 = original->card.num2;
- copy->card.num3 = original->card.num3;
- copy->card.operation = original->card.operation;
- copy->card.format = original->card.format;
- strncpy(copy->card.formula_string,
- original->card.formula_string,
- MC_FORMULA_LEN);
- strncpy(copy->card.answer_string,
- original->card.answer_string,
- MC_ANSWER_LEN);
+ copy_card(&original->card, ©->card);
+
copy->next = original->next;
copy->previous = original->previous;
copy->randomizer = original->randomizer;
@@ -2917,10 +3040,7 @@
{
if (!first || !other)
return 0;
- if (first->card.num1 == other->card.num1
- && first->card.num2 == other->card.num2
- && first->card.operation == other->card.operation
- && first->card.format == other->card.format)
+ if (compare_card(&first->card, &first->card) ) //cards are equal
return 1;
else
return 0;
@@ -2964,7 +3084,7 @@
if (i < 0
&& math_opts
- && !math_opts->allow_negatives)
+ && !math_opts->iopts[ALLOW_NEGATIVES])
{
i = 0;
}
@@ -3024,16 +3144,26 @@
****************************************************/
/* allocate space for an MC_Flashcard */
-MC_FlashCard create_flashcard(void)
+MC_FlashCard allocate_flashcard(void)
{
- MC_FlashCard ret;
+ MC_FlashCard ret;
ret.formula_string = malloc(max_formula_size * sizeof(char));
ret.answer_string = malloc(max_answer_size * sizeof(char));
+ if (!ret.formula_string || !ret.answer_string)
+ {
+ free(ret.formula_string);
+ free(ret.answer_string);
+ printf("Couldn't allocate space for a new flashcard!\n");
+ ret = DEFAULT_CARD;
+ }
+ return ret;
}
-void free_flashcard(MC_FlashCard* fc)
+void free_flashcard(MC_FlashCard fc)
{
- free(fc->formula_string);
- free(fc->answer_string);
+ if (fc.formula_string)
+ free(fc.formula_string);
+ if (fc.answer_string)
+ free(fc.answer_string);
}
void copy_card(const MC_FlashCard* src, MC_FlashCard* dest)
@@ -3042,6 +3172,54 @@
strncpy(src->answer_string, dest->answer_string, max_answer_size);
dest->answer = src->answer;
}
+
+void free_node(MC_MathQuestion* mq) //no, not that freenode.
+{
+ if (!mq)
+ return;
+ free_flashcard(mq->card);
+ free(mq);
+}
+
+MC_MathQuestion* allocate_node()
+{
+ MC_MathQuestion* ret = NULL;
+ ret = malloc(sizeof(MC_MathQuestion) );
+ if (!ret)
+ printf("Could not allocate space for a new node!\n");
+ else
+ ret->card = allocate_flashcard();
+ return ret;
+}
+
+MC_FlashCard generate_random_flashcard()
+{
+ MC_FlashCard ret = allocate_flashcard();
+
+ return ret;
+}
+
+MC_MathQuestion* generate_list(void)
+{
+ MC_MathQuestion* list = NULL;
+
+ return list;
+}
+
+static int compare_card(const MC_FlashCard* a, const MC_FlashCard* b)
+{
+ if (strncmp(a->formula_string, b->formula_string, max_formula_size) )
+ return 1;
+ if (strncmp(a->answer_string, b->answer_string, max_answer_size) )
+ return 1;
+ if (a->answer != b->answer);
+ return 1;
+
+ return 0; //the cards are identical
+}
+
+//Begin public functions
+
unsigned int MC_MapTextToIndex(const char* text)
{
int i;
@@ -3059,10 +3237,10 @@
printf("Invalid option index: %du\n", index);
return;
}
- opts.iopts[index] = val;
+ math_opts->iopts[index] = val;
}
-void MC_SetOpt(const char* param, int val)
+void MC_SetOp(const char* param, int val)
{
MC_SetOpt(MC_MapTextToIndex(param), val);
}
@@ -3074,27 +3252,27 @@
printf("Invalid option index: %du\n", index);
return MC_MATH_OPTS_INVALID;
}
- if (!opts)
+ if (!math_opts)
{
printf("Invalid options list!\n");
return MC_MATH_OPTS_INVALID;
}
- return opts->iopts[index];
+ return math_opts->iopts[index];
}
-int MC_GetOpt(const char* param)
+int MC_GetOp(const char* param)
{
return MC_GetOpt(MC_MapTextToIndex(param) );
}
void MC_SetFractionToKeep(float val)
{
- opts->fraction_to_keep = val;
+ math_opts->fraction_to_keep = val;
}
float MC_GetFractionToKeep(void)
{
- return opts->fraction_to_keep;
+ return math_opts->fraction_to_keep;
}
int MC_VerifyOptionListSane(void)
@@ -3102,4 +3280,14 @@
return MC_OPTION_TEXT[NOPTS] == "END_OF_OPTS";
}
+int MC_MaxFormulaSize(void)
+{
+ return max_formula_size;
+}
+
+int MC_MaxAnswerSize(void)
+{
+ return max_answer_size;
+}
+
#endif
Modified: tuxmath/branches/mathcards_newarch/src/mathcards.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/mathcards.h 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/mathcards.h 2008-06-24 01:21:32 UTC (rev 551)
@@ -28,13 +28,13 @@
#define MC_USE_NEWARC
/* type of math operation used in a given question */
-enum {
- MC_OPER_ADD,
- MC_OPER_SUB,
- MC_OPER_MULT,
- MC_OPER_DIV,
- MC_OPER_TYPING_PRACTICE,
- MC_NUM_OPERS
+enum MC_Operation {
+ MC_OPER_ADD = '+',
+ MC_OPER_SUB = '-',
+ MC_OPER_MULT = '*',
+ MC_OPER_DIV = '/',
+ MC_OPER_TYPING_PRACTICE = 'P',
+ MC_NUM_OPERS = 5
};
/* math question formats: */
@@ -48,11 +48,12 @@
/*
Indices for the various integer options. These are NOT the actual values!
Actual values are accessed as such: options.iopts[PLAY_THROUGH_LIST] = val;
-Creating additional [integral] options is now centralized--this should be
-the only place where it's necessary to add code. (Besides actually using
-the new options!)
+Creating additional [integral] options is now centralized--it should only
+be necessary to add to this list, the list of text, and the list of
+defaults. (Besides actually using the new options!)
*/
+#define NOT_VALID_OPTION -1
#define PLAY_THROUGH_LIST 0 /* play until all questions answered correctly */
#define REPEAT_WRONGS 1 /* reuse incorrectly answered questions or not */
#define COPIES_REPEATED_WRONGS 2 /* how many copies of an incorrectly answered question to re-insert*/
@@ -112,133 +113,16 @@
#define NOPTS 48
-const char const** MC_OPTION_TEXT = {
-"PLAY_THROUGH_LIST",
-"REPEAT_WRONGS",
-"COPIES_REPEATED_WRONGS",
-"ALLOW_NEGATIVES",
-"MAX_ANSWER",
-"MAX_QUESTIONS",
-"QUESTION_COPIES",
-"MAX_FORMULA_NUMS",
-"MIN_FORMULA_NUMS",
-
-"FORMAT_ANSWER_LAST",
-"FORMAT_ANSWER_FIRST",
-"FORMAT_ANSWER_MIDDLE",
-"FORMAT_ADD_ANSWER_LAST",
-"FORMAT_ADD_ANSWER_FIRST",
-"FORMAT_ADD_ANSWER_MIDDLE",
-"FORMAT_SUB_ANSWER_LAST",
-"FORMAT_SUB_ANSWER_FIRST",
-"FORMAT_SUB_ANSWER_MIDDLE",
-"FORMAT_MULT_ANSWER_LAST",
-"FORMAT_MULT_ANSWER_FIRST",
-"FORMAT_MULT_ANSWER_MIDDLE",
-"FORMAT_DIV_ANSWER_LAST",
-"FORMAT_DIV_ANSWER_FIRST",
-"FORMAT_DIV_ANSWER_MIDDLE",
-
-"ADDITION_ALLOWED",
-"SUBTRACTION_ALLOWED",
-"MULTIPLICATION_ALLOWED",
-"DIVISION_ALLOWED",
-"TYPING_PRACTICE_ALLOWED",
-
-"MIN_AUGEND",
-"MAX_AUGEND",
-"MIN_ADDEND",
-"MAX_ADDEND",
-
-"MIN_MINUEND",
-"MAX_MINUEND",
-"MIN_SUBTRAHEND",
-"MAX_SUBTRAHEND",
-
-"MIN_MULTIPLIER",
-"MAX_MULTIPLIER",
-"MIN_MULTIPLICAND",
-"MAX_MULTIPLICAND",
-
-"MIN_DIVISOR",
-"MAX_DIVISOR",
-"MIN_QUOTIENT",
-"MAX_QUOTIENT",
-
-"MIN_TYPING_NUM",
-"MAX_TYPING_NUM",
-
-"RANDOMIZE",
-
-"END_OF_OPTS"
-};
-
+extern const char* const MC_OPTION_TEXT[];
+extern const int MC_DEFAULTS[];
/* default values for math_options */
#define MC_GLOBAL_MAX 999 /* This is the largest absolute value that */
/* can be entered for math question values.*/
#define MC_MATH_OPTS_INVALID -9999 /* Return value for accessor functions */
/* if math_opts not valid */
#define DEFAULT_FRACTION_TO_KEEP 1
-
-const int* MC_DEFAULTS = {
- 1, //PLAY_THROUGH_LIST
- 1, //REPEAT_WRONGS
- 1, //COPIES_REPEATED_WRONGS
- 0, //ALLOW_NEGATIVES
- 999, //MAX_ANSWER
- 5000, //MAX_QUESTIONS
- 1, //QUESTION_COPIES
- 2, //MAX_FORMULA_NUMS
- 5, //MIN_FORMULA_NUMS
- //
- 1, //FORMAT_ANSWER_LAST
- 0, //FORMAT_ANSWER_FIRST
- 0, //FORMAT_ANSWER_MIDDLE
- 1, //FORMAT_ADD_ANSWER_LAST
- 0, //FORMAT_ADD_ANSWER_FIRST
- 0, //FORMAT_ADD_ANSWER_MIDDLE
- 1, //FORMAT_SUB_ANSWER_LAST
- 0, //FORMAT_SUB_ANSWER_FIRST
- 0, //FORMAT_SUB_ANSWER_MIDDLE
- 1, //FORMAT_MULT_ANSWER_LAST
- 0, //FORMAT_MULT_ANSWER_FIRST
- 0, //FORMAT_MULT_ANSWER_MIDDLE
- 1, //FORMAT_DIV_ANSWER_LAST
- 0, //FORMAT_DIV_ANSWER_FIRST
- 0, //FORMAT_DIV_ANSWER_MIDDLE
- //
- 1, //ADDITION_ALLOWED
- 1, //SUBTRACTION_ALLOWED
- 1, //MULTIPLICATION_ALLOWED
- 1, //DIVISION_ALLOWED
- 0, //TYPING_PRACTICE_ALLOWED
- //
- 0, //MIN_AUGEND
- 12, //MAX_AUGEND
- 0, //MIN_ADDEND
- 12, //MAX_ADDEND
- //
- 0, //MIN_MINUEND
- 12, //MAX_MINUEND
- 0, //MIN_SUBTRAHEND
- 12, //MAX_SUBTRAHEND
- //
- 0, //MIN_MULTIPLIER
- 12, //MAX_MULTIPLIER
- 0, //MIN_MULTIPLICAND
- 12, //MAX_MULTIPLICAND
- //
- 0, //MIN_DIVISOR
- 12, //MAX_DIVISOR
- 0, //MIN_QUOTIENT
- 12, //MAX_QUOTIENT
- //
- 0, //MIN_TYPING_NUM
- 12, //MAX_TYPING_NUM
- //
- 1 //RANDOMIZE
-};
+
#ifndef MC_USE_NEWARC
/* This struct contains all options that determine what */
/* math questions are asked during a game */
@@ -325,6 +209,7 @@
char* formula_string;
char* answer_string;
int answer;
+ int difficulty;
} MC_FlashCard;
#endif
@@ -581,5 +466,7 @@
void MC_SetFractionToKeep(float val);
float MC_GetFractionToKeep(void);
int MC_VerifyOptionListSane(void);
+int MC_MaxFormulaSize(void);
+int MC_MaxAnswerSize(void);
#endif
Modified: tuxmath/branches/mathcards_newarch/src/setup.c
===================================================================
--- tuxmath/branches/mathcards_newarch/src/setup.c 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/setup.c 2008-06-24 01:21:32 UTC (rev 551)
@@ -361,24 +361,24 @@
else if (strcmp(argv[i], "--allownegatives") == 0 ||
strcmp(argv[i], "-n") == 0)
{
- MC_SetAllowNegatives(1);
+ MC_SetOpt(ALLOW_NEGATIVES, 1);
}
else if (strcmp(argv[i], "--playthroughlist") == 0 ||
strcmp(argv[i], "-l") == 0)
{
- MC_SetPlayThroughList(1);
+ MC_SetOpt(PLAY_THROUGH_LIST, 1);
}
else if (strcmp(argv[i], "--answersfirst") == 0)
{
- MC_SetFormatAnswerLast(0);
- MC_SetFormatAnswerFirst(1);
- MC_SetFormatAnswerMiddle(0);
+ MC_SetOpt(FORMAT_ANSWER_LAST, 0);
+ MC_SetOpt(FORMAT_ANSWER_FIRST, 1);
+ MC_SetOpt(FORMAT_ANSWER_MIDDLE, 0);
}
else if (strcmp(argv[i], "--answersmiddle") == 0)
{
- MC_SetFormatAnswerLast(0);
- MC_SetFormatAnswerFirst(0);
- MC_SetFormatAnswerMiddle(1);
+ MC_SetOpt(FORMAT_ANSWER_LAST, 0);
+ MC_SetOpt(FORMAT_ANSWER_FIRST, 0);
+ MC_SetOpt(FORMAT_ANSWER_MIDDLE, 1);
}
else if (strcmp(argv[i], "--speed") == 0 ||
strcmp(argv[i], "-s") == 0)
Modified: tuxmath/branches/mathcards_newarch/src/titlescreen.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/titlescreen.h 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/titlescreen.h 2008-06-24 01:21:32 UTC (rev 551)
@@ -44,7 +44,7 @@
#include "SDL_ttf.h"
#ifndef MACOSX
-#include "config.h"
+//#include "config.h"
#endif
#include "tuxmath.h"
Modified: tuxmath/branches/mathcards_newarch/src/tuxmath.h
===================================================================
--- tuxmath/branches/mathcards_newarch/src/tuxmath.h 2008-06-23 16:46:05 UTC (rev 550)
+++ tuxmath/branches/mathcards_newarch/src/tuxmath.h 2008-06-24 01:21:32 UTC (rev 551)
@@ -22,7 +22,7 @@
#ifndef TUXMATH_H
#define TUXMATH_H
-#include "config.h"
+//#include "config.h"
// Translation stuff (now works for Mac and Win too!):
#include "gettext.h"
More information about the Tux4kids-commits
mailing list