Loading

IJCAI 2022 - The Neural MMO Challenge

Replay WebViewer Tutorial(Updated)

replay webviewer tutorial

bowu

1. Get your replay file

Method 1: Download replay

i. Find the submission of your interest and click the "view" button in Submissions page.

ii. Click the "Download" button and you will get a file named "Replay-XXX.zip".

Method 2: Generate replay locally (optional)

i. make sure you have installed the latest ijcai2022nmmo.

pip install -U git+http://gitlab.aicrowd.com/henryz/ijcai2022nmmo.git

ii. Modify your local evalualtion code as the example below (example for local evaluation):

  • Provide a replay file name to config.SAVE_REPLAY

  • Set the kwarg render=True in run()

In [ ]:
config = CompetitionConfig()
config.SAVE_REPLAY = "XXX" 
......
ro = RollOut(config, teams, parallel=True, show_progress=True)
ro.run(n_episode=1, render=True) # set render=True to get a replay

You should see a replay file named "XXX.lzma(XXX.replay)" in the same directory when the game ends.

2. (Optional) Convert replay to json:

i. Create an empty python file named replay2json.py and copy the code below to it.

ii. Make sure the \<replay file> and replay2json.py are in the same directory. The \<replay file> should have name like "Replay-XXX.zip" or "XXX.lzma(XXX.replay)" if obtained by Method 2.

iii. Run python replay2json.py <replay file> and you should see the converted json file.

In [ ]:
import argparse
import json
import lzma
import pickle
import shutil
from pathlib import Path

import lz4.block
from tqdm import tqdm


def replace(data: dict, dictionary: dict):
    """submission_id --> team_name"""
    if dictionary is None:
        return data
    for packet in data["packets"]:
        if "player" not in packet:
            continue
        for p in packet["player"].values():
            if "base" in p and "name" in p["base"]:
                name: str = p["base"]["name"]
                subm_id, eid = name.split("_")
                p["base"]["name"] = dictionary[subm_id] + "_" + eid
    return data


def replay2json(filename: str):
    dictionary = None
    if filename.endswith(".zip"):
        extract_dir = filename.replace(".zip", "")
        shutil.unpack_archive(filename, extract_dir=extract_dir)
        replays = []
        for x in Path(extract_dir).iterdir():
            if x.suffix == ".lzma" or x.suffix == ".replay":
                replays.append(x)
            elif x.name == "submissions.json":
                with open(x, "r") as fp:
                    dictionary = json.load(fp)
            else:
                pass
    else:
        assert filename.endswith(".lzma") or filename.endswith(".replay")
        replays = [Path(filename)]

    for rep in tqdm(replays):
        suffix = rep.suffix
        if suffix == ".lzma":
            with lzma.open(rep) as fp:
                data = json.loads(fp.read())
        elif suffix == ".replay":
            with open(rep, "rb") as fp:
                data = fp.read()
                data = pickle.loads(lz4.block.decompress(data))
        data = replace(data, dictionary)
        jsonfile = str(rep.resolve()).replace(suffix, ".json")
        with open(jsonfile, "w") as fp:
            json.dump(data, fp)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("file",
                        type=str,
                        help="Replay file(XXX.lzma/XXX.replay)")
    args = parser.parse_args()
    replay2json(args.file)

3. Upload the replay(XXX.lzma or XXX.json) to Replay WebViewer. Enjoy!

In [ ]:


Comments

thecrazyt
Almost 2 years ago

Is there any way to zoom in?

Ziv000007
Almost 2 years ago

@thecrazyt, there are three zoom-in levels in the bottom left of the UI. https://ijcai2022-viewer.nmmo.org/

You must login before you can post a comment.

Execute