Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| """ | |
| Debug elixir estimation end-to-end. | |
| Usage: | |
| cd toxic_royale_env | |
| BS_DEBUG_ELIXIR=1 python3 scripts/bluestacks_debug_elixir.py | |
| It will: | |
| - take a screenshot via scripts/bluestacks_screenshot.sh | |
| - estimate elixir using the same algorithm as bluestacks_autoplay_deck_rules.py | |
| - save ROI image to outputs/bluestacks/debug_elixir_roi_best.png (when BS_DEBUG_ELIXIR=1) | |
| """ | |
| import json | |
| import os | |
| import subprocess | |
| import importlib.util | |
| import sys | |
| from pathlib import Path | |
| def _load_estimator(root: Path): | |
| """ | |
| Load _estimate_elixir from scripts/bluestacks_autoplay_deck_rules.py without | |
| requiring scripts/ to be a Python package. | |
| """ | |
| mod_path = root / "scripts" / "bluestacks_autoplay_deck_rules.py" | |
| spec = importlib.util.spec_from_file_location("bluestacks_autoplay_deck_rules", mod_path) | |
| if spec is None or spec.loader is None: | |
| raise RuntimeError(f"Could not load module from {mod_path}") | |
| module = importlib.util.module_from_spec(spec) | |
| sys.modules[spec.name] = module | |
| spec.loader.exec_module(module) | |
| est = getattr(module, "_estimate_elixir", None) | |
| if est is None: | |
| raise RuntimeError("Missing _estimate_elixir in bluestacks_autoplay_deck_rules.py") | |
| return est | |
| def _run(cmd: list[str]) -> None: | |
| subprocess.run(cmd, check=False) | |
| def main() -> int: | |
| root = Path(__file__).resolve().parents[1] | |
| cfg_path = root / "config" / "bluestacks_gameplay.local.json" | |
| if not cfg_path.exists(): | |
| raise SystemExit("Missing calibration: config/bluestacks_gameplay.local.json") | |
| cfg = json.loads(cfg_path.read_text(encoding="utf-8")) | |
| out_dir = root / "outputs" / "bluestacks" | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| img = out_dir / "debug_elixir_current.png" | |
| _run([str(root / "scripts" / "bluestacks_screenshot.sh"), str(img)]) | |
| estimate = _load_estimator(root) | |
| el = estimate(img_path=img, cfg_obj=cfg) | |
| print("screenshot:", img) | |
| print("elixir_est:", el) | |
| if os.environ.get("BS_DEBUG_ELIXIR", "0") == "1": | |
| print("roi:", out_dir / "debug_elixir_roi_best.png") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |