Skip to content

Commit

Permalink
Updating test with new games, removing splash screen, updating nactions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpalms committed Apr 23, 2024
1 parent d08d480 commit 6b874c1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion diambra/arena/env_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def sanity_check(self):
check_num_in_range("normalization_factor", self.normalization_factor, [0.0, 1000000])
check_type("clip_reward", self.clip_reward, bool, admit_none=False)
check_type("no_attack_buttons_combinations", self.no_attack_buttons_combinations, bool, admit_none=False)
check_val_in_list("frame_shape[2]", self.frame_shape[2], [0, 1, 3])
check_val_in_list("frame_shape[2]", self.frame_shape[2], [0, 1])
check_num_in_range("frame_shape[0]", self.frame_shape[0], [0, MAX_FRAME_RES])
check_num_in_range("frame_shape[1]", self.frame_shape[1], [0, MAX_FRAME_RES])
if (min(self.frame_shape[0], self.frame_shape[1]) == 0 and
Expand Down
11 changes: 6 additions & 5 deletions diambra/arena/utils/integratedGames.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
"id": "mvsc",
"original_rom_name": "mvsc.zip",
"search_keywords": ["marvel vs capcom clash of super heroes", "marvel-vs.-capcom-clash-of-super-heroes-euro-980123", "5511", "wowroms"],
"notes": "Requires the QSound_HLE sound driver to be placed in the roms folder. Google `qsound_hle.zip` or `dl-1425.bin`",
"notes": "Requires the QSound_HLE sound driver to be placed in the roms folder. Search keywords: \"qsound_hle.zip\", \"dl-1425.bin\"",
"nvram_save": "",
"sha256": "6f63627cc37c554f74e8bf07b21730fa7f85511c7d5d07449850be98dde91da8",
"char_list": ["Chun-Li", "Ryu", "Zangief", "Morrigan", "Captain Commando",
Expand Down Expand Up @@ -395,7 +395,7 @@
"stages_per_game": 8,
"number_of_chars_per_round": 2,
"number_of_chars_to_select": 2,
"n_actions": [9, 10, 7],
"n_actions": [9, 19, 7],
"health": [0, 144],
"frame_shape": [224, 384, 3],
"ram_states": {
Expand Down Expand Up @@ -426,7 +426,7 @@
"id": "xmvsf",
"original_rom_name": "xmvsf.zip",
"search_keywords": ["x-men vs street fighter", "x-men-vs.-street-fighter-usa-961004", "8769", "wowroms"],
"notes": "Requires the QSound_HLE sound driver to be placed in the roms folder. Google `qsound_hle.zip` or `dl-1425.bin`",
"notes": "Requires the QSound_HLE sound driver to be placed in the roms folder. Search keywords: \"qsound_hle.zip\", \"dl-1425.bin\"",
"nvram_save": "",
"sha256": "833aa46af63a3ad87f69ce2bacd85a4445f35a50e3aff4f793f069b205b51c60",
"char_list": ["Akuma", "Magneto", "Juggernaut", "Dhalsim", "Mr. Bison",
Expand All @@ -435,6 +435,7 @@
"Ken", "Apocalypse", "Alpha Chun-Li"],
"char_forbidden_list": ["Apocalypse", "Alpha Chun-Li"],
"char_homonymy_map": {},
"outfits": [1, 2],
"difficulty": [1, 8, 2],
"difficulty_to_cluster_map": {
"1": "Easy",
Expand All @@ -455,7 +456,7 @@
"stages_per_game": 8,
"number_of_chars_per_round": 2,
"number_of_chars_to_select": 2,
"n_actions": [9, 10, 7],
"n_actions": [9, 18, 7],
"health": [0, 144],
"frame_shape": [224, 384, 3],
"ram_states": {
Expand Down Expand Up @@ -511,7 +512,7 @@
"stages_per_game": 8,
"number_of_chars_per_round": 1,
"number_of_chars_to_select": 1,
"n_actions": [9, 10, 5],
"n_actions": [9, 13, 5],
"health": [0, 240],
"frame_shape": [240, 512, 3],
"ram_states": {
Expand Down
2 changes: 1 addition & 1 deletion diambra/arena/wrappers/arena_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def env_wrapping(env, wrappers_settings: WrappersSettings):
warning_message += " X " + str(native_frame_size[1]) + "]\n"
warning_message += " \"frame_shape\" = [" + str(wrappers_settings.frame_shape[0])
warning_message += " X " + str(wrappers_settings.frame_shape[1]) + "]"
env.logger.warning(warning_message)
env.unwrapped.logger.warning(warning_message)

env = WarpFrame(env, wrappers_settings.frame_shape[:2])

Expand Down
2 changes: 1 addition & 1 deletion diambra/arena/wrappers/episode_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, env, recording_settings: RecordingSettings):

self.compression_parameters = [int(cv2.IMWRITE_JPEG_QUALITY), 80]

self.env.logger.info("Recording trajectories in \"{}\"".format(self.dataset_path))
self.unwrapped.logger.info("Recording trajectories in \"{}\"".format(self.dataset_path))
os.makedirs(self.dataset_path, exist_ok=True)

def reset(self, **kwargs):
Expand Down
20 changes: 15 additions & 5 deletions tests/env_exec_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@
"log_output": False,
}

n_rounds_map = {
"doapp": 2,
"sfiii3n": 2,
"tektagt": 2,
"umk3": 2,
"samsh5sp": 2,
"kof98umh": 3,
"mvsc": 1,
"xmvsf": 1,
"soulclbr": 2,
}

def env_exec(settings, options_list, wrappers_settings, episode_recording_settings, args=default_args):
try:
wait_key = 1
if args["interactive"] is True:
wait_key = 0

n_rounds = 2
if settings.game_id == "kof98umh":
n_rounds = 3
n_rounds = n_rounds_map[settings.game_id]

env = diambra.arena.make(settings.game_id, settings, wrappers_settings, episode_recording_settings)

Expand All @@ -48,7 +58,7 @@ def env_exec(settings, options_list, wrappers_settings, episode_recording_settin

if settings.n_players == 1:
if no_action is True:
actions = env.get_no_op_action()
actions = env.unwrapped.get_no_op_action()

if settings.action_space == SpaceTypes.DISCRETE:
move_action, att_action = discrete_to_multi_discrete_action(actions, env.unwrapped.n_actions[0])
Expand All @@ -60,7 +70,7 @@ def env_exec(settings, options_list, wrappers_settings, episode_recording_settin

else:
if no_action is True:
actions["agent_0"] = env.get_no_op_action()["agent_0"]
actions["agent_0"] = env.unwrapped.get_no_op_action()["agent_0"]

for idx in range(settings.n_players):
if settings.action_space[idx] == SpaceTypes.DISCRETE:
Expand Down
10 changes: 7 additions & 3 deletions tests/test_gym_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def func(settings, mocker):

games_dict = available_games(False)
gym_settings_var_order = ["frame_shape", "step_ratio", "action_space", "difficulty", "continue_game",
"tower", "role", "characters", "super_art", "fighting_style", "ultimate_style"]
"tower", "role", "characters", "super_art", "fighting_style", "ultimate_style", "speed_mode"]

ok_test_parameters = {
"frame_shape": [(0, 0, 0), (0, 0, 1), (82, 82, 0), (82, 82, 1)],
Expand All @@ -43,6 +43,7 @@ def func(settings, mocker):
"super_art": [None, 1, 3],
"fighting_style": [None, 1, 3],
"ultimate_style": [None, (2, 2, 2)],
"speed_mode": [None, 1, 2],
}

ko_test_parameters = {
Expand All @@ -57,6 +58,7 @@ def func(settings, mocker):
"super_art": ["Random", 4, 0],
"fighting_style": [False, 6, 0, "Random"],
"ultimate_style": [(10, 0, 0), "string", (None, None, None), ("Random", "Random", "Random")],
"speed_mode": [False, 6, 0, "Random"],
}

def pytest_generate_tests(metafunc):
Expand All @@ -67,7 +69,7 @@ def pytest_generate_tests(metafunc):
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", [1, 2])
def test_gym_settings(game_id, n_players, frame_shape, step_ratio, action_space, difficulty, continue_game,
tower, role, characters, super_art, fighting_style, ultimate_style, expected, mocker):
tower, role, characters, super_art, fighting_style, ultimate_style, speed_mode, expected, mocker):

game_data = games_dict[game_id]

Expand All @@ -84,6 +86,7 @@ def test_gym_settings(game_id, n_players, frame_shape, step_ratio, action_space,
settings.frame_shape = frame_shape
settings.step_ratio = step_ratio
settings.action_space = (action_space, action_space)
settings.splash_screen = False

settings.difficulty = difficulty
settings.continue_game = continue_game
Expand All @@ -95,10 +98,11 @@ def test_gym_settings(game_id, n_players, frame_shape, step_ratio, action_space,
settings.super_art = (super_art, super_art)
settings.fighting_style = (fighting_style, fighting_style)
settings.ultimate_style = (ultimate_style, ultimate_style)
settings.speed_mode = (speed_mode, speed_mode)

if n_players != 2:
for key in ["action_space", "role", "characters" , "outfits",
"super_art", "fighting_style", "ultimate_style"]:
"super_art", "fighting_style", "ultimate_style", "speed_mode"]:
setattr(settings, key, getattr(settings, key)[0])

assert func(settings, mocker) == expected
12 changes: 7 additions & 5 deletions tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import random
from diambra.arena.utils.engine_mock import load_mocker
from diambra.arena import SpaceTypes, Roles, EnvironmentSettings, EnvironmentSettingsMultiAgent, WrappersSettings, RecordingSettings
from diambra.arena.utils.gym_utils import available_games

# Example Usage:
# pytest
Expand Down Expand Up @@ -38,6 +39,7 @@ def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
settings.game_id = game_id
settings.frame_shape = frame_shape
settings.action_space = (action_space, action_space)
settings.splash_screen = False
if settings.n_players == 1:
settings.action_space = settings.action_space[0]

Expand All @@ -58,23 +60,23 @@ def func(game_id, n_players, action_space, frame_shape, wrappers_settings,
print(e)
return 1

game_ids = ["doapp", "sfiii3n", "tektagt", "umk3", "samsh5sp", "kof98umh"]
games_dict = available_games(False)
n_players = [1, 2]
action_spaces = [SpaceTypes.DISCRETE, SpaceTypes.MULTI_DISCRETE]
no_action_probabilities = [0.0, 1.0]

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
@pytest.mark.parametrize("no_action_probability", no_action_probabilities)
def test_random_gym_mock(game_id, n_players, action_space, no_action_probability, mocker):
frame_shape = random.choice([(128, 128, 1), (256, 256, 0)])
frame_shape = random.choice([(128, 128, 1), (128, 256, 1), (256, 256, 0)])
continue_games = [0.0]
use_mock_env = True
assert func(game_id, n_players, action_space, frame_shape, WrappersSettings(),
no_action_probability, continue_games, use_mock_env, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
@pytest.mark.parametrize("no_action_probability", no_action_probabilities)
Expand Down Expand Up @@ -106,7 +108,7 @@ def test_random_wrappers_mock(game_id, n_players, action_space, no_action_probab
assert func(game_id, n_players, action_space, frame_shape, wrappers_settings,
no_action_probability, continue_games, use_mock_env, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", n_players)
@pytest.mark.parametrize("action_space", action_spaces)
@pytest.mark.parametrize("no_action_probability", [0.0])
Expand Down
1 change: 1 addition & 0 deletions tests/test_recording_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_settings_recording(game_id ,username, dataset_path, n_players, action_s
settings = EnvironmentSettingsMultiAgent()
settings.game_id = game_id
settings.action_space = action_space
settings.splash_screen = False
if n_players == 2:
settings.action_space = (action_space, action_space)

Expand Down
8 changes: 5 additions & 3 deletions tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import diambra.arena
from diambra.arena import EnvironmentSettings, EnvironmentSettingsMultiAgent, WrappersSettings
from diambra.arena.utils.engine_mock import load_mocker
from diambra.arena.utils.gym_utils import available_games
import numpy as np
import warnings

Expand All @@ -25,6 +26,7 @@ def func(game_id, n_players, wrappers_settings, use_mocker, mocker):

settings.step_ratio = 1
settings.frame_shape = (128, 128, 1)
settings.splash_screen = False

env = diambra.arena.make(game_id, settings, wrappers_settings)
observation, info = env.reset()
Expand Down Expand Up @@ -57,7 +59,7 @@ def func(game_id, n_players, wrappers_settings, use_mocker, mocker):
return 1

n_players = [1, 2]
game_ids = ["doapp", "sfiii3n", "tektagt", "umk3", "samsh5sp", "kof98umh"]
games_dict = available_games(False)

@pytest.mark.parametrize("n_players", n_players)
def test_speed_gym_mock(n_players, mocker):
Expand Down Expand Up @@ -92,13 +94,13 @@ def test_speed_wrappers_mock(n_players, mocker):

assert func(game_id, n_players, wrappers_settings, use_mocker, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", n_players)
def test_speed_gym_integration(game_id, n_players, mocker):
use_mocker = False
assert func(game_id, n_players, WrappersSettings(), use_mocker, mocker) == 0

@pytest.mark.parametrize("game_id", game_ids)
@pytest.mark.parametrize("game_id", list(games_dict.keys()))
@pytest.mark.parametrize("n_players", n_players)
def test_speed_wrappers_integration(game_id, n_players, mocker):
use_mocker = False
Expand Down
3 changes: 2 additions & 1 deletion tests/test_wrappers_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def func(settings, wrappers_settings, mocker):
"normalization_factor": [0.2, 0.5],
"clip_reward": [True, False],
"no_attack_buttons_combinations": [True, False],
"frame_shape": [(0, 0, 0), (84, 84, 1), (84, 84, 3), (84, 84, 0)],
"frame_shape": [(0, 0, 0), (84, 84, 1), (84, 84, 0)],
"stack_frames": [1, 5],
"dilation": [1, 3],
"add_last_action": [True, False],
Expand Down Expand Up @@ -94,6 +94,7 @@ def test_wrappers_settings(game_id, step_ratio, n_players, action_space, no_op_m
settings.game_id = game_id
settings.step_ratio = step_ratio
settings.action_space = action_space
settings.splash_screen = False
if n_players == 2:
settings.action_space = (action_space, action_space)

Expand Down

0 comments on commit 6b874c1

Please sign in to comment.