-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeam.py
68 lines (51 loc) · 1.91 KB
/
Team.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
import weakref
import Task
class Team:
Instance_Arr = []
# Teams start with a Score of 200.
Initial_Score = 200
# Penalty of 10 points for wrong submisisons.
Penalty = -10
def __init__(self, Name, Token):
# Each Team is given a private Token to authenticate their submissions.
self.__class__.Instance_Arr.append(weakref.proxy(self))
self.Name = Name
self.Score = Team.Initial_Score
self.Joker = None
self.Token = Token
self.Submission_History = set([])
def Pick_Joker(self, ID):
# Teams can Pick one of the Tasks to coint double.
# This choice can only be made once.
if self.Joker is None:
self.Joker = int(ID)
return True
else:
return False
def Submit(self, ID, Submission):
# Check, if Submission was seen before
if (ID,Submission) in self.Submission_History:
return 0
else:
self.Submission_History.add((ID,Submission))
# Check Solution
if Submission == Task[ID].Solution :
# Success. Get Points.
multiplier = 2 if ID == self.Joker else 1
points = Task[ID].get_current_value() * multiplier
self.Score = self.Score + points
Task[ID].Number_of_Solutions = Task[ID].Number_of_Solutions + 1
return points
else:
# Nope. Receive Penalty.
self.Score = self.Score + Team.Penalty if self.Score + Team.Penalty >= 0 else 0
return Team.Penalty
def __class_getitem__(cls, name):
return Team.Instance_Arr[ID-1]
def __repr__(self):
return f'{self.Name}'
def get_Team(Token):
for T in Team.Instance_Arr:
if T.Token == Token:
return T
return None