-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
209 lines (169 loc) · 3.55 KB
/
Player.cpp
File metadata and controls
209 lines (169 loc) · 3.55 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "Card.h"
#include "Hand.h"
#include "Player.h"
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <cstring>
using namespace std;
class Simple: public Player {
//Overview: A subclass of Player that will use a simple playing strategy
//implementation of simple player
public:
int bet(unsigned int bankroll, unsigned int minimum){
if(bankroll >= minimum){
return minimum;
}
return 0;
}
bool draw(Card dealer, const Hand &player){
int i = 0;
int Rank_values[13] = {2,3,4,5,6,7,8,9,10,10,10,10,11};
while(dealer.get_rank() != static_cast<Card::Rank>(i)){
++i;
}
if(player.hand_is_soft() == false) {
if(player.hand_value() <= 11){
return true;
}
else if(player.hand_value() < 13 && Rank_values[i] >= 4 && Rank_values[i] <= 6){
return false;
}
else if(player.hand_value() < 13){
return true;
}
else if(player.hand_value() < 17 && Rank_values[i] >= 2 && Rank_values[i] <= 6){
return false;
}
else if(player.hand_value() < 17){
return true;
}
else if(player.hand_value() >=17){
return false;
}
}
else{
if(player.hand_value() <= 17){
return true;
}
else if(player.hand_value() < 19 && (Rank_values[i] == 2 || Rank_values[i] == 7 || Rank_values[i] == 8)){
return false;
}
else if(player.hand_value() == 18){
return true;
}
else{
return false;
}
}
// control reaches end of non-void function fix:
return false;
}
int get_count(){
return 0;
}
void expose(Card c) {
return;
}
void shuffled() {
return;
}
};
class Counting: public Simple{
//Overview: A subclass of simple that keeps track of a card counting playing strategy
private:
int count;
//implementation of counting player
public:
Counting() {
count = 0;
}
int bet(unsigned int bankroll, unsigned int minimum){
if(count >= 2){
if(bankroll >= 2*minimum){
return 2*minimum;
}
else{
return bankroll;
}
}
else{
return minimum;
}
}
void expose(Card c){
int i = 0;
int Rank_Counts[13] = {1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1};
while(c.get_rank() != static_cast<Card::Rank>(i)){
++i;
}
count = count + Rank_Counts[i];
return;
}
void shuffled(){
count = 0;
return;
}
//Effects: returns the int value of the count.
int get_count(){
return count;
}
};
class Competitor: public Counting{
//Overview: a subclass of Counting that implements a more advanced counting technique
private:
int count_competitor;
//implementation of competing player
public:
Competitor() {
count_competitor = 0;
}
int bet(unsigned int bankroll, unsigned int minimum){
if(count_competitor >= 4){
if(bankroll >= 3*minimum){
return 3*minimum;
}
else{
return bankroll;
}
}
else if(count_competitor >= 1){
if(bankroll >= 2*minimum){
return 2*minimum;
}
else{
return bankroll;
}
}
else{
return minimum;
}
}
void expose(Card c){
int i = 0;
int Rank_Counts[13] = {1,1,2,2,2,1,0,-1,-2,-2,-2,-2,0};
while(c.get_rank() != static_cast<Card::Rank>(i)){
++i;
}
count_competitor = count_competitor + Rank_Counts[i];
return;
}
int get_count(){
return count_competitor;
}
};
static Simple Simple_player;
static Counting Counting_player;
static Competitor Competing_player;
Player * player_factory(const char * s){
if(strcmp(s, "simple") == 0){
return &Simple_player;
}
else if(strcmp(s, "counting") == 0){
return &Counting_player;
}
return &Competing_player;
}