-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
36 lines (27 loc) · 1.17 KB
/
run.py
File metadata and controls
36 lines (27 loc) · 1.17 KB
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
from __future__ import annotations
import argparse
import importlib
from typing import Type
from pixelvisionai.core.config import load_config
from pixelvisionai.core.engine import CoreEngine, GameAdapter
def load_adapter(game_name: str) -> Type[GameAdapter]:
module_path = f"pixelvisionai.games.{game_name}.adapter"
module = importlib.import_module(module_path)
adapter_cls = getattr(module, "GameAdapterImpl", None)
if adapter_cls is None:
raise AttributeError(f"{module_path} must define GameAdapterImpl")
if not issubclass(adapter_cls, GameAdapter):
raise TypeError(f"{module_path}.GameAdapterImpl must inherit GameAdapter")
return adapter_cls
def main() -> None:
parser = argparse.ArgumentParser(description="PixelVisionAI runner")
parser.add_argument("--game", required=True)
parser.add_argument("--config", required=True)
parser.add_argument("--max-steps", type=int, default=100)
args = parser.parse_args()
config = load_config(args.config)
adapter = load_adapter(args.game)()
engine = CoreEngine(adapter=adapter, config=config)
engine.run(max_steps=args.max_steps)
if __name__ == "__main__":
main()