File size: 1,726 Bytes
8f447ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
adversarial.py — Adversarial Critic Agent (Factor 10: Uncertainty / Hidden Risk).

Injects realistic business shocks to prevent the Decision Agent from learning
brittle strategies. Shock intensity scales with task difficulty.
"""
import random


# (shock_name, base_probability, reputation_delta, budget_delta)
SHOCK_CATALOG: list[tuple[str, float, float, float]] = [
    ("client_dispute",      0.12, -0.08,  -5_000),
    ("key_developer_quit",  0.10, -0.05, -10_000),
    ("budget_audit",        0.08,  0.00, -15_000),
    ("market_rumour",       0.10, -0.10,      0),
    ("competitor_launch",   0.10, -0.05,      0),
    ("surprise_tax_bill",   0.06,  0.00,  -8_000),
    ("data_breach_scare",   0.05, -0.12,  -6_000),
]

DIFFICULTY_MULTIPLIER: dict[str, float] = {
    "easy":   0.40,
    "medium": 1.00,
    "hard":   1.80,
}


class AdversarialAgent:
    """
    Introduces hidden complications to expose weaknesses in the CEO agent's
    strategy and push it toward resilience.
    """

    def __init__(self, difficulty: str = "easy"):
        self.multiplier = DIFFICULTY_MULTIPLIER.get(difficulty, 1.0)

    def apply(
        self, reputation: float, budget: float
    ) -> tuple[float, float, list[str]]:
        """
        Apply random shocks for this quarter.
        Returns updated (reputation, budget, list_of_triggered_shock_names).
        """
        triggered: list[str] = []
        for name, prob, rep_delta, budget_delta in SHOCK_CATALOG:
            if random.random() < prob * self.multiplier:
                reputation = max(0.0, min(1.0, reputation + rep_delta))
                budget    += budget_delta
                triggered.append(name)
        return reputation, budget, triggered