-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathteam.py
More file actions
74 lines (61 loc) · 2.24 KB
/
team.py
File metadata and controls
74 lines (61 loc) · 2.24 KB
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
import json
from player import Player
from zone import Zone
from typing import List
class Team():
def __init__(self, name, zones, custom_lineup = None):
self.team_name = name
self.players = self.get_players(zones, custom_lineup)
self.active_players = self.players
def get_players(self,zones, custom_lineup=None) -> List[Player]:
with open('data.json', 'r', encoding="utf-8") as file:
data = json.load(file)
if custom_lineup:
lineups = custom_lineup
else:
with open("lineups.json", "r") as file:
lineups = json.load(file)[self.team_name]
players = []
# TODO Refactor this code
for en,p in enumerate(lineups['att']):
name = p
team = self
try:
features = data[self.team_name][p]
except KeyError:
features = {}
position = "F"
players.append(Player(name,team,features,position, zones[6+en%3], zones[6+en%3] , False))
for en,p in enumerate(lineups['mid']):
name = p
team = self
try:
features = data[self.team_name][p]
except:
features = {}
position = "M"
players.append(Player(name,team,features,position, zones[3+en%3], zones[3+en%3] , False))
for en,p in enumerate(lineups['def']):
name = p
team = self
try:
features = data[self.team_name][p]
except:
features = {}
position = "D"
players.append(Player(name,team,features,position, zones[en%3], zones[en%3] , False))
p = lineups['goalkeeper']
name = p
team = self
try:
features = data[self.team_name][p]
except:
features = {}
position = "G"
players.append(Player(name,team,features,position, Zone("Gate",5,5,"Gate"), Zone("Gate",5,5,"Gate") , False))
assert len(players) == 11
return players
def set_active_players(self,names):
for p in self.players:
if p.name in names:
self.active_players.append(p)