-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarddeck.pas
More file actions
104 lines (88 loc) · 2.17 KB
/
Copy pathcarddeck.pas
File metadata and controls
104 lines (88 loc) · 2.17 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
unit CardDeck;
{$mode objfpc}{$H+}
interface
uses
SpiderTypes;
procedure BuildDeck(var Deck: TDeck; Difficulty: TSpiderDifficulty);
procedure ShuffleDeck(var Deck: TDeck);
function RankToStr(R: TRank): string;
function SuitToStr(S: TSuit): string;
implementation
procedure BuildDeck(var Deck: TDeck; Difficulty: TSpiderDifficulty);
var
d, r, i: Integer;
s: TSuit;
begin
d := 0;
case Difficulty of
sdOneSuit:
begin
// 1-suit Spider: 8 copies of Spades
for i := 1 to 8 do
for r := Ord(Low(TRank)) to Ord(High(TRank)) do
begin
Deck[d].Rank := TRank(r);
Deck[d].Suit := Spades;
Deck[d].FaceUp := False;
Inc(d);
end;
end;
sdTwoSuit:
begin
// 2-suit Spider: 4 copies of Hearts, 4 copies of Spades
for i := 1 to 4 do
for s in [Hearts, Spades] do
for r := Ord(Low(TRank)) to Ord(High(TRank)) do
begin
Deck[d].Rank := TRank(r);
Deck[d].Suit := s;
Deck[d].FaceUp := False;
Inc(d);
end;
end;
sdFourSuit:
begin
// 4-suit Spider: 2 copies of each suit
for i := 1 to 2 do
for s := Low(TSuit) to High(TSuit) do
for r := Ord(Low(TRank)) to Ord(High(TRank)) do
begin
Deck[d].Rank := TRank(r);
Deck[d].Suit := s;
Deck[d].FaceUp := False;
Inc(d);
end;
end;
end;
end;
procedure ShuffleDeck(var Deck: TDeck);
var
i, j: Integer;
Temp: TCard;
begin
for i := TOTAL_CARDS - 1 downto 1 do
begin
j := Random(i + 1);
Temp := Deck[i];
Deck[i] := Deck[j];
Deck[j] := Temp;
end;
end;
function RankToStr(R: TRank): string;
const
RankNames: array[TRank] of string =
('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K');
begin
Result := RankNames[R];
end;
function SuitToStr(S: TSuit): string;
//** Work on why unicode characters are'nt working
begin
case S of
Hearts: Result := 'H';
Diamonds: Result := 'D';
Clubs: Result := 'C';
Spades: Result := 'S';
end;
end;
end.