{"id":65,"date":"2025-11-14T15:07:15","date_gmt":"2025-11-14T15:07:15","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/l_smith\/?p=65"},"modified":"2025-11-14T15:07:15","modified_gmt":"2025-11-14T15:07:15","slug":"week-9-day-3-final","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/l_smith\/2025\/11\/14\/week-9-day-3-final\/","title":{"rendered":"week 9 day 3 final"},"content":{"rendered":"\n<p>no your reading the title right it says week 9 day 3 final becuase i got everything to work finally <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nimport pandas as pd\nfrom flags import flags\n\n\n# --- Team and Division Setup ---\n\ndivisions = {\n    \"AFC East\": &#91;\"BUF\", \"MIA\", \"NE\", \"NYJ\"],\n    \"AFC North\": &#91;\"BAL\", \"CIN\", \"CLE\", \"PIT\"],\n    \"AFC South\": &#91;\"HOU\", \"IND\", \"JAX\", \"TEN\"],\n    \"AFC West\": &#91;\"DEN\", \"KC\", \"LV\", \"LAC\"],\n    \"NFC East\": &#91;\"DAL\", \"NYG\", \"PHI\", \"WAS\"],\n    \"NFC North\": &#91;\"CHI\", \"DET\", \"GB\", \"MIN\"],\n    \"NFC South\": &#91;\"ATL\", \"CAR\", \"NO\", \"TB\"],\n    \"NFC West\": &#91;\"ARI\", \"LAR\", \"SEA\", \"SF\"]\n}\n\nall_teams = &#91;t for teams in divisions.values() for t in teams]\n\n# --- Team schedule generation ---\ndef generate_team_schedule(team, divisions):\n    \"\"\"Return a set of opponents for one team (simplified NFL style).\"\"\"\n    division = next(div for div, teams in divisions.items() if team in teams)\n    div_teams = divisions&#91;division]\n\n    opponents = &#91;]\n\n    # Division home &amp; away (6 games)\n    for opp in div_teams:\n        if opp != team:\n            opponents.append(opp)\n            opponents.append(opp)\n\n    # Fill remaining 11 with random others\n    others = &#91;t for t in all_teams if t not in div_teams and t != team]\n    random.shuffle(others)\n    opponents.extend(others&#91;:11])\n\n    return opponents # 17 games\n\n# --- Full Schedule ---\ndef generate_schedule(divisions, weeks=18):\n    random.seed(42)\n    schedule = &#91;]\n    team_games = {team: generate_team_schedule(team, divisions) for team in all_teams}\n    \n    week = 1\n    while week &lt;= weeks:\n        used = set()\n        weekly_games = &#91;13 or 14]\n        random.shuffle(all_teams)\n\n        for team in all_teams:\n            if team in used or not team_games&#91;team]:\n                continue\n            opp = team_games&#91;team].pop()\n            if opp in used or team not in team_games&#91;opp]:\n                continue\n            # Assign game\n            weekly_games.append((week, team, opp))\n            used.add(team)\n            used.add(opp)\n            team_games&#91;opp].remove(team)\n\n        schedule.extend(weekly_games)\n        week += 1\n\n    return (\"Week\", \"Home\", \"Away\")\n\n\ndef calculate_standings(results):\n    standings = {team: {\"W\": 0, \"L\": 0, \"PF\": 0, \"PA\": 0} for team in all_teams}\n    for _, row in results.iterrows():\n        home, away = row&#91;\"Home\"], row&#91;\"Away\"]\n        hs, as_ = row&#91;\"HomeScore\"], row&#91;\"AwayScore\"]\n        standings&#91;home]&#91;\"PF\"] += hs\n        standings&#91;home]&#91;\"PA\"] += as_\n        standings&#91;away]&#91;\"PF\"] += as_\n        standings&#91;away]&#91;\"PA\"] += hs\n        if hs > as_:\n            standings&#91;home]&#91;\"W\"] += 1\n            standings&#91;away]&#91;\"L\"] += 1\n        else:\n            standings&#91;away]&#91;\"W\"] += 1\n            standings&#91;home]&#91;\"L\"] += 1\n    df = pd.DataFrame(&#91;\n        {\"Team\": t, \"W\": d&#91;\"W\"], \"L\": d&#91;\"L\"], \"PF\": d&#91;\"PF\"], \"PA\": d&#91;\"PA\"]}\n        for t, d in standings.items()\n    ])\n    df&#91;\"WinPct\"] = df&#91;\"W\"] \/ (df&#91;\"W\"] + df&#91;\"L\"])\n    return df.sort_values(&#91;\"WinPct\", \"PF\"], ascending=&#91;False, False]).reset_index(drop=True)\n\n\nschedule = generate_schedule(divisions)\nsimulate_scores= random\n\nclass standings:\n  standings = calculate_standings\nresults= (\"W-L\")\n\n\nclass playoffs:\n    \n\n        \"\"\"Simplified playoffs: 7 teams per conference, single elimination.\"\"\"\n        # Split AFC\/NFC\n        afc = &#91;t for div, teams in divisions.items() if \"AFC\" in div for t in teams]\n        nfc = &#91;t for div, teams in divisions.items() if \"NFC\" in div for t in teams]\n\n    \n\n        def play_game(team1, team2):\n            s1, s2 = random.randint(14, 38), random.randint(14, 38)\n            return team1 if s1 >= s2 else team2\n\n        def run_bracket(seeds):\n            # 1 seed bye, 2v7, 3v6, 4v5\n\n            play_game=play_game\n            winner_2_7 = play_game(seeds&#91;1]&#91;\"Team\"], seeds&#91;6]&#91;\"Team\"])\n            winner_3_6 = play_game(seeds&#91;2]&#91;\"Team\"], seeds&#91;5]&#91;\"Team\"])\n            winner_4_5 = play_game(seeds&#91;3]&#91;\"Team\"], seeds&#91;4]&#91;\"Team\"])\n            # Next rounds (simplified seeding)\n            semis = &#91;seeds&#91;0]&#91;\"Team\"], winner_2_7, winner_3_6, winner_4_5]\n            random.shuffle(semis)\n            finals = &#91;play_game(semis&#91;0], semis&#91;1]), play_game(semis&#91;2], semis&#91;3])]\n            champ = play_game(finals&#91;0], finals&#91;1])\n            return champ \n        \n\nclass flag_penalties:\n\n    flag_penalties={}\n    def throw_flag(self):\n        return self.get_random_flag()\n    \n    def get_random_flag(self):\n        return random.choice(flags)\n<\/code><\/pre>\n\n\n\n<p>the final main file don&#8217;t  worry i already ran everything it works well im honestly sad its over it was fun you know but on the postive this opens up possbly for next week and the weeks that fellow im thinking of doing a chat bot next but im not sure but ill have it figured out by next week <\/p>\n\n\n\n<p>now back to why your here   today was just making sure everything works and putting it all as 1 if im being honest i didnt think i could do it u know theres a saying it goes you miss 100% of the shots you dont take and well i took mine and it landed perfectly im sorry this post really is not about coding but there really not much more to say about this project but it was fun i want to thank you for these 9 weeks it was really fun <\/p>\n\n\n\n<p> <strong>THANK YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>no your reading the title right it says week 9 day 3 final becuase i got everything to work finally the final main file don&#8217;t worry i already ran everything it works well im honestly sad its over it was fun you know but on the postive this opens up possbly for next week and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/posts\/65\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_smith\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}