From 71cb575746c111da984af5f7b66182c61ea81850 Mon Sep 17 00:00:00 2001 From: Ben Brostoff Date: Mon, 29 Jan 2024 08:26:39 -0500 Subject: [PATCH] Enforce C/1B --- draftfast/optimizer.py | 2 +- draftfast/rules.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/draftfast/optimizer.py b/draftfast/optimizer.py index 171cb94..799237d 100644 --- a/draftfast/optimizer.py +++ b/draftfast/optimizer.py @@ -39,7 +39,7 @@ def __init__( self.lineup_constraints = lineup_constraints self.banned_for_exposure = exposure_dict.get("banned", []) self.locked_for_exposure = exposure_dict.get("locked", []) - self.custom_rules = settings.custom_rules + self.custom_rules = (rule_set.custom_rules or []) + (settings.custom_rules or []) self.min_teams = rule_set.min_teams or settings.min_teams self.min_matchups = rule_set.min_matchups or settings.min_matchups self.position_per_team_rules = rule_set.position_per_team_rules diff --git a/draftfast/rules.py b/draftfast/rules.py index 03a6e1d..a0f8c9c 100644 --- a/draftfast/rules.py +++ b/draftfast/rules.py @@ -3,6 +3,7 @@ NBA_GENERAL_POSITIONS, POSITIONS_BY_SITE_BY_LEAGUE, ) +from draftfast.settings import CustomRule from draftfast.constants.roster_size import ROSTER_SIZE_BY_SITE_BY_SPORT from draftfast.constants.salary_cap import SALARY_CAP_BY_SITE_BY_LEAGUE @@ -27,6 +28,7 @@ def __init__( min_teams=None, min_matchups=None, position_per_team_rules=None, + custom_rules=None, game_type="classic", ): self.site = site @@ -43,6 +45,7 @@ def __init__( self.position_per_team_rules = position_per_team_rules self.min_teams = min_teams self.min_matchups = min_matchups + self.custom_rules = custom_rules def __eq__(self, other): if not other: @@ -247,6 +250,15 @@ def __eq__(self, other): position_per_team_rules=[ [lambda pos: "P" not in pos, 4], ], + + # Handle C/1B minimums, + custom_rules=[ + CustomRule( + group_a=lambda p: p.pos in ['C', '1B'], + group_b=lambda p: p, + comparison=lambda sum, a, b: sum(a) == 1, + ) + ] ) DK_SOCCER_RULE_SET = RuleSet(