Spaces:
Configuration error
Configuration error
Upload stratego\env\stratego_env.py with huggingface_hub
Browse files
stratego//env//stratego_env.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
import textarena as ta
|
| 3 |
+
|
| 4 |
+
class StrategoEnv:
|
| 5 |
+
def __init__(self, env_id: str = "Stratego-v0", size: int = 10, seed: Optional[int] = None):
|
| 6 |
+
# TODO: make various option to play
|
| 7 |
+
# Stratego original as default, if the user want to play duel mode, env_id = "Stratego-duel"
|
| 8 |
+
# rule_opts: e.g. board_size=10, etc.
|
| 9 |
+
# find a way to replace original init file, registration file and put more environment such as Stratego-duel
|
| 10 |
+
# in original textarena library by running or installing the program.
|
| 11 |
+
# You can see which file should be edited in backup folder.
|
| 12 |
+
# Don't worry, this should be done with Package managing team.
|
| 13 |
+
if size != 10:
|
| 14 |
+
self.env = ta.make(env_id=env_id, size=size)
|
| 15 |
+
else:
|
| 16 |
+
self.env = ta.make(env_id=env_id)
|
| 17 |
+
seed = seed
|
| 18 |
+
|
| 19 |
+
def reset(self, num_players: int = 2, seed: Optional[int] = None):
|
| 20 |
+
self.env.reset(num_players=num_players, seed=seed)
|
| 21 |
+
|
| 22 |
+
def get_observation(self):
|
| 23 |
+
return self.env.get_observation()
|
| 24 |
+
|
| 25 |
+
def step(self, action: str):
|
| 26 |
+
return self.env.step(action=action)
|
| 27 |
+
|
| 28 |
+
def close(self):
|
| 29 |
+
return self.env.close()
|
| 30 |
+
|
| 31 |
+
def get_state(self):
|
| 32 |
+
return self.env.state
|
| 33 |
+
|
| 34 |
+
def repetition_count(self):
|
| 35 |
+
return self.env.repetition_count
|