Download play_scripted.py from StarAtNyte1/superbeam-env: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/StarAtNyte1/superbeam-env/resolve/main/play_scripted.py
- Command line
-
hf download hf://StarAtNyte1/superbeam-env/play_scripted.py
-
curl -L -o play_scripted.py https://huggingface.co/StarAtNyte1/superbeam-env/resolve/main/play_scripted.py
1.43 kB
| """Scripted policy against a running SUPERBEAM server (run right; right+jump near gaps/walkers). | |
| python play_scripted.py [--url http://localhost:8000] [--level classic] | |
| """ | |
| import argparse | |
| import os | |
| import re | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from superbeam_env import SuperBeamAction, SuperBeamEnv # noqa: E402 | |
| def policy(obs): | |
| ahead = [int(v) for v in re.findall(r"\((-?\d+) px ahead\)", obs.facts)] | |
| if "standing on ground" in obs.facts and any(0 <= d < 8 for d in ahead): | |
| return "right+jump" | |
| return "right" | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--url", default="http://localhost:8000") | |
| ap.add_argument("--level", default=None) | |
| a = ap.parse_args() | |
| kw = {"level": a.level} if a.level else {} | |
| with SuperBeamEnv(base_url=a.url).sync() as env: | |
| r = env.reset(**kw) | |
| print(r.observation.screen); print(r.observation.facts) | |
| n, total = 0, 0.0 | |
| while not r.done: | |
| r = env.step(SuperBeamAction(action=policy(r.observation))) | |
| n += 1 | |
| total += r.reward or 0 | |
| o = r.observation | |
| print(o.screen); print(o.facts) | |
| print("won=%s dead=%s steps=%d frames=%d progress=%.2f reward=%.1f level=%s state=%s" | |
| % (o.won, o.dead, n, o.frames, o.progress, total, o.level, env.state())) | |
| if __name__ == "__main__": | |
| main() | |