forked from dsanno/Klondike-Solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.cpp
77 lines (72 loc) · 1.29 KB
/
Card.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Card.h"
#include <iostream>
using namespace std;
void Card::Clear() {
Rank = EMPTY;
Suit = NONE;
}
void Card::Set(unsigned char value) {
Value = value;
Rank = (value % 13) + 1;
Suit = value / 13;
IsRed = Suit & 1 ? 0 : 1;
IsOdd = Rank & 1;
Foundation = Suit + 9;
/*
printf("Card::Set(%d):\n", Value);
printf(" Rank: %d\n", Rank);
printf(" Suit: %d\n", Suit);
printf(" IsRed: %d\n", IsRed);
printf(" IsOdd: %d\n", IsOdd);
printf(" Foundation: %d\n", Foundation);
*/
}
unsigned char Card::GetSuit(unsigned char suit) {
switch (toupper(suit)) {
case 'H':
return HEARTS;
break;
case 'S':
return SPADES;
break;
case 'D':
return DIAMONDS;
break;
case 'C':
return CLUBS;
break;
default:
return NONE;
}
}
unsigned char Card::GetRank(unsigned char rank) {
switch (toupper(rank)) {
case 'A':
return 1;
break;
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return rank - 48;
break;
case 'T':
return 10;
break;
case 'J':
return 11;
break;
case 'Q':
return 12;
break;
case 'K':
return 13;
break;
default:
return 0;
}
}