In [1]:
from timeit import default_timer as timer

from tqdm import tqdm
import numpy as np

from env import Env2048

In [2]:
env = Env2048()
def experiment():
    env.reset()
    s = timer()
    n = 1000
    for t in range(n):
        action = env.action_space.sample()
        _, _, done, _ = env.step(action)
        if done:
            env.reset()
    e = timer()
    env.close()
    return n / (e - s)

In [3]:
apss = []
for i in tqdm(range(20), unit="run"):
    aps = experiment()
    apss.append(aps)
print(f"Mean actions per second : {np.mean(apss)}")


100%|██████████| 20/20 [00:06<00:00,  3.26run/s]
Mean actions per second : 3271.2224065763376

Stats

Numpy 2D array : ~ 460 actions/sec

Bit board : ~ 3200 actions/sec


In [ ]: