-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.java
567 lines (520 loc) · 32 KB
/
GUI.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package thesis;
import java.io.File;
import java.io.IOException;
import static java.lang.Math.pow;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
/**
*
* @author natha_000
*/
public class GUI extends javax.swing.JFrame {
/**
* Creates new form GUI
*/
public static ArrayList<Player> tourneyPlayers = new ArrayList<Player>();
public static ArrayList<Player> placeHolder = new ArrayList<Player>();
public static ArrayList<Player> startingPlayers = new ArrayList<Player>();
public static Tournament tourney = new Tournament(placeHolder); // downfall of initializing tournament up here is that it'll be unsorted, unless we sort it after adding participants
public static int accountBalance = 500;
public static Player playerBetOn;
public static Match matchBetOn;
private JPopupMenu popupMenu;
JFileChooser excelFileChooser = new JFileChooser(new File("/Users/natha_000/Documents"));
public GUI() {
initComponents();
setTitle("prediction bot mk. 0");
setBounds(300,300,700,700);
setVisible(true);
// comboBox.removeAllItems();
// balanceArea.setText(Integer.toString(accountBalance));
popupMenu = new JPopupMenu();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
jPopupMenu2 = new javax.swing.JPopupMenu();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
playerFirstName = new javax.swing.JTextField();
playerLastName = new javax.swing.JTextField();
playerELO = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
addToTourneyButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tourneyParticipants = new javax.swing.JTextArea();
simulateDoubleElimButton = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
roundPairings = new javax.swing.JTextArea();
generateRoundPairingsButton = new javax.swing.JButton();
simulateSingleElimButton = new javax.swing.JButton();
simulateRoundButton = new javax.swing.JButton();
newTourneyButton = new javax.swing.JButton();
bulkAddButton = new javax.swing.JButton();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
numberBulkEntrants = new javax.swing.JTextField();
eloBulkEntrants = new javax.swing.JTextField();
addFromExcelButton = new javax.swing.JButton();
excelFileChooserButton = new javax.swing.JButton();
loadMatchHistoryButton = new javax.swing.JButton();
SimXTourniesButton = new javax.swing.JButton();
numTourniesToSim = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Player First Name");
jLabel2.setText("Player Last Name");
jLabel3.setText("Player ELO");
addToTourneyButton.setText("Add to tournament roster");
addToTourneyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addToTourneyButtonActionPerformed(evt);
}
});
tourneyParticipants.setColumns(20);
tourneyParticipants.setRows(5);
jScrollPane1.setViewportView(tourneyParticipants);
simulateDoubleElimButton.setText("SIMULATE! (double elimination");
simulateDoubleElimButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
simulateDoubleElimButtonActionPerformed(evt);
}
});
jLabel4.setText("Tournament Roster");
jLabel5.setText("(Add even number of entrants)");
jLabel7.setText("Current matches/match log");
roundPairings.setColumns(20);
roundPairings.setRows(5);
jScrollPane3.setViewportView(roundPairings);
generateRoundPairingsButton.setText("Generate round pairings!");
generateRoundPairingsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
generateRoundPairingsButtonActionPerformed(evt);
}
});
simulateSingleElimButton.setText("SIMULATE! (single elimination)");
simulateSingleElimButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
simulateSingleElimButtonActionPerformed(evt);
}
});
simulateRoundButton.setText("SIMULATE! (current round)");
simulateRoundButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
simulateRoundButtonActionPerformed(evt);
}
});
newTourneyButton.setText("New tournament!");
newTourneyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newTourneyButtonActionPerformed(evt);
}
});
bulkAddButton.setText("Bulk add");
bulkAddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bulkAddButtonActionPerformed(evt);
}
});
jLabel9.setText("# of entrants");
jLabel10.setText("Entrant ELO score");
addFromExcelButton.setText("Add players from default excel sheet");
addFromExcelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addFromExcelButtonActionPerformed(evt);
}
});
excelFileChooserButton.setText("Choose top 32 excel file to add players from");
excelFileChooserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
excelFileChooserButtonActionPerformed(evt);
}
});
loadMatchHistoryButton.setText("Choose match history excel file to add players from");
loadMatchHistoryButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadMatchHistoryButtonActionPerformed(evt);
}
});
SimXTourniesButton.setText("Simulate X tournaments");
SimXTourniesButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SimXTourniesButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 142, Short.MAX_VALUE)
.addComponent(excelFileChooserButton)
.addGap(53, 53, 53))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(191, 191, 191)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(addToTourneyButton)))
.addGroup(layout.createSequentialGroup()
.addGap(213, 213, 213)
.addComponent(bulkAddButton))
.addGroup(layout.createSequentialGroup()
.addGap(155, 155, 155)
.addComponent(addFromExcelButton))
.addGroup(layout.createSequentialGroup()
.addGap(176, 176, 176)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(newTourneyButton))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(numberBulkEntrants))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(eloBulkEntrants)))
.addGroup(layout.createSequentialGroup()
.addComponent(playerFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(playerLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2))
.addComponent(simulateRoundButton)
.addComponent(simulateSingleElimButton)
.addComponent(simulateDoubleElimButton)
.addGroup(layout.createSequentialGroup()
.addGap(9, 9, 9)
.addComponent(generateRoundPairingsButton))))
.addGroup(layout.createSequentialGroup()
.addGap(126, 126, 126)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(loadMatchHistoryButton)
.addGroup(layout.createSequentialGroup()
.addComponent(SimXTourniesButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(numTourniesToSim, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(42, 42, 42))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(18, 18, 18))))
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(playerELO, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(151, 151, 151)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(playerFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(playerLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(playerELO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(addToTourneyButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5))
.addComponent(jScrollPane1))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jLabel9)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(numberBulkEntrants, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(eloBulkEntrants, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bulkAddButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(addFromExcelButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(excelFileChooserButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(loadMatchHistoryButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(generateRoundPairingsButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(simulateDoubleElimButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(simulateSingleElimButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(simulateRoundButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(SimXTourniesButton)
.addComponent(numTourniesToSim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addComponent(newTourneyButton)))
.addContainerGap(33, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void addToTourneyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addToTourneyButtonActionPerformed
if (playerELO.getText().isEmpty() == false && playerFirstName.getText().isEmpty() == false && playerLastName.getText().isEmpty() == false){
System.out.println("valid input");
Player newPlayer = new Player(Integer.parseInt(playerELO.getText()), playerFirstName.getText(), playerLastName.getText());
tourneyPlayers.add(newPlayer);
startingPlayers.add(newPlayer);
// comboBox.addItem(newPlayer.getName());
playerELO.setText("");
playerFirstName.setText("");
playerLastName.setText("");
Collections.sort(tourneyPlayers);
tourney.setTourneyPlayers(tourneyPlayers);
tourneyParticipants.setText(tourneyPlayers.toString());
}
}//GEN-LAST:event_addToTourneyButtonActionPerformed
private void simulateDoubleElimButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateDoubleElimButtonActionPerformed
tourney.playDoubleElimTournament();
roundPairings.setText(tourney.getMatchLog());
}//GEN-LAST:event_simulateDoubleElimButtonActionPerformed
private void generateRoundPairingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateRoundPairingsButtonActionPerformed
// comboBox.removeAllItems();
if(tourney.getDoubleElim() == true){
tourney.generateUpperMatches();
tourney.generateLowerMatches();
roundPairings.setText(tourney.toString());
for (int i = 0; i < tourney.getTourneyMatches().size(); i++) {
}
} else {
tourney.generateUpperMatches();
roundPairings.setText(tourney.toString());
}
}//GEN-LAST:event_generateRoundPairingsButtonActionPerformed
private void simulateSingleElimButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateSingleElimButtonActionPerformed
tourney.playSingleElimTournament();
roundPairings.setText(tourney.getMatchLog());
if(tourney.getBettingStatus() == true){
System.out.println(tourney.payOutBet());
accountBalance += tourney.payOutBet();
// balanceArea.setText(String.valueOf(accountBalance));
}
}//GEN-LAST:event_simulateSingleElimButtonActionPerformed
private void simulateRoundButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateRoundButtonActionPerformed
tourney.playRound();
System.out.println("in simulateRoundButton method");
System.out.println("tourney matches size: " + tourney.getTourneyMatches().size());
for (int i = 0; i < tourney.getTourneyMatches().size(); i++) {
System.out.println("betting status: " + tourney.getTourneyMatches().get(i).checkIfBetting());
if (tourney.getTourneyMatches().get(i).checkIfBetting() == true){
accountBalance += tourney.getTourneyMatches().get(i).getPayout();
}
}
}//GEN-LAST:event_simulateRoundButtonActionPerformed
private void newTourneyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTourneyButtonActionPerformed
tourney = new Tournament(placeHolder);
roundPairings.setText("");
tourneyParticipants.setText("");
tourneyPlayers.clear();
}//GEN-LAST:event_newTourneyButtonActionPerformed
private void bulkAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bulkAddButtonActionPerformed
if(numberBulkEntrants.getText().isEmpty() == false && eloBulkEntrants.getText().isEmpty() == false){
System.out.println("number of entrants: " + numberBulkEntrants.getText());
System.out.println("ELO of entrants: " + eloBulkEntrants.getText());
System.out.println(Integer.parseInt(numberBulkEntrants.getText()));
System.out.println(Integer.parseInt(eloBulkEntrants.getText()));
for (int i = 0; i < Integer.parseInt(numberBulkEntrants.getText()); i++) {
Player newPlayer = new Player(Integer.parseInt(eloBulkEntrants.getText()), "Player", String.valueOf(tourneyPlayers.size() + 1));
tourneyPlayers.add(newPlayer);
}
Collections.sort(tourneyPlayers);
tourney.setTourneyPlayers(tourneyPlayers);
tourneyParticipants.setText(tourneyPlayers.toString());
}
}//GEN-LAST:event_bulkAddButtonActionPerformed
private void addFromExcelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFromExcelButtonActionPerformed
String path = "/Users/natha_000/Documents/2020AustralianOpenTop32.xlsx";
try {
excelReader defaultFileReader = new excelReader(tourneyPlayers, path);
tourneyPlayers = defaultFileReader.readTop32();
tourney.setTourneyPlayers(tourneyPlayers);
tourneyParticipants.setText(tourneyPlayers.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
}//GEN-LAST:event_addFromExcelButtonActionPerformed
private void excelFileChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excelFileChooserButtonActionPerformed
excelFileChooser.showOpenDialog(null);
String filePath = excelFileChooser.getSelectedFile().getAbsolutePath(); // assigns path of file chosen by user to string so we can pass it to the excelReader constructor
System.out.println(filePath);
try {
excelReader chosenFileReader = new excelReader(tourneyPlayers, filePath);
tourneyPlayers = chosenFileReader.readTop32();
tourney.setTourneyPlayers(tourneyPlayers);
tourneyParticipants.setText(tourneyPlayers.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
}//GEN-LAST:event_excelFileChooserButtonActionPerformed
private void loadMatchHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMatchHistoryButtonActionPerformed
excelFileChooser.showOpenDialog(null);
String filePath = excelFileChooser.getSelectedFile().getAbsolutePath();
System.out.println(filePath);
try {
excelReader chosenFileReader = new excelReader(tourneyPlayers, filePath);
tourneyPlayers = chosenFileReader.readMatchHistory();
tourney.setTourneyPlayers(tourneyPlayers);
tourneyParticipants.setText(tourneyPlayers.toString());
} catch (IOException ex){
ex.printStackTrace();
}
}//GEN-LAST:event_loadMatchHistoryButtonActionPerformed
private void SimXTourniesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SimXTourniesButtonActionPerformed
int[] victoryCounter = new int[tourneyPlayers.size()];
double tourneyReps = Double.parseDouble(numTourniesToSim.getText()); // run tournament x number of times
for (int i = 0; i < tourneyReps; i++) {
for (Player player : tourneyPlayers) {
player.setELOToOriginal(); // set player ELOs back to original before simulating a tournament
}
Tournament newTourney = new Tournament(tourneyPlayers);
newTourney.playDoubleElimTournament();
System.out.println("Winning player: " + newTourney.getChampion());
Player winningPlayer = newTourney.getChampion();
System.out.println(winningPlayer.getFirstName());
int indexOfWinner = tourneyPlayers.indexOf(winningPlayer);
System.out.println("index of winner: " + indexOfWinner);
for (int j = 0; j < victoryCounter.length; j++) {
System.out.println(victoryCounter[j]);
}
victoryCounter[indexOfWinner]++; // each index of victorycounter corresponds with player's index in tourneyPlayers
System.out.println(victoryCounter[indexOfWinner]);
}
for (int i = 0; i < victoryCounter.length; i++) {
System.out.println("Tournies won by " + tourneyPlayers.get(i).getName() + ": " + victoryCounter[i] + "Player ELO score: " + tourneyPlayers.get(i).getELOscore());
}
double[] playerOdds = new double[tourneyPlayers.size()];
for (int i = 0; i < playerOdds.length; i++) {// go throu
playerOdds[i] = ((double)victoryCounter[i])/ tourneyReps; // converting value at victorycounter[i] so we get a percentage, not 0
if(victoryCounter[i] == 0){
playerOdds[i] = .01;
}
}
StringBuilder str = new StringBuilder();
for (int i = 0; i < playerOdds.length; i++) {
str.append( tourneyPlayers.get(i).getName() + "'s odds to win tournament: " + playerOdds[i] + "\n");
}
roundPairings.setText(str.toString());
}//GEN-LAST:event_SimXTourniesButtonActionPerformed
public double[] calculateOdds(){
int[] victoryCounter = new int[tourneyPlayers.size()];
double tourneyReps = 1000; // run tournament x number of times
for (int i = 0; i < tourneyReps; i++) {
for (Player player : tourneyPlayers) {
player.setELOToOriginal(); // set player ELOs back to original before simulating a tournament
}
Tournament newTourney = new Tournament(tourneyPlayers);
newTourney.playSingleElimTournament();
System.out.println("Winning player: " + newTourney.getChampion());
Player winningPlayer = newTourney.getChampion();
int indexOfWinner = tourneyPlayers.indexOf(winningPlayer);
victoryCounter[indexOfWinner]++; // each index of victorycounter corresponds with player's index in tourneyPlayers
System.out.println(victoryCounter[indexOfWinner]);
}
for (int i = 0; i < victoryCounter.length; i++) {
System.out.println("Tournies won by " + tourneyPlayers.get(i).getName() + ": " + victoryCounter[i] + "Player ELO score: " + tourneyPlayers.get(i).getELOscore());
}
double[] playerOdds = new double[tourneyPlayers.size()];
for (int i = 0; i < playerOdds.length; i++) {// go throu
playerOdds[i] = ((double)victoryCounter[i])/ tourneyReps; // converting value at victorycounter[i] so we get a percentage, not 0
if(victoryCounter[i] == 0){
playerOdds[i] = .01;
}
}
for (int i = 0; i < playerOdds.length; i++) {
System.out.println("Player at index " + i + "'s odds to win tournament: " + playerOdds[i]);
}
return playerOdds;
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton SimXTourniesButton;
private javax.swing.JButton addFromExcelButton;
private javax.swing.JButton addToTourneyButton;
private javax.swing.JButton bulkAddButton;
private javax.swing.JTextField eloBulkEntrants;
private javax.swing.JButton excelFileChooserButton;
private javax.swing.JButton generateRoundPairingsButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel9;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JPopupMenu jPopupMenu2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JButton loadMatchHistoryButton;
private javax.swing.JButton newTourneyButton;
private javax.swing.JTextField numTourniesToSim;
private javax.swing.JTextField numberBulkEntrants;
private javax.swing.JTextField playerELO;
private javax.swing.JTextField playerFirstName;
private javax.swing.JTextField playerLastName;
private javax.swing.JTextArea roundPairings;
private javax.swing.JButton simulateDoubleElimButton;
private javax.swing.JButton simulateRoundButton;
private javax.swing.JButton simulateSingleElimButton;
private javax.swing.JTextArea tourneyParticipants;
// End of variables declaration//GEN-END:variables
}