This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBestPicks.py
executable file
·553 lines (496 loc) · 24.8 KB
/
BestPicks.py
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
#!python
# Evaluate the best pick for the given role and team
import os
import sys
from PyQt5.QtCore import Qt
import numpy as np
from PyQt5.QtWidgets import *
from collections import OrderedDict
import Modes
import Networks
sys._excepthook = sys.excepthook
class UnrecognizedMode(Exception):
pass
def my_exception_hook(exctype, value, traceback):
# Print the error and traceback
print(exctype, value, traceback)
# Call the normal Exception hook after
# noinspection PyProtectedMember
sys._excepthook(exctype, value, traceback)
sys.exit(1)
# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook
class App(QDialog):
# noinspection PyArgumentList,PyUnresolvedReferences
def __init__(self, mode, network):
super().__init__()
self.title = 'LoLAnalyzer - patch {}'.format(mode.learning_patches[-1])
self.left = 10
self.top = 10
self.width = 800
self.height = 600
self.mode = mode
self.network = network
self.yourTeam = None
self.yourRole = None
self.yourPick = None
self.pick_order = None
self.role_order = None
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Main Layout
mainBoxLayout = QGridLayout()
self.setLayout(mainBoxLayout)
# Bans Layout
bansGB = QGroupBox('Bans')
BansLayout = QGridLayout()
self.player1Ban = QComboBox()
self.player1Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player1Ban, 0, 0)
self.player2Ban = QComboBox()
self.player2Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player2Ban, 0, 1)
self.player3Ban = QComboBox()
self.player3Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player3Ban, 0, 2)
self.player4Ban = QComboBox()
self.player4Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player4Ban, 0, 3)
self.player5Ban = QComboBox()
self.player5Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player5Ban, 0, 4)
self.player6Ban = QComboBox()
self.player6Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player6Ban, 1, 0)
self.player7Ban = QComboBox()
self.player7Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player7Ban, 1, 1)
self.player8Ban = QComboBox()
self.player8Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player8Ban, 1, 2)
self.player9Ban = QComboBox()
self.player9Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player9Ban, 1, 3)
self.player10Ban = QComboBox()
self.player10Ban.addItems(self.mode.BP_CHAMPIONS)
BansLayout.addWidget(self.player10Ban, 1, 4)
bansGB.setLayout(BansLayout)
mainBoxLayout.addWidget(bansGB, 0, 0, 1, 6)
# Your team picks Layout
yourTeamGB = QGroupBox('Your Team')
yourTeamLayout = QGridLayout()
self.player1Pick = QComboBox()
self.player1Pick.addItems(self.mode.BP_CHAMPIONS)
self.player1Pick.currentTextChanged.connect(self.pick)
yourTeamLayout.addWidget(self.player1Pick, 0, 0)
self.player1Role = QComboBox()
self.player1Role.addItems(self.mode.BP_ROLES)
yourTeamLayout.addWidget(self.player1Role, 0, 1)
self.player2Pick = QComboBox()
self.player2Pick.addItems(self.mode.BP_CHAMPIONS)
self.player2Pick.currentTextChanged.connect(self.pick)
yourTeamLayout.addWidget(self.player2Pick, 1, 0)
self.player2Role = QComboBox()
self.player2Role.addItems(self.mode.BP_ROLES)
yourTeamLayout.addWidget(self.player2Role, 1, 1)
self.player3Pick = QComboBox()
self.player3Pick.addItems(self.mode.BP_CHAMPIONS)
self.player3Pick.currentTextChanged.connect(self.pick)
yourTeamLayout.addWidget(self.player3Pick, 2, 0)
self.player3Role = QComboBox()
self.player3Role.addItems(self.mode.BP_ROLES)
yourTeamLayout.addWidget(self.player3Role, 2, 1)
self.player4Pick = QComboBox()
self.player4Pick.addItems(self.mode.BP_CHAMPIONS)
self.player4Pick.currentTextChanged.connect(self.pick)
yourTeamLayout.addWidget(self.player4Pick, 3, 0)
self.player4Role = QComboBox()
self.player4Role.addItems(self.mode.BP_ROLES)
yourTeamLayout.addWidget(self.player4Role, 3, 1)
self.player5Pick = QComboBox()
self.player5Pick.addItems(self.mode.BP_CHAMPIONS)
self.player5Pick.currentTextChanged.connect(self.pick)
yourTeamLayout.addWidget(self.player5Pick, 4, 0)
self.player5Role = QComboBox()
self.player5Role.addItems(self.mode.BP_ROLES)
yourTeamLayout.addWidget(self.player5Role, 4, 1)
yourTeamGB.setLayout(yourTeamLayout)
mainBoxLayout.addWidget(yourTeamGB, 1, 0)
# Enemy team picks Layout
enemyTeamGB = QGroupBox('Enemy Team')
enemyTeamLayout = QGridLayout()
self.player6Pick = QComboBox()
self.player6Pick.addItems(self.mode.BP_CHAMPIONS)
self.player6Pick.currentTextChanged.connect(self.pick)
enemyTeamLayout.addWidget(self.player6Pick, 0, 0)
self.player6Role = QComboBox()
self.player6Role.addItems(self.mode.BP_ROLES)
enemyTeamLayout.addWidget(self.player6Role, 0, 1)
self.player7Pick = QComboBox()
self.player7Pick.addItems(self.mode.BP_CHAMPIONS)
self.player7Pick.currentTextChanged.connect(self.pick)
enemyTeamLayout.addWidget(self.player7Pick, 1, 0)
self.player7Role = QComboBox()
self.player7Role.addItems(self.mode.BP_ROLES)
enemyTeamLayout.addWidget(self.player7Role, 1, 1)
self.player8Pick = QComboBox()
self.player8Pick.addItems(self.mode.BP_CHAMPIONS)
self.player8Pick.currentTextChanged.connect(self.pick)
enemyTeamLayout.addWidget(self.player8Pick, 2, 0)
self.player8Role = QComboBox()
self.player8Role.addItems(self.mode.BP_ROLES)
enemyTeamLayout.addWidget(self.player8Role, 2, 1)
self.player9Pick = QComboBox()
self.player9Pick.addItems(self.mode.BP_CHAMPIONS)
self.player9Pick.currentTextChanged.connect(self.pick)
enemyTeamLayout.addWidget(self.player9Pick, 3, 0)
self.player9Role = QComboBox()
self.player9Role.addItems(self.mode.BP_ROLES)
enemyTeamLayout.addWidget(self.player9Role, 3, 1)
self.player10Pick = QComboBox()
self.player10Pick.addItems(self.mode.BP_CHAMPIONS)
self.player10Pick.currentTextChanged.connect(self.pick)
enemyTeamLayout.addWidget(self.player10Pick, 4, 0)
self.player10Role = QComboBox()
self.player10Role.addItems(self.mode.BP_ROLES)
enemyTeamLayout.addWidget(self.player10Role, 4, 1)
enemyTeamGB.setLayout(enemyTeamLayout)
mainBoxLayout.addWidget(enemyTeamGB, 1, 5)
# Best picks Layout
bestPicksGB = QGroupBox('Best Picks')
bestPicksLayout = QGridLayout()
yourTeamButtonGroup = QButtonGroup()
blueTeamButton = QRadioButton('Blue Team')
redTeamButton = QRadioButton('Red Team')
blueTeamButton.setChecked(True)
yourTeamButtonGroup.addButton(blueTeamButton)
yourTeamButtonGroup.addButton(redTeamButton)
yourTeamButtonGroup.buttonClicked['QAbstractButton *'].connect(self.teamChoice)
bestPicksLayout.addWidget(blueTeamButton, 0, 0)
bestPicksLayout.addWidget(redTeamButton, 1, 0)
self.evaluateButton = QPushButton('Wait...')
self.evaluateButton.setEnabled(False)
# noinspection PyUnresolvedReferences
self.evaluateButton.clicked.connect(lambda: self.evaluate())
bestPicksLayout.addWidget(self.evaluateButton, 0, 1)
self.generateButton = QPushButton('Wait...')
self.generateButton.setEnabled(False)
# noinspection PyUnresolvedReferences
self.generateButton.clicked.connect(lambda: self.generate())
bestPicksLayout.addWidget(self.generateButton, 1, 1)
resetButton = QPushButton('Reset')
resetButton.clicked.connect(lambda: self.teamReset())
bestPicksLayout.addWidget(resetButton, 2, 1)
self.results = QTableWidget()
self.results.setRowCount(0) # delete previous data
self.results.setColumnCount(0)
# self.results.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.results.verticalHeader().hide()
bestPicksLayout.addWidget(self.results, 3, 0, 1, 2)
bestPicksGB.setLayout(bestPicksLayout)
mainBoxLayout.addWidget(bestPicksGB, 1, 1, 1, 4)
# Centering window
qtRectangle = self.frameGeometry()
centerPoint = QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
self.show()
self.teamChoice(blueTeamButton)
self.teamReset()
self.buildNetwork()
def teamChoice(self, button):
# mirror the position for the other team
# for the sake of simplicity, we reset and do as if we selected 1 by 1 the champions
if self.yourTeam == button.text()[0]: # same team. I wonder if it's possible to get there
return
self.yourTeam = button.text()[0]
# saving current situation, we already keep in mind who's going where
exchanges = [(self.player6Pick, self.player1Pick.currentIndex()),
(self.player7Pick, self.player2Pick.currentIndex()),
(self.player8Pick, self.player3Pick.currentIndex()),
(self.player9Pick, self.player4Pick.currentIndex()),
(self.player10Pick, self.player5Pick.currentIndex()),
(self.player1Pick, self.player6Pick.currentIndex()),
(self.player2Pick, self.player7Pick.currentIndex()),
(self.player3Pick, self.player8Pick.currentIndex()),
(self.player4Pick, self.player9Pick.currentIndex()),
(self.player5Pick, self.player10Pick.currentIndex())]
p1r = self.player1Role.currentIndex()
p2r = self.player2Role.currentIndex()
p3r = self.player3Role.currentIndex()
p4r = self.player4Role.currentIndex()
p5r = self.player5Role.currentIndex()
p6r = self.player6Role.currentIndex()
p7r = self.player7Role.currentIndex()
p8r = self.player8Role.currentIndex()
p9r = self.player9Role.currentIndex()
p10r = self.player10Role.currentIndex()
self.teamReset()
# mirroring roles is straightforward
self.player1Role.setCurrentIndex(p6r)
self.player2Role.setCurrentIndex(p7r)
self.player3Role.setCurrentIndex(p8r)
self.player4Role.setCurrentIndex(p9r)
self.player5Role.setCurrentIndex(p10r)
self.player6Role.setCurrentIndex(p1r)
self.player7Role.setCurrentIndex(p2r)
self.player8Role.setCurrentIndex(p3r)
self.player9Role.setCurrentIndex(p4r)
self.player10Role.setCurrentIndex(p5r)
# now we simply pick according to pick order
for p in self.pick_order:
for e in exchanges:
if p == e[0] and e[1] != 0:
p.setCurrentIndex(e[1])
self.pick(sender=p)
break
def teamReset(self):
self.player1Pick.setEnabled(False)
self.player1Pick.setCurrentIndex(0)
self.player1Role.setEnabled(True)
self.player1Role.setCurrentIndex(0)
self.player2Pick.setEnabled(False)
self.player2Pick.setCurrentIndex(0)
self.player2Role.setEnabled(True)
self.player2Role.setCurrentIndex(0)
self.player3Pick.setEnabled(False)
self.player3Pick.setCurrentIndex(0)
self.player3Role.setEnabled(True)
self.player3Role.setCurrentIndex(0)
self.player4Pick.setEnabled(False)
self.player4Pick.setCurrentIndex(0)
self.player4Role.setEnabled(True)
self.player4Role.setCurrentIndex(0)
self.player5Pick.setEnabled(False)
self.player5Pick.setCurrentIndex(0)
self.player5Role.setEnabled(True)
self.player5Role.setCurrentIndex(0)
self.player6Pick.setEnabled(False)
self.player6Pick.setCurrentIndex(0)
self.player6Role.setEnabled(True)
self.player6Role.setCurrentIndex(0)
self.player7Pick.setEnabled(False)
self.player7Pick.setCurrentIndex(0)
self.player7Role.setEnabled(True)
self.player7Role.setCurrentIndex(0)
self.player8Pick.setEnabled(False)
self.player8Pick.setCurrentIndex(0)
self.player8Role.setEnabled(True)
self.player8Role.setCurrentIndex(0)
self.player9Pick.setEnabled(False)
self.player9Pick.setCurrentIndex(0)
self.player9Role.setEnabled(True)
self.player9Role.setCurrentIndex(0)
self.player10Pick.setEnabled(False)
self.player10Pick.setCurrentIndex(0)
self.player10Role.setEnabled(True)
self.player10Role.setCurrentIndex(0)
if self.yourTeam == 'B':
self.player1Pick.setEnabled(True)
self.generateButton.setEnabled(True)
self.pick_order = [self.player1Pick, self.player6Pick, self.player7Pick, self.player2Pick, self.player3Pick, self.player8Pick,
self.player9Pick, self.player4Pick, self.player5Pick, self.player10Pick]
self.role_order = [self.player1Role, self.player6Role, self.player7Role, self.player2Role, self.player3Role, self.player8Role,
self.player9Role, self.player4Role, self.player5Role, self.player10Role]
self.yourRole = self.player1Role # blue team is first pick
self.yourPick = self.player1Pick
else:
self.player6Pick.setEnabled(True)
self.generateButton.setEnabled(False)
self.pick_order = [self.player6Pick, self.player1Pick, self.player2Pick, self.player7Pick, self.player8Pick, self.player3Pick,
self.player4Pick, self.player9Pick, self.player10Pick, self.player5Pick]
self.role_order = [self.player6Role, self.player1Role, self.player2Role, self.player7Role, self.player8Role, self.player3Role,
self.player4Role, self.player9Role, self.player10Role, self.player5Role]
self.yourRole = None
self.yourPick = None
def pick(self, champ='', sender=None): # first arg is the combobox text, eg 'aatrox'
if sender is None: # called from button
sender = self.sender()
i = self.pick_order.index(sender)
if sender.currentIndex() != 0:
if i + 1 < len(self.pick_order):
self.pick_order[i + 1].setEnabled(True)
else:
for j in range(i + 1, len(self.pick_order)):
self.pick_order[i + 1].setCurrentIndex(0)
self.pick_order[i + 1].setEnabled(False)
self.role_order[i + 1].setCurrentIndex(0)
# get the last available combobox, if in player 1-5 then we set self.yourRole, else disable generation
l = [playerPick.isEnabled() for playerPick in self.pick_order]
currentPickIndex = -1 if False not in l else l.index(False) - 1
if self.pick_order[currentPickIndex] in [self.player1Pick, self.player2Pick, self.player3Pick, self.player4Pick, self.player5Pick]:
self.generateButton.setEnabled(True)
self.yourRole = self.role_order[currentPickIndex]
self.yourPick = self.pick_order[currentPickIndex]
else:
self.generateButton.setEnabled(False)
self.yourRole = None
self.yourPick = None
def buildNetwork(self):
import keras
keras.backend.set_learning_phase(0) # evaluation = testing phase
model_file = os.path.join(self.mode.CKPT_DIR, str(self.network) + '.h5')
print('-- New evaluating Session --', file=sys.stderr)
print(model_file, file=sys.stderr)
if not os.path.isfile(model_file):
print('Cannot find {}'.format(model_file), file=sys.stderr)
return
self.network.model = keras.models.load_model(model_file)
self.generateButton.setText('Analyze')
self.generateButton.setEnabled(True)
self.evaluateButton.setText('Evaluate')
self.evaluateButton.setEnabled(True)
def evaluate(self):
print('evaluating for team', str(self.yourTeam), file=sys.stderr)
bans = [str(self.player1Ban.currentText()), str(self.player2Ban.currentText()), str(self.player3Ban.currentText()),
str(self.player4Ban.currentText()), str(self.player5Ban.currentText()), str(self.player6Ban.currentText()),
str(self.player7Ban.currentText()), str(self.player8Ban.currentText()), str(self.player9Ban.currentText()),
str(self.player10Ban.currentText())]
print('bans', bans, file=sys.stderr)
picks = [
(str(self.player1Pick.currentText()), str(self.player1Role.currentText()), 1),
(str(self.player2Pick.currentText()), str(self.player2Role.currentText()), 1),
(str(self.player3Pick.currentText()), str(self.player3Role.currentText()), 1),
(str(self.player4Pick.currentText()), str(self.player4Role.currentText()), 1),
(str(self.player5Pick.currentText()), str(self.player5Role.currentText()), 1),
(str(self.player6Pick.currentText()), str(self.player6Role.currentText()), 0),
(str(self.player7Pick.currentText()), str(self.player7Role.currentText()), 0),
(str(self.player8Pick.currentText()), str(self.player8Role.currentText()), 0),
(str(self.player9Pick.currentText()), str(self.player9Role.currentText()), 0),
(str(self.player10Pick.currentText()), str(self.player10Role.currentText()), 0),
]
print('picks', picks, file=sys.stderr)
for (p_, r_, _) in picks:
if p_[0] != '.' and r_[0] == '.':
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText('Please enter role for {}'.format(p_))
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
return
currentState = OrderedDict()
currentState.update([('s_' + champ, 'A') for champ in self.mode.CHAMPIONS_LABEL])
currentState.update([('p_' + champ, 'N') for champ in self.mode.CHAMPIONS_LABEL])
for ban in bans:
if ban[0] != '.':
currentState['s_' + ban] = 'N'
for (pick, role, team) in picks:
if pick[0] != '.':
if self.yourTeam == 'B':
currentState['s_' + pick] = 'B' if team else 'R'
else:
currentState['s_' + pick] = 'R' if team else 'B'
currentState['p_' + pick] = role[0]
data = np.array([self.mode.row_data(currentState, False, True)])
# print(self.mode.row_data(currentState, False, True))
pred_values = self.network.model.predict(data, batch_size=len(data))[0]
if self.yourTeam == 'R':
pred_values = 1 - pred_values
pred_values *= 100
self.results.setRowCount(1)
self.results.setColumnCount(1)
self.results.clear()
self.results.setHorizontalHeaderLabels(['winrate'])
winrate = QTableWidgetItem('%.2f' % pred_values)
winrate.setTextAlignment(Qt.AlignRight)
self.results.setItem(0, 0, winrate)
header = self.results.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.Stretch)
def generate(self):
if not self.yourPick or self.yourPick.currentText()[0] != '.':
print('Nothing to analyze', file=sys.stderr)
return
yourRole = str(self.yourRole.currentText())
if yourRole[0] == '.':
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText('You need to enter a role!')
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
return
print('generating for:', yourRole, file=sys.stderr)
bans = [str(self.player1Ban.currentText()), str(self.player2Ban.currentText()), str(self.player3Ban.currentText()),
str(self.player4Ban.currentText()), str(self.player5Ban.currentText()), str(self.player6Ban.currentText()),
str(self.player7Ban.currentText()), str(self.player8Ban.currentText()), str(self.player9Ban.currentText()),
str(self.player10Ban.currentText())]
print('bans', bans, file=sys.stderr)
picks = [
(str(self.player1Pick.currentText()), str(self.player1Role.currentText()), 1),
(str(self.player2Pick.currentText()), str(self.player2Role.currentText()), 1),
(str(self.player3Pick.currentText()), str(self.player3Role.currentText()), 1),
(str(self.player4Pick.currentText()), str(self.player4Role.currentText()), 1),
(str(self.player5Pick.currentText()), str(self.player5Role.currentText()), 1),
(str(self.player6Pick.currentText()), str(self.player6Role.currentText()), 0),
(str(self.player7Pick.currentText()), str(self.player7Role.currentText()), 0),
(str(self.player8Pick.currentText()), str(self.player8Role.currentText()), 0),
(str(self.player9Pick.currentText()), str(self.player9Role.currentText()), 0),
(str(self.player10Pick.currentText()), str(self.player10Role.currentText()), 0),
]
print('picks', picks, file=sys.stderr)
for (p_, r_, _) in picks:
if p_[0] != '.' and r_[0] == '.':
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText('Please enter role for {}'.format(p_))
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
return
currentState = OrderedDict()
currentState.update([('s_' + champ, 'A') for champ in self.mode.CHAMPIONS_LABEL])
currentState.update([('p_' + champ, 'N') for champ in self.mode.CHAMPIONS_LABEL])
for ban in bans:
if ban[0] != '.':
currentState['s_' + ban] = 'N'
for (pick, role, team) in picks:
if pick[0] != '.':
if self.yourTeam == 'B':
currentState['s_' + pick] = 'B' if team else 'R'
else:
currentState['s_' + pick] = 'R' if team else 'B'
currentState['p_' + pick] = role[0]
# print(currentState, file=sys.stderr)
possibleStates = []
champions = []
POSSIBLE_CHAMPS = self.mode.ROLES_CHAMP[yourRole].split(',')
for champ in POSSIBLE_CHAMPS:
if currentState['s_' + champ] != 'A': # not available (banned or picked)
continue
state = OrderedDict(currentState)
state['s_' + champ] = self.yourTeam
state['p_' + champ] = yourRole[0]
possibleStates.append(state)
champions.append(champ)
data = []
for state in possibleStates:
data.append(self.mode.row_data(state, False, True))
pred_values = self.network.model.predict(np.array(data), batch_size=len(data))
best_champs = [(champions[k], 100 * (pred_values[k] if self.yourTeam == 'B' else 1 - pred_values[k])) for k in range(len(champions))]
best_champs = sorted(best_champs, key=lambda x: x[1], reverse=True)
# print(best_champs, file=sys.stderr)
self.results.setRowCount(len(best_champs))
self.results.setColumnCount(3)
self.results.clear()
self.results.setHorizontalHeaderLabels(['Champion', 'Winrate', 'Popularity'])
for k in range(len(best_champs)):
self.results.setItem(k, 0, QTableWidgetItem(best_champs[k][0]))
winrate = QTableWidgetItem('%.2f' % (best_champs[k][1]))
winrate.setTextAlignment(Qt.AlignRight)
self.results.setItem(k, 1, winrate)
popularity = QTableWidgetItem(self.mode.config[yourRole.upper()][best_champs[k][0]])
popularity.setTextAlignment(Qt.AlignRight)
self.results.setItem(k, 2, popularity)
header = self.results.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.Stretch)
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
def run(mode, network):
app = QApplication(sys.argv)
App(mode, network)
try:
sys.exit(app.exec_())
except Exception as e:
print(e)
if __name__ == '__main__':
m = Modes.ABR_TJMCS_Mode(['9.1','9.2','9.3','9.4','9.5','9.6','9.7'])
n = Networks.DenseUniform(mode=m, n_hidden_layers=5, NN=1024, dropout=0.2, batch_size=1000, report=1)
run(m, n)