-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmw_distribution.cpp
More file actions
96 lines (70 loc) · 2.43 KB
/
Copy pathmw_distribution.cpp
File metadata and controls
96 lines (70 loc) · 2.43 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
#include <QLineEdit>
#include <QTimer>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "distrib.h"
#include "engine.h"
#include "myPlot.h"
#include "tls.h"
void MainWindow::drawPlot() {
int cDistrPoints = ui->ed_cntDistrib->text().toInt();
cDistrPoints = std::max(100, cDistrPoints);
int cIter = ui->ed_cntIterDistrib->text().toInt();
cIter = std::max(100, cIter);
int cFractions = ui->ed_distribFractions->text().toInt();
cFractions = std::min(100, std::max(3, cFractions));
Distrib distrib(cFractions);
for (int iStp = 0; iStp < cDistrPoints; ++iStp) {
Deck deck;
ListCards myHand = deck.takeRandomCount(2);
ListCards desk = deck.takeRandomCount(3);
ResProb prob = ::calcProbability(deck, myHand, desk, {}, cIter);
double p = prob.probWin();
distrib.addValue(p);
#if 1
if (iStp % 100 == 0)
qDebug().noquote()
<< iStp
<< "HAND"
<< listNamesCards(myHand)
<< "DESK"
<< listNamesCards(desk)
<< "WIN"
<< fmt(prob.probWin(), 2, 1)
<< "LOSS"
<< fmt(prob.probLoss(), 2, 1);
#endif
deck.recallList(myHand);
deck.recallList(desk);
deck.checkFullAss();
}
//***************************************************************************
double probCancel = getEditText(ui->ed_probCancel, "0.3").toDouble();
QVector<QPointF> points = distrib.getAllPoints();
double maDen = distrib.maxDensity();
double probWinCancel = distrib.probabilityX_byArea(probCancel);
ui->lb_newProbWinCancel->setText(
"Probability of win for cancel: "+
fmt(probWinCancel, 2, 1));
QPolygonF pgCancel;
pgCancel += {probWinCancel, maDen * -0.1};
pgCancel += {probWinCancel, maDen * 1.1};
auto* plot = new MyPlot;
plot->appendPoints({{0,0},{1,0}}, QColorConstants::Gray);
double x = 0.;
for (int ii = 0; ii < 3; ++ii, x += 0.5) {
QPolygonF pgOrd1;
pgOrd1 += {x, maDen * -0.1};
pgOrd1 += {x, maDen * 1.1};
plot->appendPoints(pgOrd1, QColorConstants::Gray);
}
plot->appendPoints(points, QColorConstants::Black);
if (probCancel > 0.)
plot->appendPoints(pgCancel, QColorConstants::Red);
QTimer::singleShot(1, [this,plot] {
plot->show();
plot->repaintPlot(); });
}
void MainWindow::on_bt_distribution_clicked() {
drawPlot();
}