Spaces:
Running
Running
| import numpy as np | |
| from engine.game.game_state import GameState | |
| from engine.models.ability import Ability, Effect, EffectType, TargetType, TriggerType | |
| from engine.models.card import MemberCard | |
| def test_logging_ability_resolution(): | |
| gs = GameState() | |
| # gs.initialize_game() # Does not exist | |
| gs.member_db = {} | |
| gs.live_db = {} | |
| # gs._init_jit_arrays() # Will be called later after adding card | |
| p0 = gs.players[0] | |
| # Setup: Create a card with "On Play: Draw 1" | |
| # We mock it in member_db manually for isolation | |
| card_id = 9900 | |
| ability_text = "Draw 1 card." | |
| card = MemberCard( | |
| card_id=card_id, | |
| card_no="LOG-TEST-001", | |
| name="Logging Honoka", | |
| # rarity="R", # Removed invalid field | |
| cost=1, | |
| # color="Pink", # Removed invalid field? Wait, check definition. Color is implicit triggers? | |
| # Actually standard MemberCard doesn't check color. | |
| # source="Test", # Invalid | |
| # grading="None", # Invalid | |
| blades=1, | |
| hearts=np.zeros(7, dtype=int), | |
| blade_hearts=np.zeros(7, dtype=int), | |
| abilities=[ | |
| Ability( | |
| trigger=TriggerType.ON_PLAY, | |
| effects=[Effect(EffectType.DRAW, 1, TargetType.SELF, {})], | |
| conditions=[], | |
| costs=[], | |
| raw_text=ability_text, | |
| ) | |
| ], | |
| ) | |
| gs.live_db = {} | |
| # CRITICAL: Set Class-level DB for JIT initialization | |
| GameState.member_db[card_id] = card | |
| gs.member_db = GameState.member_db # Ensure instance sees it too if shadowed elsewhere | |
| # Give energy | |
| p0.energy_zone = [2001, 2002] # 2 energy | |
| p0.tapped_energy[:] = False # Reset all to False | |
| # Add card to hand logic (hack force) | |
| p0.hand = [card_id] | |
| p0.hand_added_turn = [1] | |
| # CRITICAL: Re-initialize JIT arrays because we added a new high-ID card | |
| gs._init_jit_arrays() | |
| # Play the card (Action ID 1 = Play hand[0] to Stage[0]) | |
| # Action ID: 1 + (0*3) + 0 = 1 | |
| # We need to bypass get_legal_actions mask check for pure unit test or ensure it's legal | |
| # It should be legal (cost 1, have 2 energy) | |
| # Setup masks | |
| gs.turn_number = 1 | |
| gs.phase = gs.phase.MAIN # 4 | |
| gs.verbose = True | |
| print(f"Legal mask for Action 1: {gs.get_legal_actions()[1]}") | |
| # Execute action | |
| gs = gs.step(1) | |
| # Check Logs | |
| print("\n--- Rule Log ---") | |
| for entry in gs.rule_log: | |
| print(entry) | |
| # Verify specific log contents | |
| found_resolution = False | |
| for entry in gs.rule_log: | |
| if "Logging Honoka" in entry and "Resolving DRAW" in entry: | |
| found_resolution = True | |
| # Also check if text snippet is there | |
| assert "Draw 1 card" in entry or "Draw 1 card"[:20] in entry | |
| assert found_resolution, "Log should contain source name and effect type" | |