-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewGameDialog.java
281 lines (247 loc) · 6.53 KB
/
NewGameDialog.java
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// NewGameDialog.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NewGameDialog extends JDialog implements ActionListener
{
private static final long serialVersionUID = 1L;
private JRadioButton blackHumanButton, blackAIButton, whiteHumanButton, whiteAIButton;
private JTextField blackPlies, whitePlies, fileName, secondsPerPlayer;
private JCheckBox useFileCheckBox;
private JButton okButton, cancelButton;
private boolean okPressed;
public NewGameDialog()
{
super((JFrame)null, "Start New Game", true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
okPressed = false;
buildUI();
setSize(500, 400);
}
public boolean okPressed()
{
return okPressed;
}
public boolean blackIsHuman()
{
return blackHumanButton.isSelected();
}
public boolean whiteIsHuman()
{
return whiteHumanButton.isSelected();
}
public int blackMaxPlies()
{
String p = blackPlies.getText();
int plies = 1;
try
{
plies = Integer.parseInt(p);
}
catch(NumberFormatException e) {}
if(plies < 1)
plies = 1;
return plies;
}
public int whiteMaxPlies()
{
String p = whitePlies.getText();
int plies = 1;
try
{
plies = Integer.parseInt(p);
}
catch(NumberFormatException e) {}
if(plies < 1)
plies = 1;
return plies;
}
public int secondsPerPlayer()
{
String s = secondsPerPlayer.getText();
int seconds = 300;
try
{
seconds = Integer.parseInt(s);
}
catch(NumberFormatException e) {}
return seconds;
}
public String getFileName() //
{
if(useFileCheckBox.isSelected())
return fileName.getText();
else
return null;
}
private void buildUI()
{
Container p = getContentPane();
GridBagLayout g = new GridBagLayout();
p.setLayout(g);
//Change the window size
GridBagConstraints c = new GridBagConstraints(0, 0, 0, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0);
// row 0
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 4;
JLabel blackLabel = new JLabel("Black");
p.add(blackLabel);
g.setConstraints(blackLabel, c);
// row 1
ButtonGroup group1 = new ButtonGroup();
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
blackHumanButton = new JRadioButton("Human", true);
group1.add(blackHumanButton);
p.add(blackHumanButton);
g.setConstraints(blackHumanButton, c);
c.gridx = 1;
blackAIButton = new JRadioButton("AI ", false);
group1.add(blackAIButton);
p.add(blackAIButton);
g.setConstraints(blackAIButton, c);
c.gridx = 2;
JLabel blackPlyLabel = new JLabel(" Plies:");
p.add(blackPlyLabel);
g.setConstraints(blackPlyLabel, c);
c.gridx = 3;
blackPlies = new JTextField("2", 2);
p.add(blackPlies);
g.setConstraints(blackPlies, c);
// row 2
/*
c.gridx = 2;
c.gridy = 2;
c.gridwidth = 1;
blackUseAB = new JCheckBox("Use alpha-beta pruning");
p.add(blackUseAB);
g.setConstraints(blackUseAB, c);
// row 3
ButtonGroup group2 = new ButtonGroup();
c.gridx = 2;
c.gridy = 3;
c.gridwidth = 1;
blackSimpleButton = new JRadioButton("Simple Board Eval", true);
group2.add(blackSimpleButton);
p.add(blackSimpleButton);
g.setConstraints(blackSimpleButton, c);
// row 4
c.gridx = 2;
c.gridy = 4;
c.gridwidth = 1;
blackCustomButton = new JRadioButton("Custom Board Eval");
group2.add(blackCustomButton);
p.add(blackCustomButton);
g.setConstraints(blackCustomButton, c);
*/
// row 5
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 4;
c.anchor = GridBagConstraints.CENTER;
JLabel whiteLabel = new JLabel("White");
p.add(whiteLabel);
g.setConstraints(whiteLabel, c);
// row 6
ButtonGroup group3 = new ButtonGroup();
c.gridx = 0;
c.gridy = 6;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
whiteHumanButton = new JRadioButton("Human", true);
group3.add(whiteHumanButton);
p.add(whiteHumanButton);
g.setConstraints(whiteHumanButton, c);
c.gridx = 1;
whiteAIButton = new JRadioButton("AI ", false);
group3.add(whiteAIButton);
p.add(whiteAIButton);
g.setConstraints(whiteAIButton, c);
c.gridx = 2;
JLabel whitePlyLabel = new JLabel(" Plies:");
p.add(whitePlyLabel);
g.setConstraints(whitePlyLabel, c);
c.gridx = 3;
whitePlies = new JTextField("2", 2);
p.add(whitePlies);
g.setConstraints(whitePlies, c);
// row 7
/*
c.gridx = 2;
c.gridy = 7;
c.gridwidth = 1;
whiteUseAB = new JCheckBox("Use alpha-beta pruning");
p.add(whiteUseAB);
g.setConstraints(whiteUseAB, c);
// row 8
ButtonGroup group4 = new ButtonGroup();
c.gridx = 2;
c.gridy = 8;
c.gridwidth = 1;
whiteSimpleButton = new JRadioButton("Simple Board Eval", true);
group4.add(whiteSimpleButton);
p.add(whiteSimpleButton);
g.setConstraints(whiteSimpleButton, c);
// row 9
c.gridx = 2;
c.gridy = 9;
c.gridwidth = 1;
whiteCustomButton = new JRadioButton("Custom Board Eval");
group4.add(whiteCustomButton);
p.add(whiteCustomButton);
g.setConstraints(whiteCustomButton, c);
*/
// row 10
c.gridx = 0;
c.gridy = 10;
JLabel lab1 = new JLabel("Seconds per player:");
p.add(lab1);
g.setConstraints(lab1, c);
c.gridx = 2;
secondsPerPlayer = new JTextField("300", 4);
p.add(secondsPerPlayer);
g.setConstraints(secondsPerPlayer, c);
// row 11
c.gridx = 0;
c.gridy = 11;
useFileCheckBox = new JCheckBox("Start from file position:");
p.add(useFileCheckBox);
g.setConstraints(useFileCheckBox, c);
c.gridx = 2;
fileName = new JTextField("", 8);
p.add(fileName);
g.setConstraints(fileName, c);
// row 12
c.gridx = 2;
c.gridy = 12;
c.anchor = GridBagConstraints.EAST;
okButton = new JButton("OK");
okButton.addActionListener(this);
p.add(okButton);
g.setConstraints(okButton, c);
c.gridx = 3;
c.anchor = GridBagConstraints.WEST;
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(this);
p.add(cancelButton);
g.setConstraints(cancelButton, c);
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if(obj == okButton)
{
okPressed = true;
processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
else if(obj == cancelButton)
{
okPressed = false;
this.dispose();
}
}
}