-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNewGameDialog.cpp
164 lines (129 loc) · 4.56 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
#include "stdafx.h"
#include "NewGameDialog.h"
#include "UCTSearch.h"
NewGameDialog::NewGameDialog( wxWindow* parent )
:
TNewGameDialog( parent )
{
}
void NewGameDialog::doInit( wxInitDialogEvent& event ) {
int size = wxConfig::Get()->Read(wxT("DefaultBoardSize"), (long)4);
m_radioBoxBoardSize->SetSelection(size);
int handicap = wxConfig::Get()->Read(wxT("DefaultHandicap"), (long)0);
m_spinCtrlHandicap->SetValue(handicap);
int komi = wxConfig::Get()->Read(wxT("DefaultKomi"), (long)7);
m_spinCtrlKomi->SetValue(komi);
int simulations = wxConfig::Get()->Read(wxT("DefaultSimulations"), (long)6);
m_radioBoxLevel->SetSelection(simulations);
int minutes = wxConfig::Get()->Read(wxT("DefaultMinutes"), (long)20);
m_spinCtrlTime->SetValue(minutes);
int color = wxConfig::Get()->Read(wxT("DefaultColor"), (long)0);
m_radioBoxColor->SetSelection(color);
bool nets = wxConfig::Get()->Read(wxT("netsEnabled"), true);
m_checkNeuralNet->SetValue(nets);
checkNetsEnabled();
checkHandicapRange();
}
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();
wxConfig::Get()->Write(wxT("DefaultSimulations"), (long)simulations);
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();
wxConfig::Get()->Write(wxT("DefaultMinutes"), (long)minutes);
bool nets = m_checkNeuralNet->GetValue();
wxConfig::Get()->Write(wxT("netsEnabled"), nets);
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();
return simulationsToVisitLimit(simuls);
}
int NewGameDialog::getPlayerColor() {
int color = m_radioBoxColor->GetSelection();
return color;
}
int NewGameDialog::getTimeControl() {
return m_spinCtrlTime->GetValue();
}
void NewGameDialog::doHandicapUpdate( wxSpinEvent& event ) {
m_spinCtrlKomi->SetValue(0);
}
bool NewGameDialog::getNetsEnabled() {
return m_checkNeuralNet->GetValue();
}
void NewGameDialog::doRadioBox(wxCommandEvent& event) {
checkNetsEnabled();
checkHandicapRange();
}
void NewGameDialog::checkNetsEnabled() {
wxString sboardsize = m_radioBoxBoardSize->GetStringSelection();
if (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);
}
}