feat: initialize majiang-rl project

This commit is contained in:
game-loader
2026-01-14 10:49:00 +08:00
commit b29a18b459
21 changed files with 18895 additions and 0 deletions

33
majiang_rl/ui/web.py Normal file
View File

@@ -0,0 +1,33 @@
from __future__ import annotations
import argparse
import functools
import http.server
import socketserver
from pathlib import Path
from .record import record_episode, write_record
def main() -> None:
parser = argparse.ArgumentParser(description="Mahjong RL web viewer")
parser.add_argument("--port", type=int, default=8000)
parser.add_argument("--seed", type=int, default=None)
parser.add_argument("--max-steps", type=int, default=200)
args = parser.parse_args()
static_dir = Path(__file__).parent / "static"
static_dir.mkdir(parents=True, exist_ok=True)
record_path = static_dir / "steps.json"
events = record_episode(seed=args.seed, max_steps=args.max_steps)
write_record(record_path, events)
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(static_dir))
with socketserver.TCPServer(("", args.port), handler) as httpd:
print(f"Serving UI at http://localhost:{args.port}/index.html")
httpd.serve_forever()
if __name__ == "__main__":
main()