00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include <stdio.h>
00011 #include "FCPresets.h"
00012
00013 const FCSPresetName FCSPresetNames[23] =
00014 {
00015 {
00016 "bakers_dozen",
00017 FCS_PRESET_BAKERS_DOZEN,
00018 },
00019 {
00020 "bakers_game",
00021 FCS_PRESET_BAKERS_GAME,
00022 },
00023 {
00024 "beleaguered_castle",
00025 FCS_PRESET_BELEAGUERED_CASTLE,
00026 },
00027 {
00028 "citadel",
00029 FCS_PRESET_BELEAGUERED_CASTLE,
00030 },
00031 {
00032 "cruel",
00033 FCS_PRESET_CRUEL,
00034 },
00035 {
00036 "der_katzenschwanz",
00037 FCS_PRESET_DER_KATZENSCHWANZ,
00038 },
00039 {
00040 "der_katz",
00041 FCS_PRESET_DER_KATZENSCHWANZ,
00042 },
00043 {
00044 "die_schlange",
00045 FCS_PRESET_DIE_SCHLANGE,
00046 },
00047 {
00048 "eight_off",
00049 FCS_PRESET_EIGHT_OFF,
00050 },
00051 {
00052 "forecell",
00053 FCS_PRESET_FORECELL,
00054 },
00055 {
00056 "freecell",
00057 FCS_PRESET_FREECELL,
00058 },
00059 {
00060 "good_measure",
00061 FCS_PRESET_GOOD_MEASURE,
00062 },
00063 {
00064 "klondike",
00065 FCS_PRESET_KLONDIKE,
00066 },
00067 {
00068 "kings_only_bakers_game",
00069 FCS_PRESET_KINGS_ONLY_BAKERS_GAME,
00070 },
00071 {
00072 "ko_bakers_game",
00073 FCS_PRESET_KINGS_ONLY_BAKERS_GAME,
00074 },
00075 {
00076 "relaxed_freecell",
00077 FCS_PRESET_RELAXED_FREECELL,
00078 },
00079 {
00080 "relaxed_seahaven_towers",
00081 FCS_PRESET_RELAXED_SEAHAVEN_TOWERS,
00082 },
00083 {
00084 "relaxed_seahaven",
00085 FCS_PRESET_RELAXED_SEAHAVEN_TOWERS,
00086 },
00087 {
00088 "seahaven_towers",
00089 FCS_PRESET_SEAHAVEN_TOWERS,
00090 },
00091 {
00092 "seahaven",
00093 FCS_PRESET_SEAHAVEN_TOWERS,
00094 },
00095 {
00096 "simple_simon",
00097 FCS_PRESET_SIMPLE_SIMON,
00098 },
00099 {
00100 "streets_and_alleys",
00101 FCS_PRESET_BELEAGUERED_CASTLE,
00102 },
00103 {
00104 "yukon",
00105 FCS_PRESET_YUKON,
00106 },
00107 };
00108
00110 static const FCSPreset FCSPresets[16] =
00111 {
00112 {
00113 FCS_PRESET_BAKERS_DOZEN,
00114 0,
00115 13,
00116 1,
00117
00118 FCS_SEQ_BUILT_BY_RANK,
00119 0,
00120 FCS_ES_FILLED_BY_NONE,
00121 FCS_TALON_NONE,
00122 "0123456789",
00123 },
00124 {
00125 FCS_PRESET_BAKERS_GAME,
00126 4,
00127 8,
00128 1,
00129
00130 FCS_SEQ_BUILT_BY_SUIT,
00131 0,
00132 FCS_ES_FILLED_BY_ANY_CARD,
00133 FCS_TALON_NONE,
00134 "[01][23456789]",
00135 },
00136 {
00137 FCS_PRESET_BELEAGUERED_CASTLE,
00138 0,
00139 8,
00140 1,
00141
00142 FCS_SEQ_BUILT_BY_RANK,
00143 0,
00144 FCS_ES_FILLED_BY_ANY_CARD,
00145 FCS_TALON_NONE,
00146 "[01][23456789]",
00147 },
00148 {
00149 FCS_PRESET_CRUEL,
00150 0,
00151 12,
00152 1,
00153
00154 FCS_SEQ_BUILT_BY_SUIT,
00155 0,
00156 FCS_ES_FILLED_BY_NONE,
00157 FCS_TALON_NONE,
00158 "0123456789",
00159 },
00160 {
00161 FCS_PRESET_DER_KATZENSCHWANZ,
00162 8,
00163 9,
00164 2,
00165
00166 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00167 1,
00168 FCS_ES_FILLED_BY_NONE,
00169 FCS_TALON_NONE,
00170 "[01][23456789]",
00171 },
00172 {
00173 FCS_PRESET_DIE_SCHLANGE,
00174 8,
00175 9,
00176 2,
00177
00178 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00179 0,
00180 FCS_ES_FILLED_BY_NONE,
00181 FCS_TALON_NONE,
00182 "[01][23456789]",
00183 },
00184 {
00185 FCS_PRESET_EIGHT_OFF,
00186 8,
00187 8,
00188 1,
00189
00190 FCS_SEQ_BUILT_BY_SUIT,
00191 0,
00192 FCS_ES_FILLED_BY_KINGS_ONLY,
00193 FCS_TALON_NONE,
00194 "[01][23456789]",
00195 },
00196 {
00197 FCS_PRESET_FORECELL,
00198 4,
00199 8,
00200 1,
00201
00202 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00203 0,
00204 FCS_ES_FILLED_BY_KINGS_ONLY,
00205 FCS_TALON_NONE,
00206 "[01][23456789]",
00207 },
00208 {
00209 FCS_PRESET_FREECELL,
00210 4,
00211 8,
00212 1,
00213
00214 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00215 0,
00216 FCS_ES_FILLED_BY_ANY_CARD,
00217 FCS_TALON_NONE,
00218 "[01][23456789]",
00219 },
00220 {
00221 FCS_PRESET_GOOD_MEASURE,
00222 0,
00223 10,
00224 1,
00225
00226 FCS_SEQ_BUILT_BY_RANK,
00227 0,
00228 FCS_ES_FILLED_BY_NONE,
00229 FCS_TALON_NONE,
00230 "0123456789",
00231 },
00232 {
00233 FCS_PRESET_KINGS_ONLY_BAKERS_GAME,
00234 4,
00235 8,
00236 1,
00237
00238 FCS_SEQ_BUILT_BY_SUIT,
00239 0,
00240 FCS_ES_FILLED_BY_KINGS_ONLY,
00241 FCS_TALON_NONE,
00242 "[01][23456789]",
00243 },
00244 {
00245 FCS_PRESET_KLONDIKE,
00246 0,
00247 7,
00248 1,
00249
00250 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00251 1,
00252 FCS_ES_FILLED_BY_KINGS_ONLY,
00253 FCS_TALON_KLONDIKE,
00254 "[0123456]",
00255 },
00256 {
00257 FCS_PRESET_RELAXED_FREECELL,
00258 4,
00259 8,
00260 1,
00261
00262 FCS_SEQ_BUILT_BY_ALTERNATE_COLOR,
00263 1,
00264 FCS_ES_FILLED_BY_ANY_CARD,
00265 FCS_TALON_NONE,
00266 "[01][23456789]",
00267 },
00268 {
00269 FCS_PRESET_RELAXED_SEAHAVEN_TOWERS,
00270 4,
00271 10,
00272 1,
00273
00274 FCS_SEQ_BUILT_BY_SUIT,
00275 1,
00276 FCS_ES_FILLED_BY_KINGS_ONLY,
00277 FCS_TALON_NONE,
00278 "[01][23456789]",
00279 },
00280 {
00281 FCS_PRESET_SEAHAVEN_TOWERS,
00282 4,
00283 10,
00284 1,
00285
00286 FCS_SEQ_BUILT_BY_SUIT,
00287 0,
00288 FCS_ES_FILLED_BY_KINGS_ONLY,
00289 FCS_TALON_NONE,
00290 "[01][23456789]",
00291 },
00292 {
00293 FCS_PRESET_SIMPLE_SIMON,
00294 0,
00295 10,
00296 1,
00297
00298 FCS_SEQ_BUILT_BY_SUIT,
00299 0,
00300 FCS_ES_FILLED_BY_ANY_CARD,
00301 FCS_TALON_NONE,
00302 "012345678",
00303 }
00304 };
00305
00306 FCSPresetID FCSPresetName::GetPresetID(const char* Name)
00307 {
00308 int NumberOfElements = sizeof(FCSPresetNames)/sizeof(FCSPresetName);
00309
00310 for(int a=0;a<NumberOfElements;a++)
00311 if (!strcmp(Name, FCSPresetNames[a].m_Name))
00312 return FCSPresetNames[a].m_PresetID;
00313
00314 return FCS_PRESET_NONE;
00315 }
00316
00317 FCSPreset* FCSPreset::GetPresetInfo(const char* Name)
00318 {
00319 FCSPresetID PresetID = FCSPresetName::GetPresetID(Name);
00320 if (PresetID >= 0)
00321 {
00322 FCSPreset* Preset = new FCSPreset();
00323 Preset->ApplyPresetID(PresetID);
00324 return Preset;
00325 }
00326
00327 return NULL;
00328 }
00329
00330 void FCSPreset::ApplyPresetID(FCSPresetID Id)
00331 {
00332 int NumberOfElements = sizeof(FCSPresets)/sizeof(FCSPreset);
00333
00334 for(int PresetIndex=0; PresetIndex < NumberOfElements ; PresetIndex++)
00335 {
00336 if (FCSPresets[PresetIndex].m_PresetID == Id)
00337 {
00338 m_NumberOfFreecells = FCSPresets[PresetIndex].m_NumberOfFreecells;
00339 m_NumberOfStacks = FCSPresets[PresetIndex].m_NumberOfStacks;
00340 m_NumberOfDecks = FCSPresets[PresetIndex].m_NumberOfDecks;
00341 m_SequencesAreBuiltBy = FCSPresets[PresetIndex].m_SequencesAreBuiltBy;
00342 m_UnlimitedSequenceMove = FCSPresets[PresetIndex].m_UnlimitedSequenceMove;
00343 m_EmptyStacksFill = FCSPresets[PresetIndex].m_EmptyStacksFill;
00344 m_TalonType = FCSPresets[PresetIndex].m_TalonType;
00345 strcpy(m_TestOrder, FCSPresets[PresetIndex].m_TestOrder);
00346 }
00347 }
00348 }
00349
00350 int FCSApplyTestOrder(int* TestOrderArray, const char* TestOrderString,
00351 int* TestOrderCount, char* GameName, char** ErrorString)
00352 {
00353 int Length = strlen(TestOrderString),
00354 TestIndex = 0,
00355 TestsOrder[FCS_TESTS_NUM],
00356 a;
00357
00358 bool IsGroup = false,
00359 IsStartGroup = false;
00360
00361
00362 char* LocalErrorString = new char[50];
00363
00364
00365
00366 for(a=0;a<Length;a++)
00367 {
00368 if ((TestOrderString[a] == '(') || (TestOrderString[a] == '['))
00369 {
00370 if (IsGroup)
00371 {
00372 strcpy(LocalErrorString, "There's a nested random group.");
00373 *ErrorString = LocalErrorString;
00374 return 1;
00375 }
00376
00377 IsGroup = true;
00378 IsStartGroup = true;
00379 continue;
00380 }
00381
00382 if ((TestOrderString[a] == ')') || (TestOrderString[a] == ']'))
00383 {
00384 if (IsStartGroup)
00385 {
00386 strcpy(LocalErrorString,"There's an empty group.");
00387 *ErrorString = LocalErrorString;
00388 return 2;
00389 }
00390 if (!IsGroup)
00391 {
00392 strcpy(LocalErrorString, "There's a renegade right parenthesis or bracket.");
00393 *ErrorString = LocalErrorString;
00394 return 3;
00395 }
00396 IsGroup = false;
00397 IsStartGroup = false;
00398 continue;
00399 }
00400
00401
00402 bool TestOrderError = false;
00403 if (!strcmp(GameName, "simple_simon"))
00404 {
00405 if ((TestOrderString[a] < '0') || (TestOrderString[a] > '8'))
00406 TestOrderError = true;
00407 }
00408 else if (!strcmp(GameName, "klondike"))
00409 {
00410 if ((TestOrderString[a] < '0') || (TestOrderString[a] > '6'))
00411 TestOrderError = true;
00412 }
00413 else
00414 {
00415 if ((TestOrderString[a] < '0') || (TestOrderString[a] > '9'))
00416 TestOrderError = true;
00417 }
00418
00419 if (TestOrderError)
00420 {
00421 sprintf(LocalErrorString, "'%c' is not a valid --test-order value.", TestOrderString[a]);
00422 *ErrorString = LocalErrorString;
00423 return 4;
00424 }
00425
00426 if (TestIndex < FCS_TESTS_NUM)
00427 TestsOrder[TestIndex++] = ((TestOrderString[a]-'0')%FCS_TESTS_NUM) | (IsGroup ? FCS_TEST_ORDER_FLAG_RANDOM : 0) | (IsStartGroup ? FCS_TEST_ORDER_FLAG_START_RANDOM_GROUP : 0);
00428
00429 IsStartGroup = false;
00430 }
00431
00432 if (a != Length)
00433 {
00434 sprintf(LocalErrorString, "The number of tests exceeds the maximum of %i.\n Recomile the program if you wish to have more", FCS_TESTS_NUM);
00435 *ErrorString = LocalErrorString;
00436 return 5;
00437 }
00438
00439 *TestOrderCount = TestIndex;
00440 memcpy(TestOrderArray, TestsOrder, sizeof(int)*TestIndex);
00441 delete [] LocalErrorString;
00442 *ErrorString = NULL;
00443
00444 return 0;
00445 }
00446