00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include "AFreecellGameBoard.h"
00013 #include "PysolGameBoards.h"
00014 #include "MiscFreecellGameBoards.h"
00015
00017 const BoardName AllBoardNames[50] =
00018 {
00019 {
00020 "bakers_dozen",
00021 BOARD_ID_BAKERS_DOZEN,
00022 },
00023 {
00024 "bakers_game",
00025 BOARD_ID_BAKERS_GAME,
00026 },
00027 {
00028 "beleaguered_castle",
00029 BOARD_ID_BELEAGUERED_CASTLE,
00030 },
00031 {
00032 "casino_klondike",
00033 BOARD_ID_KLONDIKE,
00034 },
00035 {
00036 "citadel",
00037 BOARD_ID_CITADEL,
00038 },
00039 {
00040 "cruel",
00041 BOARD_ID_CRUEL,
00042 },
00043 {
00044 "der_katzenschwanz",
00045 BOARD_ID_DER_KATZENSCHWANZ,
00046 },
00047 {
00048 "der_katz",
00049 BOARD_ID_DER_KATZENSCHWANZ,
00050 },
00051 {
00052 "die_schlange",
00053 BOARD_ID_DIE_SCHLANGE,
00054 },
00055 {
00056 "eight_off",
00057 BOARD_ID_EIGHT_OFF,
00058 },
00059 {
00060 "fan",
00061 BOARD_ID_FAN,
00062 },
00063 {
00064 "forecell",
00065 BOARD_ID_FORECELL,
00066 },
00067 {
00068 "freecell",
00069 BOARD_ID_FREECELL,
00070 },
00071 {
00072 "gnome_freecell",
00073 BOARD_ID_GNOME_FREECELL,
00074 },
00075 {
00076 "good_measure",
00077 BOARD_ID_GOOD_MEASURE,
00078 },
00079 {
00080 "gypsy",
00081 BOARD_ID_GYPSY,
00082 },
00083 {
00084 "kings_only_bakers_game",
00085 BOARD_ID_KINGS_ONLY_BAKERS_GAME,
00086 },
00087 {
00088 "klondike",
00089 BOARD_ID_KLONDIKE,
00090 },
00091 {
00092 "klondike_by_threes",
00093 BOARD_ID_KLONDIKE,
00094 },
00095 {
00096 "ko_bakers_game",
00097 BOARD_ID_KINGS_ONLY_BAKERS_GAME,
00098 },
00099 {
00100 "microsoft_freecell",
00101 BOARD_ID_MICROSOFT_FREECELL,
00102 },
00103 {
00104 "pysol_bakers_game",
00105 BOARD_ID_PYSOL_BAKERS_GAME,
00106 },
00107 {
00108 "pysol_beleaguered_castle",
00109 BOARD_ID_PYSOL_BELEAGUERED_CASTLE,
00110 },
00111 {
00112 "pysol_casino_klondike",
00113 BOARD_ID_PYSOL_KLONDIKE,
00114 },
00115 {
00116 "pysol_eight_off",
00117 BOARD_ID_PYSOL_EIGHT_OFF,
00118 },
00119 {
00120 "pysol_freecell",
00121 BOARD_ID_PYSOL_FREECELL,
00122 },
00123 {
00124 "pysol_kings_only_bakers_game",
00125 BOARD_ID_PYSOL_KINGS_ONLY_BAKERS_GAME,
00126 },
00127 {
00128 "pysol_klondike",
00129 BOARD_ID_PYSOL_KLONDIKE,
00130 },
00131 {
00132 "pysol_klondike_by_threes",
00133 BOARD_ID_PYSOL_KLONDIKE,
00134 },
00135 {
00136 "pysol_ko_bakers_game",
00137 BOARD_ID_PYSOL_KINGS_ONLY_BAKERS_GAME,
00138 },
00139 {
00140 "pysol_relaxed_freecell",
00141 BOARD_ID_PYSOL_RELAXED_FREECELL,
00142 },
00143 {
00144 "pysol_relaxed_seahaven",
00145 BOARD_ID_PYSOL_RELAXED_SEAHAVEN_TOWERS,
00146 },
00147 {
00148 "pysol_relaxed_seahaven_towers",
00149 BOARD_ID_PYSOL_RELAXED_SEAHAVEN_TOWERS,
00150 },
00151 {
00152 "pysol_seahaven",
00153 BOARD_ID_PYSOL_SEAHAVEN_TOWERS,
00154 },
00155 {
00156 "pysol_seahaven_towers",
00157 BOARD_ID_PYSOL_SEAHAVEN_TOWERS,
00158 },
00159 {
00160 "pysol_streets_and_alleys",
00161 BOARD_ID_PYSOL_STREETS_AND_ALLEYS,
00162 },
00163 {
00164 "pysol_thumb_and_pouch",
00165 BOARD_ID_PYSOL_KLONDIKE,
00166 },
00167 {
00168 "pysol_vegas_klondike",
00169 BOARD_ID_PYSOL_KLONDIKE,
00170 },
00171 {
00172 "relaxed_freecell",
00173 BOARD_ID_RELAXED_FREECELL,
00174 },
00175 {
00176 "relaxed_seahaven_towers",
00177 BOARD_ID_RELAXED_SEAHAVEN_TOWERS,
00178 },
00179 {
00180 "relaxed_seahaven",
00181 BOARD_ID_RELAXED_SEAHAVEN_TOWERS,
00182 },
00183 {
00184 "seahaven_towers",
00185 BOARD_ID_SEAHAVEN_TOWERS,
00186 },
00187 {
00188 "simple_simon",
00189 BOARD_ID_SIMPLE_SIMON,
00190 },
00191 {
00192 "small_harp",
00193 BOARD_ID_SMALL_HARP,
00194 },
00195 {
00196 "streets_and_alleys",
00197 BOARD_ID_STREETS_AND_ALLEYS,
00198 },
00199 {
00200 "thumb_and_pouch",
00201 BOARD_ID_KLONDIKE,
00202 },
00203 {
00204 "vegas_klondike",
00205 BOARD_ID_KLONDIKE,
00206 },
00207 {
00208 "yukon",
00209 BOARD_ID_YUKON,
00210 },
00211 {
00212 "whitehead",
00213 BOARD_ID_WHITEHEAD,
00214 }
00215
00216 };
00217
00222 BoardID GetBoardID(const char* Name)
00223 {
00224 int NumberOfElements = sizeof(AllBoardNames)/sizeof(BoardName);
00225
00226 for(int a=0;a<NumberOfElements;a++)
00227 if (!strcmp(Name, AllBoardNames[a].m_Name))
00228 return AllBoardNames[a].m_BoardID;
00229
00230 return BOARD_ID_NONE;
00231 }
00232
00233 AFreecellGameBoard* CreateAFreecellGameBoard(char* GameName, bool Display10AsT)
00234 {
00235 switch(GetBoardID(GameName))
00236 {
00237 case BOARD_ID_CRUEL:
00238 case BOARD_ID_GOOD_MEASURE:
00239 return NULL;
00240 case BOARD_ID_BAKERS_DOZEN:
00241 return new PysolBakersDozenGameBoard(Display10AsT);
00242 case BOARD_ID_BELEAGUERED_CASTLE:
00243 return new AisleRiotBeleagueredCastleGameBoard(Display10AsT);
00244 case BOARD_ID_CITADEL:
00245 return new PysolCitadelGameBoard(Display10AsT);
00246 case BOARD_ID_DIE_SCHLANGE:
00247 return new PysolDieSchlangeGameBoard(Display10AsT);
00248 case BOARD_ID_DER_KATZENSCHWANZ:
00249 return new PysolDerKatzenschwantzGameBoard(Display10AsT);
00250 case BOARD_ID_EIGHT_OFF:
00251 return new AisleRiotEightOffGameBoard(Display10AsT);
00252 case BOARD_ID_FAN:
00253 return new PysolFanGameBoard(Display10AsT);
00254 case BOARD_ID_FORECELL:
00255 return new PysolForecellGameBoard(Display10AsT);
00256 case BOARD_ID_FREECELL:
00257 case BOARD_ID_BAKERS_GAME:
00258 case BOARD_ID_KINGS_ONLY_BAKERS_GAME:
00259 case BOARD_ID_RELAXED_FREECELL:
00260 case BOARD_ID_STREETS_AND_ALLEYS:
00261 return new AisleRiotFreecellGameBoard(Display10AsT);
00262 case BOARD_ID_GNOME_FREECELL:
00263 return new GnomeFreecellGameBoard(Display10AsT);
00264 case BOARD_ID_GYPSY:
00265 return new PysolGypsyGameBoard(Display10AsT);
00266 case BOARD_ID_KLONDIKE:
00267 return new AisleRiotKlondikeGameBoard(Display10AsT);
00268 case BOARD_ID_MICROSOFT_FREECELL:
00269 return new MicrosoftFreecellGameBoard(Display10AsT);
00270 case BOARD_ID_PYSOL_BELEAGUERED_CASTLE:
00271 return new PysolBeleagueredCastleGameBoard(Display10AsT);
00272 case BOARD_ID_PYSOL_EIGHT_OFF:
00273 return new PysolEightOffGameBoard(Display10AsT);
00274 case BOARD_ID_PYSOL_FREECELL:
00275 case BOARD_ID_PYSOL_BAKERS_GAME:
00276 case BOARD_ID_PYSOL_KINGS_ONLY_BAKERS_GAME:
00277 case BOARD_ID_PYSOL_RELAXED_FREECELL:
00278 case BOARD_ID_PYSOL_STREETS_AND_ALLEYS:
00279 return new PysolFreecellGameBoard(Display10AsT);
00280 case BOARD_ID_PYSOL_KLONDIKE:
00281 return new PysolKlondikeGameBoard(Display10AsT);
00282 case BOARD_ID_PYSOL_RELAXED_SEAHAVEN_TOWERS:
00283 case BOARD_ID_PYSOL_SEAHAVEN_TOWERS:
00284 return new PysolSeahavenTowersGameBoard(Display10AsT);
00285 case BOARD_ID_SEAHAVEN_TOWERS:
00286 case BOARD_ID_RELAXED_SEAHAVEN_TOWERS:
00287 return new AisleRiotSeahavenTowersGameBoard(Display10AsT);
00288 case BOARD_ID_SIMPLE_SIMON:
00289 return new PysolSimpleSimonGameBoard(Display10AsT);
00290 case BOARD_ID_SMALL_HARP:
00291 return new PysolSmallHarpGameBoard(Display10AsT);
00292 case BOARD_ID_WHITEHEAD:
00293 return new PysolWhiteheadGameBoard(Display10AsT);
00294 case BOARD_ID_YUKON:
00295 return new PysolYukonGameBoard(Display10AsT);
00296 case BOARD_ID_NONE:
00297 default:
00298 return NULL;
00299 }
00300
00301 return NULL;
00302 }
00303
00304 AFreecellGameBoard::AFreecellGameBoard(bool Display10AsT)
00305 {
00306
00307 m_Deck = new char[GetNumberOfCardsInDeck()];
00308
00309 for (int i=0;i<GetNumberOfCardsInDeck();i++)
00310 m_Deck[i] = MakeCard((i%13)+1, i/13);
00311
00312 m_Display10AsT = Display10AsT;
00313 }
00314
00315 AFreecellGameBoard::AFreecellGameBoard()
00316 {
00317 m_Deck = NULL;
00318 m_Display10AsT = false;
00319 }
00320
00321
00322 AFreecellGameBoard::~AFreecellGameBoard()
00323 {
00324 if (m_Deck != NULL)
00325 delete [] m_Deck;
00326 }
00327
00328 int AFreecellGameBoard::GetNumberOfCardsInDeck()
00329 {
00330 return 52;
00331 }
00332
00333
00334 char* AFreecellGameBoard::CardToString(char* String, char Card, bool AppendWhiteSpace, bool FlipCondition)
00335 {
00336 if (FlipCondition)
00337 strcpy(String, "<");
00338 else
00339 String[0] = NULL;
00340
00341 switch(GetValue(Card))
00342 {
00343 case 1:
00344 strcat(String, "A");
00345 break;
00346 case 2:
00347 case 3:
00348 case 4:
00349 case 5:
00350 case 6:
00351 case 7:
00352 case 8:
00353 case 9:
00354 String[FlipCondition ? 1 : 0] = GetValue(Card) + '0';
00355 String[FlipCondition ? 2 : 1] = NULL;
00356 break;
00357 case 10:
00358 if (m_Display10AsT)
00359 strcat(String, "T");
00360 else
00361 strcat(String, "10");
00362 break;
00363 case 11:
00364 strcat(String, "J");
00365 break;
00366 case 12:
00367 strcat(String, "Q");
00368 break;
00369 case 13:
00370 strcat(String, "K");
00371 break;
00372 default:
00373 strcat(String, "***");
00374 }
00375
00376 switch (GetSuit(Card))
00377 {
00378 case 0:
00379 strcat(String, "C");
00380 break;
00381 case 1:
00382 strcat(String, "D");
00383 break;
00384 case 2:
00385 strcat(String, "H");
00386 break;
00387 case 3:
00388 strcat(String, "S");
00389 break;
00390 default:
00391 strcat(String, "$$$");
00392 }
00393
00394 if (FlipCondition)
00395 strcat(String, ">");
00396
00397 if (AppendWhiteSpace)
00398 strcat(String, " ");
00399
00400 return String;
00401 }