-
Notifications
You must be signed in to change notification settings - Fork 1
/
statisticalmodel.cpp
66 lines (55 loc) · 1.52 KB
/
statisticalmodel.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
#include "statisticalmodel.h"
#include <QStringList>
#include <QFile>
#include <QTextStream>
StatisticalModel::StatisticalModel()
{
load();
}
StatisticalModel::~StatisticalModel()
{
save();
}
void StatisticalModel::addContext(float potOdds, Player::Action lastAction, const Deck &communityCards, int handPower)
{
m_contexts.append(Context(potOdds, lastAction, communityCards, handPower));
}
QString StatisticalModel::Context::toString() const
{
QString ret;
ret += QString::number(m_potOdds);
ret += ';';
ret += QString::number(m_lastAction);
ret += ';';
ret += m_communityCards.toString();
ret += ';';
ret += QString::number(m_handPower);
ret += '\n';
return ret;
}
StatisticalModel::Context StatisticalModel::Context::fromString(QString string)
{
QStringList elements = string.split(';');
float potOdds = elements[0].toFloat();
Player::Action action = (Player::Action)elements[1].toInt();
Deck deck = Deck::fromString(elements[2]);
int handPower = elements[3].toInt();
return Context(potOdds, action, deck, handPower);
}
void StatisticalModel::save(QString filename)
{
QFile file(filename);
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
foreach(const Context &context, m_contexts) {
out << context.toString();
}
}
void StatisticalModel::load(QString filename)
{
QFile file(filename);
file.open(QIODevice::ReadOnly);
while (!file.atEnd()) {
m_contexts.append(Context::fromString(file.readLine()));
}
}