add action_policy for problem;

This commit is contained in:
wls2002
2024-06-07 17:09:16 +08:00
parent 10ec1c2df9
commit 3d5b80c6fa
13 changed files with 2417 additions and 1191 deletions

View File

@@ -7,14 +7,21 @@ from ..rl_jit import RLEnv
class Jumanji_2048(RLEnv):
def __init__(
self, max_step=1000, repeat_times=1, record_episode=False, guarantee_invalid_action=True
self, guarantee_invalid_action=True, *args, **kwargs
):
super().__init__(max_step, repeat_times, record_episode)
super().__init__(*args, **kwargs)
self.guarantee_invalid_action = guarantee_invalid_action
self.env = jumanji.make("Game2048-v1")
def env_step(self, randkey, env_state, action):
action_mask = env_state["action_mask"]
###################################################################
action = jnp.concatenate([action, jnp.full((4 - action.shape[0], ), -99999)])
action = (action - 1) / 15
###################################################################
if self.guarantee_invalid_action:
score_with_mask = jnp.where(action_mask, action, -jnp.inf)
action = jnp.argmax(score_with_mask)