-
Notifications
You must be signed in to change notification settings - Fork 14
/
ai_smart.cpp
155 lines (132 loc) · 4.55 KB
/
ai_smart.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
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
/*
OOPoker
Copyright (c) 2010 Lode Vandevenne
All rights reserved.
This file is part of OOPoker.
OOPoker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OOPoker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OOPoker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ai_smart.h"
#include "info.h"
#include "random.h"
#include "pokermath.h"
#include <iostream>
AISmart::AISmart(double tightness)
: tightness(tightness)
{
}
Action AISmart::doTurn(const Info& info)
{
/*
The "Smart" AI tries to win by playing with good cards and folding with bad cards.
This AI is called smart because it's smart compared to the Naive demo AI's. However, it
isn't that smart at all! It wins without problems against ai_random. But are you able
to make an AI that beats AISmart?
Some hints for better AI's:
-use pot equity / odds
-have a memory, to enable strategies that take multiple turns, such as check-raise
-use Harrington zones
-use position compared to the dealer
-take the amount of opponents into account
-try to keep track of playing style of other players, recognise individual players
-change strategy every now and then to try not to be too predictable
-detect when an opponent is weak and can be outbluffed
-isolate a certain opponent
-...
*/
double raiseChance = 0.0;
double allInChance = 0.0;
int maxWager = 0; //for calling
int bb = info.getBigBlind();
if(info.round == R_PRE_FLOP)
{
int group = getSklanskyMalmuthGroup(info.getHoleCards()[0], info.getHoleCards()[1]);
if(group == 9) maxWager = 0;
else if(group == 8 || group == 7) maxWager = bb;
else if(group == 6 || group == 5)
{
maxWager = bb * 4;
raiseChance = 0.2;
}
else if(group == 4 || group == 3)
{
maxWager = info.getStack() + info.getWager();
raiseChance = 0.5;
allInChance = 0.1;
}
else if(group == 2 || group == 1)
{
maxWager = info.getStack() + info.getWager();
raiseChance = 0.5;
allInChance = 0.2;
}
}
else
{
double win, tie, lose;
int num_opponents = info.getNumActivePlayers() - 1;
if(info.round == R_FLOP) getWinChanceAgainstNAtFlop(win, tie, lose, info.getHoleCards()[0], info.getHoleCards()[1], info.boardCards[0], info.boardCards[1], info.boardCards[2], num_opponents);
else if(info.round == R_TURN) getWinChanceAgainstNAtTurn(win, tie, lose, info.getHoleCards()[0], info.getHoleCards()[1], info.boardCards[0], info.boardCards[1], info.boardCards[2], info.boardCards[3], num_opponents);
else if(info.round == R_RIVER) getWinChanceAgainstNAtRiver(win, tie, lose, info.getHoleCards()[0], info.getHoleCards()[1], info.boardCards[0], info.boardCards[1], info.boardCards[2], info.boardCards[3], info.boardCards[4], num_opponents);
if(win > tightness)
{
maxWager = info.getStack() + info.getWager();
raiseChance = 0.5;
allInChance = 0.5;
}
else if(win > tightness / 2)
{
maxWager = (info.getStack() + info.getWager()) / 3;
raiseChance = 0.2;
}
else if(tie > 0.8)
{
//large chance to tie (maybe there's a royal flush on the table or so). Never fold in this case!
raiseChance = 0;
allInChance = 0;
maxWager = info.getStack() + info.getWager();
}
else //misery... only check or fold
{
maxWager = 0;
}
}
int minWagerTotal = info.getWager() + info.getCallAmount();
if(minWagerTotal > info.getWager() + info.getStack()) minWagerTotal = info.getWager() + info.getStack();
if(minWagerTotal > maxWager)
{
return info.getCheckFoldAction();
}
else
{
if(getRandom() < raiseChance)
{
int amount = (int)(info.getMinChipsToRaise() * (1.0 + getRandom()));
//round the amount to become a multiple of big blinds
amount = (amount / bb) * bb;
if(amount == 0) amount = info.getMinChipsToRaise();
return info.amountToAction(amount);
}
else if(getRandom() < allInChance)
{
return info.getAllInAction();
}
else
{
return info.getCallAction();
}
}
return info.getCheckFoldAction();
}
std::string AISmart::getAIName()
{
return "Smart";
}