forked from gcp/LeelaGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewGameDialog.cpp
237 lines (191 loc) · 7 KB
/
NewGameDialog.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "stdafx.h"
#include "NewGameDialog.h"
#include "UCTSearch.h"
#include "GTP.h"
NewGameDialog::NewGameDialog( wxWindow* parent )
:
TNewGameDialog( parent )
{
}
void NewGameDialog::doInit( wxInitDialogEvent& event ) {
int size = wxConfig::Get()->ReadLong(wxT("DefaultBoardSize"), (long)4);
m_radioBoxBoardSize->SetSelection(size);
int handicap = wxConfig::Get()->ReadLong(wxT("DefaultHandicap"), (long)0);
m_spinCtrlHandicap->SetValue(handicap);
int komi = wxConfig::Get()->ReadLong(wxT("DefaultKomi"), (long)7);
m_spinCtrlKomi->SetValue(komi);
int simulations;
if (cfg_use_engine == GTP::ORIGINE_ENGINE) {
simulations = wxConfig::Get()->ReadLong(wxT("DefaultSimulations"), (long)6);
m_radioBoxLevel->SetSelection(simulations);
int simulations_num = wxConfig::Get()->ReadLong(wxT("DefaultSimulationsNum"), (long)250);
m_spinCtrlLevel->SetValue(simulations_num);
int minutes = wxConfig::Get()->ReadLong(wxT("DefaultMinutes"), (long)20);
m_spinCtrlTime->SetValue(minutes);
int byo = wxConfig::Get()->ReadLong(wxT("DefaultByo"), (long)2);
m_spinCtrlByo->SetValue(byo);
} else {
simulations = wxConfig::Get()->ReadLong(wxT("DefaultSimulationsKataGo"), (long)6);
m_radioBoxLevel->SetSelection(simulations);
int simulations_num = wxConfig::Get()->ReadLong(wxT("DefaultSimulationsNumKataGo"), (long)250);
m_spinCtrlLevel->SetValue(simulations_num);
int minutes = wxConfig::Get()->ReadLong(wxT("DefaultMinutesKataGo"), (long)20);
m_spinCtrlTime->SetValue(minutes);
int byo = wxConfig::Get()->ReadLong(wxT("DefaultByoKataGo"), (long)2);
m_spinCtrlByo->SetValue(byo);
}
int color = wxConfig::Get()->ReadLong(wxT("DefaultColor"), (long)0);
m_radioBoxColor->SetSelection(color);
bool nets = wxConfig::Get()->Read(wxT("netsEnabled"), true);
m_checkNeuralNet->SetValue(nets);
if (cfg_use_engine == GTP::KATAGO_ENGINE) {
m_checkNeuralNet->Enable(false);
}
if (!cfg_board25) {
wxString sboardsize = m_radioBoxBoardSize->GetStringSelection();
if (sboardsize == "25 x 25") {
m_radioBoxBoardSize->SetSelection( 4 );
}
m_radioBoxBoardSize->Enable(5, false);
}
if (simulations != 7) {
m_spinCtrlLevel->Enable(false);
}
checkNetsEnabled();
checkHandicapRange();
}
void NewGameDialog::doLevel( wxCommandEvent& WXUNUSED(event) ) {
int simuls = m_radioBoxLevel->GetSelection();
if (simuls != 7) {
m_spinCtrlLevel->Enable(false);
} else {
m_spinCtrlLevel->Enable(true);
}
}
void NewGameDialog::doCancel( wxCommandEvent& event ) {
event.Skip();
}
void NewGameDialog::doOK( wxCommandEvent& event ) {
int size = m_radioBoxBoardSize->GetSelection();
wxConfig::Get()->Write(wxT("DefaultBoardSize"), (long)size);
int simulations = m_radioBoxLevel->GetSelection();
int simulations_num = m_spinCtrlLevel->GetValue();
if (cfg_use_engine == GTP::ORIGINE_ENGINE) {
wxConfig::Get()->Write(wxT("DefaultSimulations"), (long)simulations);
wxConfig::Get()->Write(wxT("DefaultSimulationsNum"), (long)simulations_num);
} else {
wxConfig::Get()->Write(wxT("DefaultSimulationsKataGo"), (long)simulations);
wxConfig::Get()->Write(wxT("DefaultSimulationsNumKataGo"), (long)simulations_num);
}
int color = m_radioBoxColor->GetSelection();
wxConfig::Get()->Write(wxT("DefaultColor"), (long)color);
int handicap = m_spinCtrlHandicap->GetValue();
wxConfig::Get()->Write(wxT("DefaultHandicap"), (long)handicap);
int komi = m_spinCtrlKomi->GetValue();
wxConfig::Get()->Write(wxT("DefaultKomi"), (long)komi);
int minutes = m_spinCtrlTime->GetValue();
int byo = m_spinCtrlByo->GetValue();
if (cfg_use_engine == GTP::ORIGINE_ENGINE) {
wxConfig::Get()->Write(wxT("DefaultMinutes"), (long)minutes);
wxConfig::Get()->Write(wxT("DefaultByo"), (long)byo);
} else {
wxConfig::Get()->Write(wxT("DefaultMinutesKataGo"), (long)minutes);
wxConfig::Get()->Write(wxT("DefaultByoKataGo"), (long)byo);
}
bool nets = m_checkNeuralNet->GetValue();
wxConfig::Get()->Write(wxT("netsEnabled"), nets);
if (simulations != 7) {
m_spinCtrlLevel->Enable(false);
}
event.Skip();
}
float NewGameDialog::getKomi() {
float komi = m_spinCtrlKomi->GetValue();
return komi + 0.5f;
}
int NewGameDialog::getHandicap() {
int handicap = m_spinCtrlHandicap->GetValue();
return handicap;
}
int NewGameDialog::getBoardsize() {
wxString sboardsize = m_radioBoxBoardSize->GetStringSelection();
if (sboardsize == "7 x 7") {
return 7;
} else if (sboardsize == "9 x 9") {
return 9;
} else if (sboardsize == "13 x 13") {
return 13;
} else if (sboardsize == "17 x 17") {
return 17;
} else if (sboardsize == "19 x 19") {
return 19;
} else if (sboardsize == "25 x 25") {
return 25;
}
throw std::runtime_error("Invalid board size selection");
}
int NewGameDialog::simulationsToVisitLimit(int simuls) {
if (simuls == 0) {
return 100;
} else if (simuls == 1) {
return 500;
} else if (simuls == 2) {
return 1000;
} else if (simuls == 3) {
return 5000;
} else if (simuls == 4) {
return 10000;
} else if (simuls == 5) {
return 20000;
} else if (simuls == 6) {
return 0;
} else {
throw std::runtime_error("Invalid simulations level selection");
}
}
int NewGameDialog::getSimulations() {
int simuls = m_radioBoxLevel->GetSelection();
if (simuls != 7) {
return simulationsToVisitLimit(simuls);
} else {
return m_spinCtrlLevel->GetValue();
}
}
int NewGameDialog::getPlayerColor() {
int color = m_radioBoxColor->GetSelection();
return color;
}
int NewGameDialog::getTimeControl() {
return m_spinCtrlTime->GetValue();
}
int NewGameDialog::getByoControl() {
return m_spinCtrlByo->GetValue();
}
void NewGameDialog::doHandicapUpdate( wxSpinEvent& event ) {
m_spinCtrlKomi->SetValue(0);
}
bool NewGameDialog::getNetsEnabled() {
return m_checkNeuralNet->GetValue();
}
void NewGameDialog::doRadioBox(wxCommandEvent& WXUNUSED(event)) {
checkNetsEnabled();
checkHandicapRange();
}
void NewGameDialog::checkNetsEnabled() {
wxString sboardsize = m_radioBoxBoardSize->GetStringSelection();
if (cfg_use_engine != GTP::ORIGINE_ENGINE || sboardsize != "19 x 19") {
m_checkNeuralNet->Enable(false);
} else {
m_checkNeuralNet->Enable(true);
}
}
void NewGameDialog::checkHandicapRange() {
wxString sboardsize = m_radioBoxBoardSize->GetStringSelection();
if (sboardsize == "7 x 7") {
m_spinCtrlHandicap->SetRange(0, 4);
} else if (sboardsize == "9 x 9") {
m_spinCtrlHandicap->SetRange(0, 9);
} else {
m_spinCtrlHandicap->SetRange(0, 100);
}
}