File size: 3,621 Bytes
0fc5daf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Comprehensive test script: Retry Loop + Multi-Round Stability."""

from server.environment import NationEnvironment
from server.models import ParliamentaryAction
from schemas.phases import Phase

def run_combined_test():
    env = NationEnvironment(seed=42)
    obs, _ = env.reset()
    departments = env.departments
    
    print("=== STARTING COMPREHENSIVE SIMULATION TEST ===")
    
    # --- ROUND 1: THE RETRY SCENARIO ---
    print(f"\n[ROUND {obs.round}] Starting Phase: {obs.phase_name}")
    
    # 1. Debate
    obs, _, _, _, _ = env.step(ParliamentaryAction(agent_id=departments[0], type="DEBATE", message="Crisis debate"))
    obs, _, _, _, _ = env.step(ParliamentaryAction(agent_id=departments[0], type="DEBATE", message="")) # End debate
    
    # 2. Proposals
    for dept in departments:
        obs, _, _, _, _ = env.step(ParliamentaryAction(
            agent_id=dept, type="PROPOSE_BUDGET", department=dept, amount=150.0, justification="Greedy request"
        ))
    
    # 3. Voting (VOTE NO to trigger retry)
    print(f"Current Phase: {obs.phase_name}. Agents voting NO...")
    while obs.phase_name == "VOTING":
        dept = obs.current_agent
        target = next((p for p in obs.proposals if dept != p.agent_id and dept not in p.votes), None)
        if target:
            obs, _, _, _, _ = env.step(ParliamentaryAction(agent_id=dept, type="VOTE", proposal_id=target.proposal_id, vote="NO"))
        else: break
        
    print(f"Transitioned to: {obs.phase_name} (Retry Count: {obs.retry_count})")
    if obs.retry_count == 1:
        print("SUCCESS: Retry loop triggered correctly.")
    else:
        print("FAILURE: Retry loop did not trigger.")
        return

    # 4. Re-Proposal (Retry Round)
    print(f"Submiting safer proposals for Retry {obs.retry_count}...")
    for dept in departments:
        obs, _, _, _, _ = env.step(ParliamentaryAction(
            agent_id=dept, type="PROPOSE_BUDGET", department=dept, amount=60.0, justification="Safe request"
        ))
        
    # 5. Voting (VOTE YES to finish round)
    print("Agents voting YES on retry proposals...")
    while obs.phase_name == "VOTING":
        dept = obs.current_agent
        target = next((p for p in obs.proposals if dept != p.agent_id and dept not in p.votes), None)
        if target:
            obs, reward, done, _, info = env.step(ParliamentaryAction(agent_id=dept, type="VOTE", proposal_id=target.proposal_id, vote="YES"))
        else: break

    print(f"Round 1 Complete! Reward: {reward:.4f} | Treasury: {obs.treasury:.2f}")
    
    # --- ROUND 2: NORMAL STABILITY ---
    print(f"\n[ROUND {obs.round}] Phase: {obs.phase_name}")
    
    # Skip debate
    obs, _, _, _, _ = env.step(ParliamentaryAction(agent_id=departments[0], type="DEBATE", message=""))
    
    # Propose
    for dept in departments:
        obs, _, _, _, _ = env.step(ParliamentaryAction(
            agent_id=dept, type="PROPOSE_BUDGET", department=dept, amount=70.0, justification="Normal request"
        ))
        
    # Vote YES
    while obs.phase_name == "VOTING":
        dept = obs.current_agent
        target = next((p for p in obs.proposals if dept != p.agent_id and dept not in p.votes), None)
        if target:
            obs, reward, done, _, info = env.step(ParliamentaryAction(agent_id=dept, type="VOTE", proposal_id=target.proposal_id, vote="YES"))
        else: break

    print(f"Round 2 Complete! Reward: {reward:.4f} | Treasury: {obs.treasury:.2f} | Pop: {obs.population}")
    print("\n=== COMPREHENSIVE TEST FINISHED SUCCESSFULLY ===")

if __name__ == "__main__":
    run_combined_test()