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()