From 7483293e9cc03fe561f33a0edc5daa0c97ec2b2a Mon Sep 17 00:00:00 2001 From: stone_tao Date: Thu, 2 Feb 2023 17:23:10 -0800 Subject: [PATCH 1/3] cast to ints --- ChangeLog.md | 4 ++++ luxai_s2/luxai_s2/actions.py | 1 + luxai_s2/luxai_s2/env.py | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index ef8a8785..bdf35476 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog +### v2.1.2 + +Cast all numbers to ints, ensure all observations only contain ints, no floats. + ### v2.1.1 Remove max episode timesteps from gym registration of the Lux AI env. Expect user to specify themselves diff --git a/luxai_s2/luxai_s2/actions.py b/luxai_s2/luxai_s2/actions.py index a5646b99..afc6b59b 100644 --- a/luxai_s2/luxai_s2/actions.py +++ b/luxai_s2/luxai_s2/actions.py @@ -189,6 +189,7 @@ def format_factory_action(a: int): def format_action_vec(a: np.ndarray): # (0 = move, 1 = transfer X amount of R, 2 = pickup X amount of R, 3 = dig, 4 = self destruct, 5 = recharge X) + a = a.astype(int) a_type = a[0] if a_type == 0: act = MoveAction(a[1], dist=1, repeat=a[4], n=a[5]) diff --git a/luxai_s2/luxai_s2/env.py b/luxai_s2/luxai_s2/env.py index 338f3da7..5c708a69 100644 --- a/luxai_s2/luxai_s2/env.py +++ b/luxai_s2/luxai_s2/env.py @@ -340,6 +340,8 @@ def _handle_factory_placement_step(self, actions): factory = self.add_factory(self.state.teams[k], a["spawn"]) if factory is None: continue + a["water"] = math.floor(a["water"]) + a["metal"] = math.floor(a["metal"]) factory.cargo.water = a["water"] factory.cargo.metal = a["metal"] factory.power = self.env_cfg.INIT_POWER_PER_FACTORY @@ -1097,5 +1099,6 @@ def raw_env() -> LuxAI_S2: gym.register( id="LuxAI_S2-v0", - entry_point="luxai_s2.env:LuxAI_S2" + entry_point="luxai_s2.env:LuxAI_S2", + max_episode_steps=1000, ) From c3e32090ab3c45bc5dc08d97c88c8ea2cdc1df0c Mon Sep 17 00:00:00 2001 From: stone_tao Date: Thu, 2 Feb 2023 17:27:33 -0800 Subject: [PATCH 2/3] Update env.py --- luxai_s2/luxai_s2/env.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/luxai_s2/luxai_s2/env.py b/luxai_s2/luxai_s2/env.py index 5c708a69..131d2028 100644 --- a/luxai_s2/luxai_s2/env.py +++ b/luxai_s2/luxai_s2/env.py @@ -1099,6 +1099,5 @@ def raw_env() -> LuxAI_S2: gym.register( id="LuxAI_S2-v0", - entry_point="luxai_s2.env:LuxAI_S2", - max_episode_steps=1000, + entry_point="luxai_s2.env:LuxAI_S2" ) From a5f84af1fd767e2321943ffcf439a1433c7de864 Mon Sep 17 00:00:00 2001 From: stone_tao Date: Thu, 2 Feb 2023 17:30:38 -0800 Subject: [PATCH 3/3] Update env.py --- luxai_s2/luxai_s2/env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luxai_s2/luxai_s2/env.py b/luxai_s2/luxai_s2/env.py index 131d2028..7a206f82 100644 --- a/luxai_s2/luxai_s2/env.py +++ b/luxai_s2/luxai_s2/env.py @@ -250,7 +250,7 @@ def _handle_bid(self, actions): ].factories_to_place = self.state.board.factories_per_team # verify bid is valid valid_action = True - bid = abs(a["bid"]) + bid = math.floor(abs(a["bid"])) self.state.teams[k].bid = a["bid"] if bid > self.state.teams[k].init_water: valid_action = False @@ -1017,7 +1017,7 @@ def add_factory(self, team: Team, pos: np.ndarray): unit_id=f"factory_{self.state.global_id}", num_id=self.state.global_id, ) - factory.pos.pos = list(pos) + factory.pos.pos = np.array([pos[0], pos[1]]).astype(int) factory.cargo.water = self.env_cfg.INIT_WATER_METAL_PER_FACTORY factory.cargo.metal = self.env_cfg.INIT_WATER_METAL_PER_FACTORY factory.power = self.env_cfg.INIT_POWER_PER_FACTORY