00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include "FCSCard.h"
00011 #include "FCDebugState.h"
00012 #include "FCCompactState.h"
00013 #include "FCIndirectState.h"
00014
00016 char CardMap10[14][4] = { " ", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
00018 char CardMapT[14][4] = { " ", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" };
00019
00021 #define MakeUpperCase(c) ( (((c)>='a') && ((c)<='z')) ? ((c)+'A'-'a') : (c))
00022
00023 FCSCard* FCSCard::Create()
00024 {
00025 switch(GlobalStateType)
00026 {
00027 case FC_DEBUG_STATE:
00028 case FC_TALON_DEBUG_STATE:
00029 return new FCSDebugCard();
00030 case FC_COMPACT_STATE:
00031 case FC_TALON_COMPACT_STATE:
00032 return new FCSCompactCard();
00033 case FC_INDIRECT_STATE:
00034 case FC_TALON_INDIRECT_STATE:
00035 return new FCSIndirectCard();
00036 default:
00037 return NULL;
00038 }
00039 }
00040
00041 int FCSCard::Compare(FCSCard* Card)
00042 {
00043
00044 if (GetCardNumber() > Card->GetCardNumber())
00045 return 1;
00046 else if (GetCardNumber() < Card->GetCardNumber())
00047 return -1;
00048
00049
00050 if (GetSuit() > Card->GetSuit())
00051 return 1;
00052 else if (GetSuit() < Card->GetSuit())
00053 return -1;
00054
00055 return 0;
00056 }
00057
00058
00059 void FCSCard::User2Perl(const char *String)
00060 {
00061 SetFlipped(User2PerlFlippedStatus(String));
00062 SetCardNumber(User2PerlCardNumber(String));
00063 SetSuit(User2PerlSuit(String));
00064 }
00065
00066 char* FCSCard::Perl2User(char* String, int Display10AsT, bool DisplayDebug)
00067 {
00068 bool CardNumberIsNull;
00069 char* ReturnString = String;
00070
00071 if (DisplayDebug && GetFlipped())
00072 {
00073 *String = '<';
00074 String++;
00075 }
00076
00077 Perl2UserCardNumber(GetCardNumber(), String, &CardNumberIsNull, Display10AsT, GetFlipped(), DisplayDebug);
00078
00079
00080
00081 Perl2UserSuit(GetSuit(), String + strlen(String), &CardNumberIsNull, GetFlipped(), DisplayDebug);
00082
00083 if (DisplayDebug && GetFlipped())
00084 strcat(String, ">");
00085
00086 return ReturnString;
00087 }
00088
00089 char* FCSCard::Perl2UserCardNumber(int Number, char* String, bool *CardNumberIsNull,
00090 int Display10AsT, int Flipped, bool DisplayDebug)
00091 {
00092 char (*CardMap) [4] = CardMap10;
00093 if (Display10AsT)
00094 CardMap = CardMapT;
00095
00096 if ((DisplayDebug) && Flipped)
00097 {
00098 strncpy(String, "*", 2);
00099 *CardNumberIsNull = false;
00100 }
00101 else if ((!DisplayDebug) && Flipped)
00102 {
00103 strncpy(String, " ", 2);
00104 *CardNumberIsNull = false;
00105 }
00106 else if (!Flipped)
00107 {
00108 if ((Number >= 0) && (Number <= 13))
00109 {
00110 strncpy(String, CardMap[Number], strlen(CardMap[Number])+1);
00111 *CardNumberIsNull = (Number == 0);
00112 }
00113 else
00114 {
00115 strncpy(String, CardMap[0], strlen(CardMap[0])+1);
00116 *CardNumberIsNull = true;
00117 }
00118 }
00119
00120 return String;
00121 }
00122
00123 char* FCSCard::Perl2UserSuit(int Suit, char* String, bool *CardNumberIsNull, int Flipped, bool DisplayDebug)
00124 {
00125 if ((!DisplayDebug) && Flipped)
00126 {
00127 strncpy(String, "*", 2);
00128 }
00129 if (!Flipped)
00130 {
00131 switch(Suit)
00132 {
00133 case 0:
00134 if (*CardNumberIsNull)
00135 {
00136 if (DisplayDebug)
00137 strncpy(String, "*", 2);
00138 else
00139 strncpy(String, " ", 2);
00140 }
00141 else
00142 strncpy(String, "H", 2);
00143 break;
00144 case 1:
00145 strncpy(String, "C", 2);
00146 break;
00147 case 2:
00148 strncpy(String, "D", 2);
00149 break;
00150 case 3:
00151 strncpy(String, "S", 2);
00152 break;
00153 default:
00154 strncpy(String, " ", 2);
00155 }
00156 }
00157
00158 return String;
00159 }
00160
00161 int FCSCard::User2PerlCardNumber(const char* String)
00162 {
00163 char Rest;
00164
00165 while (1)
00166 {
00167 Rest = MakeUpperCase(*String);
00168 switch(Rest)
00169 {
00170 case '\0':
00171 case ' ':
00172 case '\t':
00173 return 0;
00174 case 'A':
00175 return 1;
00176 case 'J':
00177 return 11;
00178 case 'Q':
00179 return 12;
00180 case 'K':
00181 return 13;
00182 case '1':
00183 return (*(String+1) == '0')?10:1;
00184 case '0':
00185 case 'T':
00186 return 10;
00187 case '2':
00188 case '3':
00189 case '4':
00190 case '5':
00191 case '6':
00192 case '7':
00193 case '8':
00194 case '9':
00195 return Rest - '0';
00196 default:
00197 String++;
00198 }
00199 }
00200 }
00201
00202
00203 int FCSCard::User2PerlSuit(const char* String)
00204 {
00205 char c = MakeUpperCase(*String);
00206 while (
00207 (c != 'H') &&
00208 (c != 'S') &&
00209 (c != 'D') &&
00210 (c != 'C') &&
00211 (c != ' ') &&
00212 (c != '\0'))
00213 {
00214 String++;
00215 c = MakeUpperCase(*String);
00216 }
00217
00218 switch (c)
00219 {
00220 case 'H':
00221 return 0;
00222 case 'C':
00223 return 1;
00224 case 'D':
00225 return 2;
00226 case 'S':
00227 return 3;
00228 default:
00229 return 0;
00230 }
00231 }
00232
00233 int FCSCard::User2PerlFlippedStatus(const char * String)
00234 {
00235 while (*String != '\0')
00236 {
00237 if ((*String != ' ') && (*String != '\t'))
00238 {
00239 return (*String == '<');
00240 }
00241 String++;
00242 }
00243 return 0;
00244 }