NBA style predictor


today im taking a brake from my wheelchair basketball game and making a nba style of my nfl projct from a few months ago and since i wrote almost all the code already i just mostly copyed and pasted the code

this vision with have box score 82 games for EACH team playoffs sats and more

import random

class NBAGame:
    def __init__(self, home_team, away_team):
        self.home_team = home_team
        self.away_team = away_team
        # Dictionary to store the points per quarter
        self.box_score = {
            "Home": {"Q1": 0, "Q2": 0, "Q3": 0, "Q4": 0, "OT": 0, "Total": 0},
            "Away": {"Q1": 0, "Q2": 0, "Q3": 0, "Q4": 0, "OT": 0, "Total": 0}
        }

    def simulate_quarter(self, q_name):
        # NBA teams usually score 22-35 points per quarter
        h_pts = random.randint(22, 36)
        a_pts = random.randint(22, 36)
        
        self.box_score["Home"][q_name] = h_pts
        self.box_score["Away"][q_name] = a_pts
        self.box_score["Home"]["Total"] += h_pts
        self.box_score["Away"]["Total"] += a_pts

    def play_game(self):
        # Play the standard 4 quarters
        for q in ["Q1", "Q2", "Q3", "Q4"]:
            self.simulate_quarter(q)

        # Overtime logic (NBA games cannot end in a tie)
        while self.box_score["Home"]["Total"] == self.box_score["Away"]["Total"]:
            print("--- OVERTIME! ---")
            h_ot = random.randint(5, 15)
            a_ot = random.randint(5, 15)
            self.box_score["Home"]["OT"] += h_ot
            self.box_score["Away"]["OT"] += a_ot
            self.box_score["Home"]["Total"] += h_ot
            self.box_score["Away"]["Total"] += a_ot

        self.display_box_score()
        return self.home_team if self.box_score["Home"]["Total"] > self.box_score["Away"]["Total"] else self.away_team

    def display_box_score(self):
        h = self.box_score["Home"]
        a = self.box_score["Away"]
        
        print(f"\n{'TEAM':<10} | Q1 | Q2 | Q3 | Q4 | OT | FINAL")
        print("-" * 45)
        print(f"{self.away_team:<10} | {a['Q1']:>2} | {a['Q2']:>2} | {a['Q3']:>2} | {a['Q4']:>2} | {a['OT']:>2} | {a['Total']}")
        print(f"{self.home_team:<10} | {h['Q1']:>2} | {h['Q2']:>2} | {h['Q3']:>2} | {h['Q4']:>2} | {h['OT']:>2} | {h['Total']}")
        
        winner = self.home_team if h['Total'] > a['Total'] else self.away_team
        print(f"\nWINNER: {winner}\n")

i hoping to add trades FA ( Free Agency. ) AND MORE


Leave a Reply

Your email address will not be published. Required fields are marked *