-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.cpp
85 lines (72 loc) · 1.77 KB
/
player.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
79
80
81
82
83
84
#include "player.h"
#include "table.h"
#include <QDebug>
Player::Player(bool offensive) :
m_hasFolded(false),
m_money(1000),
m_bet(0),
m_offensive(offensive),
m_win(0),
m_tie(0)
{
static int count=0;
count++;
if (offensive) {
m_name = "offensive" + QString::number(count);
} else {
m_name = "conservative" + QString::number(count);
}
}
Player::Action Player::assess(Table *table)
{
if (table->flop().isEmpty() && qrand() % 2 == 1)
return Fold;
if (m_offensive) {
if (table->lastBet() < 150) {
m_bet = 50;
return Raise;
}
if (table->flop().isEmpty()) {
return Call;
}
if (handStrength(table) < 5) {
m_hasFolded = true;
return Fold;
} else if (lastHandStrength() > 6 && lastHandStrength() < 7)
return Call;
else {
m_bet = table->lastBet() + 50;
return Raise;
}
} else {
if (table->flop().isEmpty()) {
return Call;
}
if (handStrength(table) < 5) {
m_hasFolded = true;
return Fold;
} else if (lastHandStrength() > 7 && lastHandStrength() < 8)
return Call;
else {
m_bet = table->lastBet() + 50;
return Raise;
}
}
}
int Player::handStrength(Table *table)
{
Deck cards(m_cards);
cards.append(table->flop());
if (!table->turn().isNull())
cards.append(table->turn());
if (!table->river().isNull())
cards.append(table->river());
m_lastHandStrength = cards.strength();
return m_lastHandStrength;
}
void Player::setDeck(Deck deck)
{
m_cards = deck;
m_hasFolded = false;
m_cards.printOut();
}