forked from ShootMe/Klondike-Solver
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPile.cpp
78 lines (75 loc) · 1.22 KB
/
Pile.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
78
#include"Pile.h"
void Pile::AddDown(Card card) {
down[downSize++] = card;
size++;
}
void Pile::AddUp(Card card) {
up[upSize++] = card;
size++;
}
void Pile::Flip() {
if (upSize > 0) {
down[downSize++] = up[--upSize];
} else {
up[upSize++] = down[--downSize];
}
}
void Pile::Remove(Pile & to) {
to.AddUp(up[--upSize]);
size--;
}
void Pile::Remove(Pile & to, int count) {
for (int i = upSize - count; i < upSize; ++i) {
to.AddUp(up[i]);
}
upSize -= count;
size -= count;
}
void Pile::RemoveTalon(Pile & to, int count) {
int i = size - count;
do {
to.AddUp(up[--size]);
} while (size > i);
upSize = size;
}
void Pile::Reset() {
size = 0;
upSize = 0;
downSize = 0;
}
void Pile::Initialize() {
size = 0;
upSize = 0;
downSize = 0;
for (int i = 0; i < 24; i++) {
up[i].Clear();
down[i].Clear();
}
}
int Pile::Size() {
return size;
}
int Pile::DownSize() {
return downSize;
}
int Pile::UpSize() {
return upSize;
}
Card Pile::operator[](int index) {
return up[index];
}
Card Pile::Down(int index) {
return down[index];
}
Card Pile::Up(int index) {
return up[index];
}
Card Pile::Low() {
return up[upSize - 1];
}
Card Pile::High() {
return up[0];
}
int Pile::HighValue() {
return upSize > 0 ? up[0].Value : 99;
}