import random

# 전역 점수, 포제션
score = {"HOME": 0, "AWAY": 0}
possession = "HOME"  # HOME or AWAY
rebound_count = 0  # 공격리바운드 연속 횟수

def change_possession():
    global possession, rebound_count
    possession = "AWAY" if possession == "HOME" else "HOME"
    rebound_count = 0
    print(f"==== 공격권 전환, 현재 공격팀: {possession} ====")

def pg_onball():
    # 1. Pick & Roll, 2. Pull-up 2점, 3. Pull-up 3점 랜덤으로 한 번 선택
    action = random.choice(["pick_and_roll", "pullup2", "pullup3"])
    print(f"[{possession}] PG 온더볼 선택: {action}")
    if action == "pick_and_roll":
        pick_and_roll()
    elif action == "pullup2":
        pullup_2()
    elif action == "pullup3":
        pullup_3()

def pick_and_roll():
    # 스크린 성공(70%)
    screen = random.random() < 0.7
    if not screen:
        print("스크린 실패 → PG 드라이브로 전환")
        drive_and_layup()
        return
    # PG 돌파 선택(40%) vs 롤맨 패스(60%)
    if random.random() < 0.4:
        print("PG 돌파 선택")
        result = random.choices(['dunk', 'layup', 'fail', 'turnover'], [0.3,0.3,0.3,0.1])[0]
        if result == "dunk":
            dunk()
        elif result == "layup":
            layup()
        elif result == "fail":
            print("PG 돌파 실패 → 리바운드 루프")
            rebound_loop()
        else:
            print("PG 돌파 중 턴오버")
            change_possession()
    else:
        print("롤맨 패스 선택")
        pass_success = random.random() < 0.8
        if not pass_success:
            print("롤맨 패스 실패 → 턴오버")
            change_possession()
            return
        print("롤맨 패스 성공 → 롤맨 마무리")
        if random.random() < 0.7:
            dunk()
        else:
            layup()

def pullup_2():
    print("PG 2점 풀업")
    if random.random() < 0.45:
        print("2점 성공! +2점")
        score[possession] += 2
        change_possession()
    else:
        print("2점 실패 → 리바운드 루프")
        rebound_loop()

def pullup_3():
    print("PG 3점 풀업")
    if random.random() < 0.33:
        print("3점 성공! +3점")
        score[possession] += 3
        change_possession()
    else:
        print("3점 실패 → 리바운드 루프")
        rebound_loop()

def dunk():
    print("덩크 시도!")
    if random.random() < 0.75:
        print("덩크 성공! +2점")
        score[possession] += 2
        change_possession()
    else:
        print("덩크 실패 → 리바운드 루프")
        rebound_loop()

def layup():
    print("레이업 시도!")
    if random.random() < 0.6:
        print("레이업 성공! +2점")
        score[possession] += 2
        change_possession()
    else:
        print("레이업 실패 → 리바운드 루프")
        rebound_loop()

def drive_and_layup():
    print("PG 드라이브 → 레이업 시도")
    layup()

def rebound_loop():
    global rebound_count
    rebound_count += 1
    # 3회 초과면 공격리바 확률 다운 (예시로 40%)
    if rebound_count >= 3:
        offense_rebound = random.random() < 0.4
    else:
        offense_rebound = random.random() < 0.5
    if offense_rebound:
        print("공격 리바운드! Putback 시도")
        putback()
    else:
        print("수비 리바운드! 공격권 전환")
        change_possession()

def putback():
    print("Putback 시도!")
    if random.random() < 0.5:
        print("Putback 성공! +2점")
        score[possession] += 2
        change_possession()
    else:
        print("Putback 실패 → 리바운드 루프")
        rebound_loop()

# ==== 간단히 10턴 시뮬 돌려보기 ====
print("===== PG 온더볼 시뮬레이션(10포제션) =====")
for _ in range(10):
    print("\n---- 새로운 공격 턴 ----")
    pg_onball()

print("\n최종 스코어:", score)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: