DarshanScripts commited on
Commit
261bf61
·
verified ·
1 Parent(s): 303a956

Upload stratego\installer.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. stratego//installer.py +60 -0
stratego//installer.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import shutil
3
+ from pathlib import Path
4
+ import textarena
5
+ import textarena.envs.registration as _reg
6
+ from textarena.wrappers import LLMObservationWrapper, ActionFormattingWrapper, GameMessagesAndCurrentBoardObservationWrapper, GameMessagesObservationWrapper, GameBoardObservationWrapper, ClipCharactersActionWrapper, SettlersOfCatanObservationWrapper
7
+
8
+
9
+ def get_textarena_env_dir() -> Path:
10
+ ta_root = Path(textarena.__file__).resolve().parent
11
+ env_root = ta_root / "envs"
12
+ if env_root.exists():
13
+ return env_root
14
+
15
+ def install_strategos():
16
+ stratego_directory = Path(__file__).resolve().parent
17
+ src_dir = stratego_directory / "env" / "backup" / "edited_env"
18
+ # reg = src_dir / "__init__.txt"
19
+
20
+ for path in ["Stratego", "StrategoDuel", "StrategoCustom"]:
21
+ env = src_dir / path / "env.py"
22
+ init = src_dir / path / "__init__.py"
23
+ if not env.exists():
24
+ raise FileNotFoundError(f"{env} file not found!")
25
+ if not init.exists():
26
+ raise FileNotFoundError(f"{init} file not found!")
27
+ ta_dir = get_textarena_env_dir()
28
+ dst_dir = ta_dir / path
29
+ dst_dir.mkdir(parents=True, exist_ok=True)
30
+ dst_env = dst_dir / "env.py"
31
+ shutil.copy2(env, dst_env)
32
+ dst_init = dst_dir / "__init__.py"
33
+ shutil.copy2(init, dst_init)
34
+ print(f"{path} env installed!")
35
+
36
+ ta_init = ta_dir / "__init__.py"
37
+ if not ta_init.exists():
38
+ raise FileNotFoundError("Init file of textarena env is not found!")
39
+
40
+ # registration_code = reg.read_text(encoding="utf-8")
41
+
42
+ # marker = "#--- Initializing StrategoDuel ---#"
43
+ # if marker in ta_init.read_text(encoding="utf-8"):
44
+ # print("Stratego duel arleady exists in init file")
45
+ # return
46
+
47
+ # with ta_init.open("a", encoding="utf-8") as f:
48
+ # f.write("\n\n" + marker + "\n")
49
+ # f.write(registration_code + "\n")
50
+ DEFAULT_WRAPPERS = [LLMObservationWrapper, ActionFormattingWrapper]
51
+ BOARDGAME_WRAPPERS = [GameMessagesAndCurrentBoardObservationWrapper, ActionFormattingWrapper]
52
+ try:
53
+ _reg.register_with_versions(id="Stratego-duel", entry_point="textarena.envs.StrategoDuel.env:StrategoDuelEnv", wrappers={"default": DEFAULT_WRAPPERS, "-train": BOARDGAME_WRAPPERS})
54
+ _reg.register_with_versions(id="Stratego-custom", entry_point="textarena.envs.StrategoCustom.env:StrategoCustomEnv", wrappers={"default": DEFAULT_WRAPPERS, "-train": BOARDGAME_WRAPPERS})
55
+ print("Stratego Games are newly registered!")
56
+ except ValueError:
57
+ print("Stratego Games are already registered!")
58
+ pass
59
+ def main():
60
+ install_strategos()