@@ -573,34 +573,28 @@ def suggest_switch(self, teams, gametype):
573573 """Suggest a switch based on average team ratings."""
574574
575575 if gametype == "ad" :
576- # when there is an even amount of players with elo >= AD_ELO_THRESHOLD
577- # make sure they are divided evenly over the teams
578- elos_red = [
579- (p , self .ratings [p .steam_id ][gametype ]["elo" ]) for p in teams ["red" ]
580- ]
581- elos_red_high = sorted ([p for p in elos_red if p [1 ] >= AD_ELO_THRESHOLD ], key = lambda x : x [1 ])
582- elos_red_low = sorted ([p for p in elos_red if p [1 ] < AD_ELO_THRESHOLD ], key = lambda x : x [1 ])
583- nr_elos_red_high = len (elos_red_high )
584- elos_blue = [
585- (p , self .ratings [p .steam_id ][gametype ]["elo" ]) for p in teams ["blue" ]
586- ]
587- elos_blue_high = sorted ([p for p in elos_blue if p [1 ] >= AD_ELO_THRESHOLD ], key = lambda x : x [1 ])
588- elos_blue_low = sorted ([p for p in elos_blue if p [1 ] < AD_ELO_THRESHOLD ], key = lambda x : x [1 ])
589- nr_elos_blue_high = len (elos_blue_high )
590- total_high_elos = nr_elos_red_high + nr_elos_blue_high
591- diff_high_elos = nr_elos_red_high - nr_elos_blue_high
592-
593- if total_high_elos > 1 :
594- if total_high_elos % 2 :
595- if diff_high_elos >= 2 :
596- return ((elos_red_high [- 1 ], elos_blue_low [- 1 ]), 0 )
597- elif diff_high_elos <= - 2 :
598- return ((elos_red_low [- 1 ], elos_blue_high [- 1 ]), 0 )
599- else :
600- if diff_high_elos >= 1 :
601- return ((elos_red_high [- 1 ], elos_blue_low [- 1 ]), 0 )
602- elif diff_high_elos <= - 1 :
603- return ((elos_red_low [- 1 ], elos_blue_high [- 1 ]), 0 )
576+ # Special handling for AD: ensure high-ELO players are distributed evenly
577+ red_high = [p for p in teams ["red" ] if self .ratings [p .steam_id ][gametype ]["elo" ] >= AD_ELO_THRESHOLD ]
578+ blue_high = [p for p in teams ["blue" ] if self .ratings [p .steam_id ][gametype ]["elo" ] >= AD_ELO_THRESHOLD ]
579+ red_low = [p for p in teams ["red" ] if self .ratings [p .steam_id ][gametype ]["elo" ] < AD_ELO_THRESHOLD ]
580+ blue_low = [p for p in teams ["blue" ] if self .ratings [p .steam_id ][gametype ]["elo" ] < AD_ELO_THRESHOLD ]
581+
582+ high_diff = len (red_high ) - len (blue_high )
583+ total_high = len (red_high ) + len (blue_high )
584+
585+ # If we have high-ELO players and they're unevenly distributed
586+ if total_high >= 2 and abs (high_diff ) >= 1 :
587+ # Move a high-ELO player from the team with more to balance with a low-ELO player
588+ if high_diff > 0 and blue_low : # Red has more high-ELO players
589+ # Sort to get the lowest high-ELO from red and highest low-ELO from blue
590+ red_high_sorted = sorted (red_high , key = lambda p : self .ratings [p .steam_id ][gametype ]["elo" ])
591+ blue_low_sorted = sorted (blue_low , key = lambda p : self .ratings [p .steam_id ][gametype ]["elo" ], reverse = True )
592+ return ((red_high_sorted [0 ], blue_low_sorted [0 ]), abs (high_diff ) * 100 )
593+ elif high_diff < 0 and red_low : # Blue has more high-ELO players
594+ # Sort to get the lowest high-ELO from blue and highest low-ELO from red
595+ blue_high_sorted = sorted (blue_high , key = lambda p : self .ratings [p .steam_id ][gametype ]["elo" ])
596+ red_low_sorted = sorted (red_low , key = lambda p : self .ratings [p .steam_id ][gametype ]["elo" ], reverse = True )
597+ return ((red_low_sorted [0 ], blue_high_sorted [0 ]), abs (high_diff ) * 100 )
604598
605599
606600 avg_red = self .team_average (teams ["red" ], gametype )
0 commit comments