-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPotentialSystem
228 lines (187 loc) · 10.3 KB
/
PotentialSystem
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
import pandas as pd
import random
############# Make Rookies have 'R' as YearsPro #############
file_path = 'Files/Madden25/IE/Season8/PotentialInput.xlsx'
df = pd.read_excel(file_path)
# Create the missing columns SkillPoints0, SkillPoints1, SkillPoints2, SkillPointsRookieRoll if they don't exist
for col_name in ['SkillPointsRookieRoll', 'SkillPoints0', 'SkillPoints1', 'SkillPoints2']:
if col_name not in df.columns:
df[col_name] = 0 # Initialize the column with zeros
# Fill NaN values in the 'SkillPointsRookieRoll' column with 0
df['SkillPointsRookieRoll'] = df['SkillPointsRookieRoll'].fillna(0)
# Define a function to calculate DevTraitChange
def calculate_dev_trait_change(row):
last_season = row['DevTraitLastSeason']
current = row['TraitDevelopment']
mapping = {
('Normal', 'Star'): 'NtoS',
('Normal', 'Superstar'): 'NtoSS',
('Normal', 'XFactor'): 'NtoXF',
('Star', 'Normal'): 'StoN',
('Star', 'Superstar'): 'StoSS',
('Star', 'XFactor'): 'StoXF',
('Superstar', 'Normal'): 'SStoN',
('Superstar', 'Star'): 'SStoS',
('Superstar', 'XFactor'): 'SStoXF',
('XFactor', 'Normal'): 'XFtoN',
('XFactor', 'Star'): 'XFtoS',
('XFactor', 'Superstar'): 'XFtoSS',
}
return mapping.get((last_season, current), '')
# Apply the function to the DataFrame
df['DevTraitChange'] = df.apply(calculate_dev_trait_change, axis=1)
def calculate_total_skill_points(row):
# Calculate TotalSkillPoints by summing SkillPoints0 to SkillPoints2 and SkillPointsRookieRoll
total_skill_points = row[['SkillPoints0', 'SkillPoints1', 'SkillPoints2', 'SkillPointsRookieRoll']].sum()
return total_skill_points
def calculate_age_based_skill_points(row):
if row['YearsPro'] != 'R':
return row # Skip processing for players who are not rookies
# Only assign values once for SkillPoints0, SkillPoints1, and SkillPoints2
if (
row['ContractStatus'] in ['Signed', 'FreeAgent', 'PracticeSquad']
and row['Age'] in [20, 21, 22, 23, 24, 25]
and row['Position'] not in ['QB', 'K', 'P']
):
skill_points_columns = ['SkillPoints0', 'SkillPoints1', 'SkillPoints2']
for col in skill_points_columns:
development_trait = row['TraitDevelopment']
if development_trait == 'Normal':
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.00, 0.70, 0.20, 0.05, 0.025, 0.01, 0.01, 0.005, 0.00] # Avg = 1.5 #
elif development_trait == 'Star':
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.00, 0.10, 0.20, 0.45, 0.15, 0.05, 0.03, 0.015, 0.005] # Avg ~ 3 #
elif development_trait in ['Superstar', 'XFactor']:
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.00, 0.00, 0.00, 0.20, 0.54, 0.15, 0.08, 0.02, 0.01] # Avg = 4.25 #
skill_points = random.choices(chances, probabilities)[0]
row[col] += skill_points # Add skill points to the corresponding column
return row
def calculate_rookie_skill_points(row):
if row['YearsPro'] != 'R':
return row['SkillPointsRookieRoll'] # Skip processing for players who are not rookies
if row['YearsPro'] == 'R' and row['ContractStatus'] in ['Signed', 'FreeAgent', 'PracticeSquad']:
development_trait = row['TraitDevelopment']
if development_trait == 'Normal':
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.20, 0.41, 0.20, 0.12, 0.04, 0.017, 0.008, 0.004, 0.001] # Average = 1.5 #
elif development_trait == 'Star':
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.00, 0.125, 0.45, 0.125, 0.125, 0.075, 0.05, 0.035, 0.015] # Average = 3 #
elif development_trait in ['Superstar', 'XFactor']:
chances = [0, 1, 2, 3, 4, 5, 6, 8, 10]
probabilities = [0.00, 0.00, 0.00, 0.40, 0.25, 0.125, 0.10, 0.075, 0.05] # Average = 4.5 #
skill_points = random.choices(chances, probabilities)[0]
return skill_points
return row['SkillPointsRookieRoll'] # Keep the existing skill points if conditions are not met.
def calculate_skill_points_rookieroll(row):
if row['YearsPro'] == 'R': # Only process players who are rookies (YearsPro == 'R')
skill_points_rookie_roll = row['SkillPointsRookieRoll']
skill_points_columns = ['SkillPoints0', 'SkillPoints1', 'SkillPoints2']
for col in skill_points_columns:
skill_points = row[col]
chance = random.random()
if chance < 0.30: # 30% chance to take out 0%
pass
elif 0.30 <= chance < 0.60: # 30% chance to take out 25%
amount_taken = min(skill_points, int(skill_points_rookie_roll * 0.25)) # Take minimum of the two values
skill_points -= amount_taken # Subtract the amount taken from the current column
skill_points_rookie_roll += amount_taken # Add the amount taken to SkillPointsRookieRoll
elif 0.60 <= chance < 0.90: # 30% chance to take out 50%
amount_taken = min(skill_points, int(skill_points_rookie_roll * 0.5)) # Take minimum of the two values
skill_points -= amount_taken # Subtract the amount taken from the current column
skill_points_rookie_roll += amount_taken # Add the amount taken to SkillPointsRookieRoll
else: # 10% chance to take out 75%
amount_taken = min(skill_points, int(skill_points_rookie_roll * 0.75)) # Take minimum of the two values
skill_points -= amount_taken # Subtract the amount taken from the current column
skill_points_rookie_roll += amount_taken # Add the amount taken to SkillPointsRookieRoll
# Ensure the values in the skill points columns are never less than 0
row[col] = max(skill_points, 0)
# Update the SkillPointsRookieRoll in the row
row['SkillPointsRookieRoll'] = skill_points_rookie_roll
return row['SkillPointsRookieRoll'] if row['YearsPro'] == 'R' else row['SkillPoints_Rookie'] # Keep the existing skill points if YearsPro != 'R'
# Apply the functions to the DataFrame
df = df.apply(calculate_age_based_skill_points, axis=1)
df['SkillPointsRookieRoll'] = df.apply(calculate_rookie_skill_points, axis=1)
df['TotalSkillPoints'] = df.apply(calculate_total_skill_points, axis=1)
# Calculate SkillPoints_Rookie by summing SkillPointsRookieRoll and random amounts from SkillPoints0 to SkillPoints2
df['SkillPoints_Rookie'] = df.apply(calculate_skill_points_rookieroll, axis=1)
def calculate_remaining_skill_points(row):
if row['YearsPro'] != 'R':
return row # Skip processing for players who are not rookies
if row['YearsPro'] == 'R':
# Calculate RemainingSkillPoints by subtracting SkillPointsRookieRoll from TotalSkillPoints
row['RemainingSkillPoints'] = row['TotalSkillPoints'] - row['SkillPoints_Rookie']
# Ensure RemainingSkillPoints is non-negative
row['RemainingSkillPoints'] = max(row['RemainingSkillPoints'], 0)
return row
def distribute_remaining_skill_points(row):
if row['YearsPro'] != 'R':
return row # Skip processing for players who are not rookies
if row['YearsPro'] == 'R':
remaining_points = row['RemainingSkillPoints']
new_skill_points = [0, 0, 0]
while True:
total_new_skill_points = sum(new_skill_points)
# Ensure the sum of NewSkillPoints0 through NewSkillPoints2 equals RemainingSkillPoints
if total_new_skill_points == remaining_points and all(x >= 0 for x in new_skill_points):
break
new_skill_points = [random.randint(0, remaining_points) for _ in range(3)]
if sum(new_skill_points) > remaining_points:
# Randomly pick one of the new_skill_points to adjust
adjust_index = random.choice([0, 1, 2])
new_skill_points[adjust_index] -= sum(new_skill_points) - remaining_points
# Assign the new skill points to the respective columns
row['NewSkillPoints0'], row['NewSkillPoints1'], row['NewSkillPoints2'] = new_skill_points
return row
df = df.apply(calculate_remaining_skill_points, axis=1)
df = df.apply(distribute_remaining_skill_points, axis=1)
# Define a function to adjust NewSkillPoints based on DevTraitChange
def adjust_skill_points_based_on_dev_trait(row):
dev_trait_change = row['DevTraitChange']
skill_points_to_add = {
'NtoS': 1,
'NtoSS': 2,
'NtoXF': 2,
'StoN': -1,
'StoSS': 1,
'StoXF': 1,
'SStoN': -2,
'SStoS': -1,
'SStoXF': 0,
'XFtoN': -2,
'XFtoS': -1,
'XFtoSS': 0,
}
if row['YearsPro'] == 0:
# Adjust all NewSkillPoints0, NewSkillPoints1, NewSkillPoints2 based on DevTraitChange
for i in range(3): # Iterate over NewSkillPoints0 to NewSkillPoints2
col_name = f'NewSkillPoints{i}'
current_points = row[col_name]
change = skill_points_to_add.get(dev_trait_change, 0)
new_points = current_points + change
# Ensure new points are non-negative
row[col_name] = max(new_points, 0)
elif row['YearsPro'] == 1:
# Adjust only NewSkillPoints1 and NewSkillPoints2 based on DevTraitChange
for i in range(1, 3): # Iterate over NewSkillPoints1 to NewSkillPoints2
col_name = f'NewSkillPoints{i}'
current_points = row[col_name]
change = skill_points_to_add.get(dev_trait_change, 0)
new_points = current_points + change
# Ensure new points are non-negative
row[col_name] = max(new_points, 0)
elif row['YearsPro'] == 2:
# Adjust only NewSkillPoints2 based on DevTraitChange
col_name = 'NewSkillPoints2'
current_points = row[col_name]
change = skill_points_to_add.get(dev_trait_change, 0)
new_points = current_points + change
# Ensure new points are non-negative
row[col_name] = max(new_points, 0)
return row
# Apply the function to the DataFrame
df = df.apply(adjust_skill_points_based_on_dev_trait, axis=1)
# Save the modified DataFrame to Excel
df.to_excel('Files/Madden25/IE/Season8/Player_Potential.xlsx', index=False)