File size: 5,061 Bytes
bb3fbf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
import sys

# Ensure we can import engine
sys.path.append(os.getcwd())

import engine_rust

def setup_game():
    # Load DB
    db_path = "engine/data/cards_compiled.json"
    with open(db_path, "r", encoding="utf-8") as f:
        cards_data_raw = f.read()

    db = engine_rust.PyCardDatabase(cards_data_raw)
    state = engine_rust.PyGameState(db)
    return state, db

def find_card_id(db, card_no):
    # Iterate to find card ID (naive but works for test)
    # Actually PyCardDatabase might not expose iteration on python side easily?
    # We can rely on a known ID if we had it, but let's try to search.
    # If not exposed, we might need to parse json manually.
    pass

def test_poppin_up():
    import json
    # Manually load json to find ID
    with open("engine/data/cards_compiled.json", "r", encoding="utf-8") as f:
        data = json.load(f)
    
    POPPIN_ID = -1
    # Check live_db for the card
    live_db = data.get("live_db", {})
    for k, v in live_db.items():
        if isinstance(v, dict) and v.get("card_no") == "PL!N-bp1-026-L":
            POPPIN_ID = v.get("card_id")
            break
            
    if POPPIN_ID == -1:
        print("Could not find Poppin' Up card ID in live_db")
        return

    print(f"Found Poppin' Up ID: {POPPIN_ID}")
    print(f"Card Details: Score={v.get('score')}, Hearts={v.get('required_hearts')}")

    state, db = setup_game()

    print(f"Card Details: Score={v.get('score')}, Hearts={v.get('required_hearts')}")

    state, db = setup_game()
    
    # Requirements: Yellow(2), Blue(3), Purple(4), Orange(5). Total 4 colors.
    # We have 3 slots.
    # We need a member that gives >1 of these colors, or "Rainbow" hearts.
    
    # Let's find members.
    def find_member(wanted_indices):
        member_db = data.get("member_db", {})
        for mid, mdata in member_db.items():
            h = mdata.get("hearts", [])
            # Check if this member helps with ANY wanted index
            matches = 0
            for idx in wanted_indices:
                if len(h) > idx and h[idx] > 0:
                    matches += 1
            if matches >= 2: # Found a dual provider!
                return int(mdata.get("card_id"))
        return -1
        
    def find_single(idx):
        member_db = data.get("member_db", {})
        for mid, mdata in member_db.items():
             h = mdata.get("hearts", [])
             if len(h) > idx and h[idx] > 0:
                 return int(mdata.get("card_id"))
        return 249

    # Strategy:
    # Find a member for Yellow+Orange? Or Yellow+Blue?
    # Req: 2, 3, 4, 5
    
    # Try to find a member that gives ANY two of these.
    dual_member = find_member([2, 3, 4, 5])
    
    slot0 = 249
    slot1 = 249
    slot2 = 249
    
    covered = set()
    
    if dual_member != -1:
         print(f"Found dual member: {dual_member}")
         slot0 = dual_member
         # Check what it covers
         # We need to re-fetch data or iterate again, but for test we assume it works or check logs.
         # Actually we can check `data` again if we want to be robust.
         mdata = data["member_db"][str(dual_member)]
         h = mdata.get("hearts", [])
         for i in [2,3,4,5]:
             if len(h)>i and h[i]>0: covered.add(i)
    else:
         print("No dual member found, trying single coverage")
    
    # Fill remaining slots
    remaining = [i for i in [2,3,4,5] if i not in covered]
    
    if remaining:
        slot1 = find_single(remaining[0])
        remaining.pop(0)
    
    if remaining:
        slot2 = find_single(remaining[0])
        remaining.pop(0)
        
    if remaining:
        print(f"WARNING: Still missing coverage for: {remaining}")
        # Hope for the best or that Slot 0 covered more.
    
    state.initialize_game([249]*48, [249]*48, [20001]*12, [20001]*12, [POPPIN_ID]*4+[10001]*8, [POPPIN_ID]*4+[10001]*8)
    
    state.set_stage_card(0, 0, slot0)
    state.set_stage_card(0, 1, slot1)
    state.set_stage_card(0, 2, slot2)
    
    # Set Poppin Up
    state.set_live_card(0, 0, POPPIN_ID, True)
    
    state.current_player = 0
    state.phase = 6 # Perf P1
    
    print("Starting Performance Phase...")
    print("Starting Performance Phase...")
    # Step multiple times to allow triggers to resolve
    for _ in range(5):
        state.step(0)
        logs = state.rule_log
        if state.pending_choices:
            break
        
    logs = state.rule_log
    
    found = False
    for line in logs:
        if "Trigger" in line or "Poppin" in line:
            print(line)
        if "Choosing" in line: # Choice prompt
             found = True
        if "Live Success" in line or "ライブ成功" in line:
             print("LIVE WAS SUCCESSFUL")
             
    if state.pending_choices:
        print(f"Pending choice: {state.pending_choices[0]}")
        found = True
        
    if found:
        print("SUCCESS: Trigger activated!")
    else:
        print("FAILURE: No trigger activated")

if __name__ == "__main__":
    test_poppin_up()