From 287972c59e8bb72d5296ede03e34225473cd0270 Mon Sep 17 00:00:00 2001 From: Kaiyotech <93724202+Kaiyotech@users.noreply.github.com> Date: Thu, 4 May 2023 22:58:09 -0400 Subject: [PATCH] just testing things --- sim_tester.py | 23 +++++++++++++++++------ test_files/test_obs.py | 36 +++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/sim_tester.py b/sim_tester.py index 5cfe2e7..4d5d745 100644 --- a/sim_tester.py +++ b/sim_tester.py @@ -7,15 +7,17 @@ import numpy as np from rlgym_sim.utils.terminal_conditions.common_conditions import GoalScoredCondition, TimeoutCondition -setter = AugmentSetter(ReplaySetter("replays/easy_double_tap_1v0.npy", defender_front_goal_weight=0.2, - random_boost=True, print_choice=True, override=1), +bad_list = [] +index = {} +setter = AugmentSetter(ReplaySetter("replays/easy_double_tap_1v1.npy", defender_front_goal_weight=0.2, + random_boost=True, print_choice=True, override=None, index=index), True, False, False) parser = CoyoteAction() obs = TestObs() reward = TestReward() terminals = [GoalScoredCondition(), TimeoutCondition(100)] -env = rlgym_sim.make(tick_skip=4, spawn_opponents=False, state_setter=setter, copy_gamestate_every_step=True, +env = rlgym_sim.make(tick_skip=4, spawn_opponents=True, state_setter=setter, copy_gamestate_every_step=True, action_parser=parser, obs_builder=obs, reward_fn=reward, terminal_conditions=terminals) total_steps = 0 @@ -34,12 +36,21 @@ done = False steps = 0 while not done: - # actions = np.asarray((np.asarray([0]), np.asarray([np.random.randint(0, 373)]))) - actions = np.asarray(np.asarray([0],)) + actions = np.asarray((np.asarray([0]), np.asarray([np.random.randint(0, 373)]))) + # actions = np.asarray(np.asarray([0],)) new_obs, reward, done, state = env.step(actions) obs = new_obs + if np.isnan(obs).any(): + # self.actions.reverse() + # self.states.reverse() + print(f"There is a nan in the obs. Printing states") + if index[0] not in bad_list: + bad_list.append(index[0]) + # input() + break steps += 1 total_steps += steps - print(f"completed {steps} steps. Starting new episode. Done {total_steps} total steps") + print(bad_list) + # print(f"completed {steps} steps. Starting new episode. Done {total_steps} total steps") diff --git a/test_files/test_obs.py b/test_files/test_obs.py index 86bd491..0bb4cd4 100644 --- a/test_files/test_obs.py +++ b/test_files/test_obs.py @@ -63,6 +63,7 @@ def __init__(self, pos_coef=1 / 2300, ang_coef=1 / math.pi, lin_vel_coef=1 / 230 self.steps = 0 self.actions = deque(maxlen=50) + def reset(self, initial_state: GameState): self.states.clear() self.actions.clear() @@ -111,23 +112,24 @@ def build_obs(self, player: PlayerData, state: GameState, previous_action: np.nd # obs = obs.flatten() # obs = np.expand_dims(np.fromiter(obs, dtype=np.float32, count=len(obs)), 0) obs = np.concatenate(obs) - if np.isnan(obs).any(): - self.actions.reverse() - self.states.reverse() - print(f"There is a nan in the obs. Printing states") - print(f" {self.steps} since reset") - i = 0 - for each_state in self.states: - print(i) - i += 1 - print_state(each_state) - print("printing actions") - i = 0 - for each_action in self.actions: - print(i) - i += 1 - print(each_action) - exit() + # if np.isnan(obs).any(): + # # self.actions.reverse() + # # self.states.reverse() + # print(f"There is a nan in the obs. Printing states") + # input() + # print(f" {self.steps} since reset") + # i = 0 + # for each_state in self.states: + # print(i) + # i += 1 + # print_state(each_state) + # print("printing actions") + # i = 0 + # for each_action in self.actions: + # print(i) + # i += 1 + # print(each_action) + # exit() return obs def _add_player_to_obs(self, obs: List, player: PlayerData, inverted: bool):