synth-ai 0.1.9__py3-none-any.whl → 0.2.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synth_ai/__init__.py +28 -2
- synth_ai/core/system.py +4 -0
- synth_ai/environments/__init__.py +35 -0
- synth_ai/environments/environment/__init__.py +1 -0
- synth_ai/environments/environment/artifacts/__init__.py +1 -0
- synth_ai/environments/environment/artifacts/base.py +50 -0
- synth_ai/environments/environment/core.py +22 -0
- synth_ai/environments/environment/db/__init__.py +1 -0
- synth_ai/environments/environment/db/sqlite.py +45 -0
- synth_ai/environments/environment/registry.py +24 -0
- synth_ai/environments/environment/resources/sqlite.py +46 -0
- synth_ai/environments/environment/results.py +1 -0
- synth_ai/environments/environment/rewards/__init__.py +1 -0
- synth_ai/environments/environment/rewards/core.py +28 -0
- synth_ai/environments/environment/shared_engine.py +26 -0
- synth_ai/environments/environment/tools/__init__.py +34 -0
- synth_ai/environments/examples/__init__.py +1 -0
- synth_ai/environments/examples/crafter_classic/__init__.py +8 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_comprehensive_evaluation.py +58 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_evaluation_browser.py +152 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_evaluation_framework.py +1194 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_quick_evaluation.py +51 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_react_agent.py +872 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_trace_evaluation.py +1412 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/test_crafter_react_agent.py +1110 -0
- synth_ai/environments/examples/crafter_classic/config_logging.py +111 -0
- synth_ai/environments/examples/crafter_classic/engine.py +502 -0
- synth_ai/environments/examples/crafter_classic/engine_deterministic_patch.py +63 -0
- synth_ai/environments/examples/crafter_classic/engine_helpers/action_map.py +5 -0
- synth_ai/environments/examples/crafter_classic/engine_helpers/serialization.py +74 -0
- synth_ai/environments/examples/crafter_classic/environment.py +255 -0
- synth_ai/environments/examples/crafter_classic/taskset.py +228 -0
- synth_ai/environments/examples/enron/agent_demos/test_synth_react.py +535 -0
- synth_ai/environments/examples/enron/art_helpers/email_search_tools.py +156 -0
- synth_ai/environments/examples/enron/art_helpers/local_email_db.py +280 -0
- synth_ai/environments/examples/enron/art_helpers/types_enron.py +24 -0
- synth_ai/environments/examples/enron/engine.py +291 -0
- synth_ai/environments/examples/enron/environment.py +165 -0
- synth_ai/environments/examples/enron/taskset.py +112 -0
- synth_ai/environments/examples/enron/units/keyword_stats.py +111 -0
- synth_ai/environments/examples/enron/units/test_email_index.py +8 -0
- synth_ai/environments/examples/minigrid/__init__.py +48 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_evaluation_framework.py +1188 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_quick_evaluation.py +47 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_react_agent.py +562 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_trace_evaluation.py +220 -0
- synth_ai/environments/examples/minigrid/agent_demos/test_minigrid_react_agent.py +393 -0
- synth_ai/environments/examples/minigrid/engine.py +589 -0
- synth_ai/environments/examples/minigrid/environment.py +274 -0
- synth_ai/environments/examples/minigrid/environment_mapping.py +242 -0
- synth_ai/environments/examples/minigrid/puzzle_loader.py +416 -0
- synth_ai/environments/examples/minigrid/taskset.py +583 -0
- synth_ai/environments/examples/minigrid/units/test_action_behavior.py +226 -0
- synth_ai/environments/examples/minigrid/units/test_debug_messages.py +83 -0
- synth_ai/environments/examples/minigrid/units/test_exploration.py +120 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_engine.py +214 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_environment.py +238 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_environment_mapping.py +301 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_taskset.py +210 -0
- synth_ai/environments/examples/nethack/__init__.py +7 -0
- synth_ai/environments/examples/nethack/achievements.py +337 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_evaluation_framework.py +981 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_quick_evaluation.py +74 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_react_agent.py +832 -0
- synth_ai/environments/examples/nethack/agent_demos/test_nethack_react_agent.py +1112 -0
- synth_ai/environments/examples/nethack/engine.py +738 -0
- synth_ai/environments/examples/nethack/environment.py +255 -0
- synth_ai/environments/examples/nethack/helpers/__init__.py +42 -0
- synth_ai/environments/examples/nethack/helpers/action_mapping.py +301 -0
- synth_ai/environments/examples/nethack/helpers/nle_wrapper.py +401 -0
- synth_ai/environments/examples/nethack/helpers/observation_utils.py +433 -0
- synth_ai/environments/examples/nethack/helpers/recording_wrapper.py +201 -0
- synth_ai/environments/examples/nethack/helpers/trajectory_recorder.py +268 -0
- synth_ai/environments/examples/nethack/helpers/visualization/replay_viewer.py +308 -0
- synth_ai/environments/examples/nethack/helpers/visualization/visualizer.py +430 -0
- synth_ai/environments/examples/nethack/taskset.py +323 -0
- synth_ai/environments/examples/nethack/units/test_nethack_engine.py +277 -0
- synth_ai/environments/examples/nethack/units/test_nethack_environment.py +281 -0
- synth_ai/environments/examples/nethack/units/test_nethack_taskset.py +213 -0
- synth_ai/environments/examples/nethack/units/test_recording.py +307 -0
- synth_ai/environments/examples/red/__init__.py +7 -0
- synth_ai/environments/examples/red/agent_demos/__init__.py +1 -0
- synth_ai/environments/examples/red/agent_demos/test_synth_react.py +1471 -0
- synth_ai/environments/examples/red/config_logging.py +110 -0
- synth_ai/environments/examples/red/engine.py +693 -0
- synth_ai/environments/examples/red/engine_helpers/__init__.py +1 -0
- synth_ai/environments/examples/red/engine_helpers/memory_map.py +28 -0
- synth_ai/environments/examples/red/engine_helpers/reward_components.py +275 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/__init__.py +142 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/adaptive_rewards.py +56 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/battle_rewards.py +283 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/composite_rewards.py +149 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/economy_rewards.py +137 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/efficiency_rewards.py +56 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/exploration_rewards.py +330 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/novelty_rewards.py +120 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/pallet_town_rewards.py +558 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/pokemon_rewards.py +312 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/social_rewards.py +147 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/story_rewards.py +246 -0
- synth_ai/environments/examples/red/engine_helpers/screen_analysis.py +367 -0
- synth_ai/environments/examples/red/engine_helpers/state_extraction.py +139 -0
- synth_ai/environments/examples/red/environment.py +235 -0
- synth_ai/environments/examples/red/taskset.py +77 -0
- synth_ai/environments/examples/red/test_fixes.py +125 -0
- synth_ai/environments/examples/red/test_fixes_mock.py +148 -0
- synth_ai/environments/examples/red/units/__init__.py +1 -0
- synth_ai/environments/examples/red/units/test_basic_functionality.py +97 -0
- synth_ai/environments/examples/red/units/test_button_press_requirements.py +217 -0
- synth_ai/environments/examples/red/units/test_engine.py +192 -0
- synth_ai/environments/examples/red/units/test_environment.py +455 -0
- synth_ai/environments/examples/red/units/test_exploration_strategy.py +227 -0
- synth_ai/environments/examples/red/units/test_integration.py +217 -0
- synth_ai/environments/examples/red/units/test_memory_extraction.py +111 -0
- synth_ai/environments/examples/red/units/test_menu_bug_reproduction.py +1100 -0
- synth_ai/environments/examples/red/units/test_movement_debug.py +255 -0
- synth_ai/environments/examples/red/units/test_pokemon_mcts_debug.py +163 -0
- synth_ai/environments/examples/red/units/test_pokemon_mcts_verbose.py +117 -0
- synth_ai/environments/examples/red/units/test_red_basic.py +145 -0
- synth_ai/environments/examples/red/units/test_red_comprehensive.py +323 -0
- synth_ai/environments/examples/red/units/test_retry_movement.py +195 -0
- synth_ai/environments/examples/red/units/test_reward_components.py +186 -0
- synth_ai/environments/examples/red/units/test_rom_integration.py +260 -0
- synth_ai/environments/examples/red/units/test_taskset.py +116 -0
- synth_ai/environments/examples/red/units/test_tree.py +448 -0
- synth_ai/environments/examples/sokoban/__init__.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/sokoban_full_eval.py +900 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_dspy_react.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_sokoban_react_agent.py +498 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_lats.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_react_locally.py +748 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_react_service.py +296 -0
- synth_ai/environments/examples/sokoban/engine.py +675 -0
- synth_ai/environments/examples/sokoban/engine_helpers/__init__.py +1 -0
- synth_ai/environments/examples/sokoban/engine_helpers/room_utils.py +656 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/__init__.py +17 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/__init__.py +3 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/boxoban_env.py +129 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/render_utils.py +370 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/room_utils.py +331 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env.py +305 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_fixed_targets.py +66 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_pull.py +114 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_two_player.py +122 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_variations.py +394 -0
- synth_ai/environments/examples/sokoban/environment.py +228 -0
- synth_ai/environments/examples/sokoban/generate_verified_puzzles.py +438 -0
- synth_ai/environments/examples/sokoban/puzzle_loader.py +311 -0
- synth_ai/environments/examples/sokoban/taskset.py +425 -0
- synth_ai/environments/examples/sokoban/units/astar_common.py +94 -0
- synth_ai/environments/examples/sokoban/units/test_building_task_set.py +49 -0
- synth_ai/environments/examples/sokoban/units/test_false_positive.py +120 -0
- synth_ai/environments/examples/sokoban/units/test_simple_run_through_environment.py +119 -0
- synth_ai/environments/examples/sokoban/units/test_sokoban_environment.py +98 -0
- synth_ai/environments/examples/sokoban/units/test_tree.py +364 -0
- synth_ai/environments/examples/tictactoe/__init__.py +1 -0
- synth_ai/environments/examples/tictactoe/agent_demos/test_synth_react.py +266 -0
- synth_ai/environments/examples/tictactoe/agent_demos/test_tictactoe_react_agent.py +470 -0
- synth_ai/environments/examples/tictactoe/engine.py +368 -0
- synth_ai/environments/examples/tictactoe/environment.py +239 -0
- synth_ai/environments/examples/tictactoe/taskset.py +214 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_engine.py +393 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_environment.py +493 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_taskset.py +191 -0
- synth_ai/environments/examples/verilog/__init__.py +10 -0
- synth_ai/environments/examples/verilog/agent_demos/test_synth_react.py +520 -0
- synth_ai/environments/examples/verilog/engine.py +328 -0
- synth_ai/environments/examples/verilog/environment.py +349 -0
- synth_ai/environments/examples/verilog/taskset.py +418 -0
- synth_ai/environments/examples/verilog/units/test_verilog_engine.py +466 -0
- synth_ai/environments/examples/verilog/units/test_verilog_environment.py +585 -0
- synth_ai/environments/examples/verilog/units/test_verilog_integration.py +383 -0
- synth_ai/environments/examples/verilog/units/test_verilog_taskset.py +457 -0
- synth_ai/environments/reproducibility/core.py +42 -0
- synth_ai/environments/reproducibility/tree.py +364 -0
- synth_ai/environments/service/app.py +78 -0
- synth_ai/environments/service/core_routes.py +775 -0
- synth_ai/environments/service/external_registry.py +57 -0
- synth_ai/environments/service/registry.py +9 -0
- synth_ai/environments/stateful/__init__.py +1 -0
- synth_ai/environments/stateful/core.py +28 -0
- synth_ai/environments/stateful/engine.py +21 -0
- synth_ai/environments/stateful/state.py +7 -0
- synth_ai/environments/tasks/api.py +19 -0
- synth_ai/environments/tasks/core.py +78 -0
- synth_ai/environments/tasks/filters.py +39 -0
- synth_ai/environments/tasks/utils.py +89 -0
- synth_ai/environments/v0_observability/history.py +3 -0
- synth_ai/environments/v0_observability/log.py +2 -0
- synth_ai/lm/caching/constants.py +1 -0
- synth_ai/{zyk/lms → lm}/caching/ephemeral.py +4 -8
- synth_ai/{zyk/lms → lm}/caching/handler.py +15 -15
- synth_ai/{zyk/lms → lm}/caching/initialize.py +2 -4
- synth_ai/{zyk/lms → lm}/caching/persistent.py +4 -10
- synth_ai/{zyk/lms → lm}/config.py +2 -1
- synth_ai/{zyk/lms → lm}/constants.py +2 -2
- synth_ai/{zyk/lms → lm}/core/all.py +10 -10
- synth_ai/{zyk/lms → lm}/core/main.py +57 -33
- synth_ai/{zyk/lms → lm}/core/vendor_clients.py +12 -10
- synth_ai/lm/cost/monitor.py +1 -0
- synth_ai/lm/cost/statefulness.py +1 -0
- synth_ai/lm/provider_support/__init__.py +8 -0
- synth_ai/lm/provider_support/anthropic.py +945 -0
- synth_ai/lm/provider_support/openai.py +1115 -0
- synth_ai/lm/provider_support/suppress_logging.py +31 -0
- synth_ai/{zyk/lms → lm}/structured_outputs/handler.py +58 -80
- synth_ai/{zyk/lms → lm}/structured_outputs/inject.py +6 -20
- synth_ai/{zyk/lms → lm}/structured_outputs/rehabilitate.py +6 -12
- synth_ai/{zyk/lms → lm}/vendors/core/anthropic_api.py +21 -30
- synth_ai/{zyk/lms → lm}/vendors/core/gemini_api.py +37 -32
- synth_ai/{zyk/lms → lm}/vendors/core/mistral_api.py +19 -28
- synth_ai/{zyk/lms → lm}/vendors/core/openai_api.py +26 -36
- synth_ai/{zyk/lms → lm}/vendors/openai_standard.py +29 -33
- synth_ai/{zyk/lms → lm}/vendors/retries.py +1 -1
- synth_ai/lm/vendors/supported/__init__.py +0 -0
- synth_ai/{zyk/lms → lm}/vendors/supported/custom_endpoint.py +131 -118
- synth_ai/{zyk/lms → lm}/vendors/supported/deepseek.py +4 -8
- synth_ai/{zyk/lms → lm}/vendors/supported/grok.py +6 -8
- synth_ai/{zyk/lms → lm}/vendors/supported/groq.py +1 -1
- synth_ai/{zyk/lms → lm}/vendors/supported/ollama.py +2 -2
- synth_ai/{zyk/lms → lm}/vendors/supported/openrouter.py +18 -16
- synth_ai/{zyk/lms → lm}/vendors/supported/together.py +1 -1
- synth_ai/tracing/__init__.py +0 -0
- synth_ai/tracing/abstractions.py +224 -0
- synth_ai/tracing/base_client.py +91 -0
- synth_ai/tracing/client_manager.py +131 -0
- synth_ai/tracing/config.py +140 -0
- synth_ai/tracing/context.py +146 -0
- synth_ai/tracing/decorators.py +679 -0
- synth_ai/tracing/events/__init__.py +0 -0
- synth_ai/tracing/events/manage.py +147 -0
- synth_ai/tracing/events/scope.py +86 -0
- synth_ai/tracing/events/store.py +227 -0
- synth_ai/tracing/immediate_client.py +152 -0
- synth_ai/tracing/local.py +18 -0
- synth_ai/tracing/log_client_base.py +74 -0
- synth_ai/tracing/retry_queue.py +187 -0
- synth_ai/tracing/trackers.py +515 -0
- synth_ai/tracing/upload.py +504 -0
- synth_ai/tracing/utils.py +9 -0
- synth_ai/zyk/__init__.py +28 -2
- synth_ai-0.2.1.dev0.dist-info/METADATA +349 -0
- synth_ai-0.2.1.dev0.dist-info/RECORD +261 -0
- synth_ai/zyk/lms/caching/constants.py +0 -1
- synth_ai/zyk/lms/cost/monitor.py +0 -1
- synth_ai/zyk/lms/cost/statefulness.py +0 -1
- synth_ai-0.1.9.dist-info/METADATA +0 -37
- synth_ai-0.1.9.dist-info/RECORD +0 -50
- /synth_ai/{zyk/lms/__init__.py → environments/reproducibility/helpers.py} +0 -0
- /synth_ai/{zyk/lms/caching → lm}/__init__.py +0 -0
- /synth_ai/{zyk/lms/core → lm/caching}/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/caching/dbs.py +0 -0
- /synth_ai/{zyk/lms/cost → lm/core}/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/core/exceptions.py +0 -0
- /synth_ai/{zyk/lms/structured_outputs → lm/cost}/__init__.py +0 -0
- /synth_ai/{zyk/lms/vendors → lm/structured_outputs}/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/tools/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/tools/base.py +0 -0
- /synth_ai/{zyk/lms/vendors/core → lm/vendors}/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/vendors/base.py +0 -0
- /synth_ai/{zyk/lms/vendors/local → lm/vendors/core}/__init__.py +0 -0
- /synth_ai/{zyk/lms/vendors/supported → lm/vendors/local}/__init__.py +0 -0
- /synth_ai/{zyk/lms → lm}/vendors/local/ollama.py +0 -0
- {synth_ai-0.1.9.dist-info → synth_ai-0.2.1.dev0.dist-info}/WHEEL +0 -0
- {synth_ai-0.1.9.dist-info → synth_ai-0.2.1.dev0.dist-info}/licenses/LICENSE +0 -0
- {synth_ai-0.1.9.dist-info → synth_ai-0.2.1.dev0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
from .sokoban_env import SokobanEnv
|
2
|
+
from .render_utils import room_to_rgb
|
3
|
+
import os
|
4
|
+
from os import listdir
|
5
|
+
from os.path import isfile, join
|
6
|
+
import requests
|
7
|
+
import zipfile
|
8
|
+
from tqdm import tqdm
|
9
|
+
import random
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
|
13
|
+
class BoxobanEnv(SokobanEnv):
|
14
|
+
num_boxes = 4
|
15
|
+
dim_room = (10, 10)
|
16
|
+
|
17
|
+
def __init__(self, max_steps=120, difficulty="unfiltered", split="train"):
|
18
|
+
self.difficulty = difficulty
|
19
|
+
self.split = split
|
20
|
+
self.verbose = False
|
21
|
+
super(BoxobanEnv, self).__init__(self.dim_room, max_steps, self.num_boxes, None)
|
22
|
+
|
23
|
+
def reset(self):
|
24
|
+
self.cache_path = ".sokoban_cache"
|
25
|
+
self.train_data_dir = os.path.join(
|
26
|
+
self.cache_path, "boxoban-levels-master", self.difficulty, self.split
|
27
|
+
)
|
28
|
+
|
29
|
+
if not os.path.exists(self.cache_path):
|
30
|
+
url = "https://github.com/deepmind/boxoban-levels/archive/master.zip"
|
31
|
+
|
32
|
+
if self.verbose:
|
33
|
+
print("Boxoban: Pregenerated levels not downloaded.")
|
34
|
+
print('Starting download from "{}"'.format(url))
|
35
|
+
|
36
|
+
response = requests.get(url, stream=True)
|
37
|
+
|
38
|
+
if response.status_code != 200:
|
39
|
+
raise "Could not download levels from {}. If this problem occurs consistantly please report the bug under https://github.com/mpSchrader/gym-sokoban/issues. ".format(
|
40
|
+
url
|
41
|
+
)
|
42
|
+
|
43
|
+
os.makedirs(self.cache_path)
|
44
|
+
path_to_zip_file = os.path.join(self.cache_path, "boxoban_levels-master.zip")
|
45
|
+
with open(path_to_zip_file, "wb") as handle:
|
46
|
+
for data in tqdm(response.iter_content()):
|
47
|
+
handle.write(data)
|
48
|
+
|
49
|
+
zip_ref = zipfile.ZipFile(path_to_zip_file, "r")
|
50
|
+
zip_ref.extractall(self.cache_path)
|
51
|
+
zip_ref.close()
|
52
|
+
|
53
|
+
self.select_room()
|
54
|
+
|
55
|
+
self.num_env_steps = 0
|
56
|
+
self.reward_last = 0
|
57
|
+
self.boxes_on_target = 0
|
58
|
+
|
59
|
+
starting_observation = room_to_rgb(self.room_state, self.room_fixed)
|
60
|
+
|
61
|
+
return starting_observation
|
62
|
+
|
63
|
+
def select_room(self):
|
64
|
+
generated_files = [
|
65
|
+
f for f in listdir(self.train_data_dir) if isfile(join(self.train_data_dir, f))
|
66
|
+
]
|
67
|
+
source_file = join(self.train_data_dir, random.choice(generated_files))
|
68
|
+
|
69
|
+
maps = []
|
70
|
+
current_map = []
|
71
|
+
|
72
|
+
with open(source_file, "r") as sf:
|
73
|
+
for line in sf.readlines():
|
74
|
+
if ";" in line and current_map:
|
75
|
+
maps.append(current_map)
|
76
|
+
current_map = []
|
77
|
+
if "#" == line[0]:
|
78
|
+
current_map.append(line.strip())
|
79
|
+
|
80
|
+
maps.append(current_map)
|
81
|
+
|
82
|
+
selected_map = random.choice(maps)
|
83
|
+
|
84
|
+
if self.verbose:
|
85
|
+
print('Selected Level from File "{}"'.format(source_file))
|
86
|
+
|
87
|
+
self.room_fixed, self.room_state, self.box_mapping = self.generate_room(selected_map)
|
88
|
+
|
89
|
+
def generate_room(self, select_map):
|
90
|
+
room_fixed = []
|
91
|
+
room_state = []
|
92
|
+
|
93
|
+
targets = []
|
94
|
+
boxes = []
|
95
|
+
for row in select_map:
|
96
|
+
room_f = []
|
97
|
+
room_s = []
|
98
|
+
|
99
|
+
for e in row:
|
100
|
+
if e == "#":
|
101
|
+
room_f.append(0)
|
102
|
+
room_s.append(0)
|
103
|
+
|
104
|
+
elif e == "@":
|
105
|
+
self.player_position = np.array([len(room_fixed), len(room_f)])
|
106
|
+
room_f.append(1)
|
107
|
+
room_s.append(5)
|
108
|
+
|
109
|
+
elif e == "$":
|
110
|
+
boxes.append((len(room_fixed), len(room_f)))
|
111
|
+
room_f.append(1)
|
112
|
+
room_s.append(4)
|
113
|
+
|
114
|
+
elif e == ".":
|
115
|
+
targets.append((len(room_fixed), len(room_f)))
|
116
|
+
room_f.append(2)
|
117
|
+
room_s.append(2)
|
118
|
+
|
119
|
+
else:
|
120
|
+
room_f.append(1)
|
121
|
+
room_s.append(1)
|
122
|
+
|
123
|
+
room_fixed.append(room_f)
|
124
|
+
room_state.append(room_s)
|
125
|
+
|
126
|
+
# used for replay in room generation, unused here because pre-generated levels
|
127
|
+
box_mapping = {}
|
128
|
+
|
129
|
+
return np.array(room_fixed), np.array(room_state), box_mapping
|
@@ -0,0 +1,370 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import pkg_resources
|
3
|
+
import imageio
|
4
|
+
|
5
|
+
|
6
|
+
def room_to_rgb(room, room_structure=None):
|
7
|
+
"""
|
8
|
+
Creates an RGB image of the room.
|
9
|
+
:param room:
|
10
|
+
:param room_structure:
|
11
|
+
:return:
|
12
|
+
"""
|
13
|
+
resource_package = __name__
|
14
|
+
|
15
|
+
room = np.array(room)
|
16
|
+
if not room_structure is None:
|
17
|
+
# Change the ID of a player on a target
|
18
|
+
room[(room == 5) & (room_structure == 2)] = 6
|
19
|
+
|
20
|
+
# Load images, representing the corresponding situation
|
21
|
+
box_filename = pkg_resources.resource_filename(
|
22
|
+
resource_package, "/".join(("surface", "box.png"))
|
23
|
+
)
|
24
|
+
box = imageio.imread(box_filename)
|
25
|
+
|
26
|
+
box_on_target_filename = pkg_resources.resource_filename(
|
27
|
+
resource_package, "/".join(("surface", "box_on_target.png"))
|
28
|
+
)
|
29
|
+
box_on_target = imageio.imread(box_on_target_filename)
|
30
|
+
|
31
|
+
box_target_filename = pkg_resources.resource_filename(
|
32
|
+
resource_package, "/".join(("surface", "box_target.png"))
|
33
|
+
)
|
34
|
+
box_target = imageio.imread(box_target_filename)
|
35
|
+
|
36
|
+
floor_filename = pkg_resources.resource_filename(
|
37
|
+
resource_package, "/".join(("surface", "floor.png"))
|
38
|
+
)
|
39
|
+
floor = imageio.imread(floor_filename)
|
40
|
+
|
41
|
+
player_filename = pkg_resources.resource_filename(
|
42
|
+
resource_package, "/".join(("surface", "player.png"))
|
43
|
+
)
|
44
|
+
player = imageio.imread(player_filename)
|
45
|
+
|
46
|
+
player_on_target_filename = pkg_resources.resource_filename(
|
47
|
+
resource_package, "/".join(("surface", "player_on_target.png"))
|
48
|
+
)
|
49
|
+
player_on_target = imageio.imread(player_on_target_filename)
|
50
|
+
|
51
|
+
wall_filename = pkg_resources.resource_filename(
|
52
|
+
resource_package, "/".join(("surface", "wall.png"))
|
53
|
+
)
|
54
|
+
wall = imageio.imread(wall_filename)
|
55
|
+
|
56
|
+
surfaces = [wall, floor, box_target, box_on_target, box, player, player_on_target]
|
57
|
+
|
58
|
+
# Assemble the new rgb_room, with all loaded images
|
59
|
+
room_rgb = np.zeros(shape=(room.shape[0] * 16, room.shape[1] * 16, 3), dtype=np.uint8)
|
60
|
+
for i in range(room.shape[0]):
|
61
|
+
x_i = i * 16
|
62
|
+
|
63
|
+
for j in range(room.shape[1]):
|
64
|
+
y_j = j * 16
|
65
|
+
surfaces_id = room[i, j]
|
66
|
+
|
67
|
+
room_rgb[x_i : (x_i + 16), y_j : (y_j + 16), :] = surfaces[surfaces_id]
|
68
|
+
|
69
|
+
return room_rgb
|
70
|
+
|
71
|
+
|
72
|
+
def room_to_tiny_world_rgb(room, room_structure=None, scale=1):
|
73
|
+
room = np.array(room)
|
74
|
+
if not room_structure is None:
|
75
|
+
# Change the ID of a player on a target
|
76
|
+
room[(room == 5) & (room_structure == 2)] = 6
|
77
|
+
|
78
|
+
wall = [0, 0, 0]
|
79
|
+
floor = [243, 248, 238]
|
80
|
+
box_target = [254, 126, 125]
|
81
|
+
box_on_target = [254, 95, 56]
|
82
|
+
box = [142, 121, 56]
|
83
|
+
player = [160, 212, 56]
|
84
|
+
player_on_target = [219, 212, 56]
|
85
|
+
|
86
|
+
surfaces = [wall, floor, box_target, box_on_target, box, player, player_on_target]
|
87
|
+
|
88
|
+
# Assemble the new rgb_room, with all loaded images
|
89
|
+
room_small_rgb = np.zeros(
|
90
|
+
shape=(room.shape[0] * scale, room.shape[1] * scale, 3), dtype=np.uint8
|
91
|
+
)
|
92
|
+
for i in range(room.shape[0]):
|
93
|
+
x_i = i * scale
|
94
|
+
for j in range(room.shape[1]):
|
95
|
+
y_j = j * scale
|
96
|
+
surfaces_id = int(room[i, j])
|
97
|
+
room_small_rgb[x_i : (x_i + scale), y_j : (y_j + scale), :] = np.array(
|
98
|
+
surfaces[surfaces_id]
|
99
|
+
)
|
100
|
+
|
101
|
+
return room_small_rgb
|
102
|
+
|
103
|
+
|
104
|
+
def room_to_rgb_FT(room, box_mapping, room_structure=None):
|
105
|
+
"""
|
106
|
+
Creates an RGB image of the room.
|
107
|
+
:param room:
|
108
|
+
:param room_structure:
|
109
|
+
:return:
|
110
|
+
"""
|
111
|
+
resource_package = __name__
|
112
|
+
|
113
|
+
room = np.array(room)
|
114
|
+
if not room_structure is None:
|
115
|
+
# Change the ID of a player on a target
|
116
|
+
room[(room == 5) & (room_structure == 2)] = 6
|
117
|
+
|
118
|
+
# Load images, representing the corresponding situation
|
119
|
+
box_filename = pkg_resources.resource_filename(
|
120
|
+
resource_package, "/".join(("surface", "box.png"))
|
121
|
+
)
|
122
|
+
box = imageio.imread(box_filename)
|
123
|
+
|
124
|
+
box_on_target_filename = pkg_resources.resource_filename(
|
125
|
+
resource_package, "/".join(("surface", "box_on_target.png"))
|
126
|
+
)
|
127
|
+
box_on_target = imageio.imread(box_on_target_filename)
|
128
|
+
|
129
|
+
box_target_filename = pkg_resources.resource_filename(
|
130
|
+
resource_package, "/".join(("surface", "box_target.png"))
|
131
|
+
)
|
132
|
+
box_target = imageio.imread(box_target_filename)
|
133
|
+
|
134
|
+
floor_filename = pkg_resources.resource_filename(
|
135
|
+
resource_package, "/".join(("surface", "floor.png"))
|
136
|
+
)
|
137
|
+
floor = imageio.imread(floor_filename)
|
138
|
+
|
139
|
+
player_filename = pkg_resources.resource_filename(
|
140
|
+
resource_package, "/".join(("surface", "player.png"))
|
141
|
+
)
|
142
|
+
player = imageio.imread(player_filename)
|
143
|
+
|
144
|
+
player_on_target_filename = pkg_resources.resource_filename(
|
145
|
+
resource_package, "/".join(("surface", "player_on_target.png"))
|
146
|
+
)
|
147
|
+
player_on_target = imageio.imread(player_on_target_filename)
|
148
|
+
|
149
|
+
wall_filename = pkg_resources.resource_filename(
|
150
|
+
resource_package, "/".join(("surface", "wall.png"))
|
151
|
+
)
|
152
|
+
wall = imageio.imread(wall_filename)
|
153
|
+
|
154
|
+
surfaces = [wall, floor, box_target, box_on_target, box, player, player_on_target]
|
155
|
+
|
156
|
+
# Assemble the new rgb_room, with all loaded images
|
157
|
+
room_rgb = np.zeros(shape=(room.shape[0] * 16, room.shape[1] * 16, 3), dtype=np.uint8)
|
158
|
+
for i in range(room.shape[0]):
|
159
|
+
x_i = i * 16
|
160
|
+
|
161
|
+
for j in range(room.shape[1]):
|
162
|
+
y_j = j * 16
|
163
|
+
|
164
|
+
surfaces_id = room[i, j]
|
165
|
+
surface = surfaces[surfaces_id]
|
166
|
+
if 1 < surfaces_id < 5:
|
167
|
+
try:
|
168
|
+
surface = get_proper_box_surface(surfaces_id, box_mapping, i, j)
|
169
|
+
except:
|
170
|
+
pass
|
171
|
+
room_rgb[x_i : (x_i + 16), y_j : (y_j + 16), :] = surface
|
172
|
+
|
173
|
+
return room_rgb
|
174
|
+
|
175
|
+
|
176
|
+
def get_proper_box_surface(surfaces_id, box_mapping, i, j):
|
177
|
+
# not used, kept for documentation
|
178
|
+
# names = ["wall", "floor", "box_target", "box_on_target", "box", "player", "player_on_target"]
|
179
|
+
|
180
|
+
box_id = 0
|
181
|
+
situation = ""
|
182
|
+
|
183
|
+
if surfaces_id == 2:
|
184
|
+
situation = "_target"
|
185
|
+
box_id = list(box_mapping.keys()).index((i, j))
|
186
|
+
elif surfaces_id == 3:
|
187
|
+
box_id = list(box_mapping.values()).index((i, j))
|
188
|
+
box_key = list(box_mapping.keys())[box_id]
|
189
|
+
if box_key == (i, j):
|
190
|
+
situation = "_on_target"
|
191
|
+
else:
|
192
|
+
situation = "_on_wrong_target"
|
193
|
+
pass
|
194
|
+
elif surfaces_id == 4:
|
195
|
+
box_id = list(box_mapping.values()).index((i, j))
|
196
|
+
|
197
|
+
surface_name = "box{}{}.png".format(box_id, situation)
|
198
|
+
resource_package = __name__
|
199
|
+
filename = pkg_resources.resource_filename(
|
200
|
+
resource_package, "/".join(("surface", "multibox", surface_name))
|
201
|
+
)
|
202
|
+
surface = imageio.imread(filename)
|
203
|
+
|
204
|
+
return surface
|
205
|
+
|
206
|
+
|
207
|
+
def room_to_tiny_world_rgb_FT(room, box_mapping, room_structure=None, scale=1):
|
208
|
+
room = np.array(room)
|
209
|
+
if not room_structure is None:
|
210
|
+
# Change the ID of a player on a target
|
211
|
+
room[(room == 5) & (room_structure == 2)] = 6
|
212
|
+
|
213
|
+
wall = [0, 0, 0]
|
214
|
+
floor = [243, 248, 238]
|
215
|
+
box_target = [254, 126, 125]
|
216
|
+
box_on_target = [254, 95, 56]
|
217
|
+
box = [142, 121, 56]
|
218
|
+
player = [160, 212, 56]
|
219
|
+
player_on_target = [219, 212, 56]
|
220
|
+
|
221
|
+
surfaces = [wall, floor, box_target, box_on_target, box, player, player_on_target]
|
222
|
+
|
223
|
+
# Assemble the new rgb_room, with all loaded images
|
224
|
+
room_small_rgb = np.zeros(
|
225
|
+
shape=(room.shape[0] * scale, room.shape[1] * scale, 3), dtype=np.uint8
|
226
|
+
)
|
227
|
+
for i in range(room.shape[0]):
|
228
|
+
x_i = i * scale
|
229
|
+
for j in range(room.shape[1]):
|
230
|
+
y_j = j * scale
|
231
|
+
|
232
|
+
surfaces_id = int(room[i, j])
|
233
|
+
surface = np.array(surfaces[surfaces_id])
|
234
|
+
if 1 < surfaces_id < 5:
|
235
|
+
try:
|
236
|
+
surface = get_proper_tiny_box_surface(surfaces_id, box_mapping, i, j)
|
237
|
+
except:
|
238
|
+
pass
|
239
|
+
room_small_rgb[x_i : (x_i + scale), y_j : (y_j + scale), :] = surface
|
240
|
+
|
241
|
+
return room_small_rgb
|
242
|
+
|
243
|
+
|
244
|
+
def get_proper_tiny_box_surface(surfaces_id, box_mapping, i, j):
|
245
|
+
box_id = 0
|
246
|
+
situation = "box"
|
247
|
+
|
248
|
+
if surfaces_id == 2:
|
249
|
+
situation = "target"
|
250
|
+
box_id = list(box_mapping.keys()).index((i, j))
|
251
|
+
elif surfaces_id == 3:
|
252
|
+
box_id = list(box_mapping.values()).index((i, j))
|
253
|
+
box_key = list(box_mapping.keys())[box_id]
|
254
|
+
if box_key == (i, j):
|
255
|
+
situation = "on_target"
|
256
|
+
else:
|
257
|
+
situation = "on_wrong_target"
|
258
|
+
pass
|
259
|
+
elif surfaces_id == 4:
|
260
|
+
box_id = list(box_mapping.values()).index((i, j))
|
261
|
+
|
262
|
+
surface = [255, 255, 255]
|
263
|
+
if box_id == 0:
|
264
|
+
if situation == "target":
|
265
|
+
surface = [111, 127, 232]
|
266
|
+
elif situation == "on_target":
|
267
|
+
surface = [6, 33, 130]
|
268
|
+
elif situation == "on_wrong_target":
|
269
|
+
surface = [69, 81, 122]
|
270
|
+
else:
|
271
|
+
# Just the box
|
272
|
+
surface = [11, 60, 237]
|
273
|
+
|
274
|
+
elif box_id == 1:
|
275
|
+
if situation == "target":
|
276
|
+
surface = [195, 127, 232]
|
277
|
+
elif situation == "on_target":
|
278
|
+
surface = [96, 5, 145]
|
279
|
+
elif situation == "on_wrong_target":
|
280
|
+
surface = [96, 63, 114]
|
281
|
+
else:
|
282
|
+
surface = [145, 17, 214]
|
283
|
+
|
284
|
+
elif box_id == 2:
|
285
|
+
if situation == "target":
|
286
|
+
surface = [221, 113, 167]
|
287
|
+
elif situation == "on_target":
|
288
|
+
surface = [140, 5, 72]
|
289
|
+
elif situation == "on_wrong_target":
|
290
|
+
surface = [109, 60, 71]
|
291
|
+
else:
|
292
|
+
surface = [239, 0, 55]
|
293
|
+
|
294
|
+
elif box_id == 3:
|
295
|
+
if situation == "target":
|
296
|
+
surface = [247, 193, 145]
|
297
|
+
elif situation == "on_target":
|
298
|
+
surface = [132, 64, 3]
|
299
|
+
elif situation == "on_wrong_target":
|
300
|
+
surface = [94, 68, 46]
|
301
|
+
else:
|
302
|
+
surface = [239, 111, 0]
|
303
|
+
|
304
|
+
return surface
|
305
|
+
|
306
|
+
|
307
|
+
def color_player_two(room_rgb, position, room_structure):
|
308
|
+
resource_package = __name__
|
309
|
+
|
310
|
+
player_filename = pkg_resources.resource_filename(
|
311
|
+
resource_package, "/".join(("surface", "multiplayer", "player1.png"))
|
312
|
+
)
|
313
|
+
player = imageio.imread(player_filename)
|
314
|
+
|
315
|
+
player_on_target_filename = pkg_resources.resource_filename(
|
316
|
+
resource_package, "/".join(("surface", "multiplayer", "player1_on_target.png"))
|
317
|
+
)
|
318
|
+
player_on_target = imageio.imread(player_on_target_filename)
|
319
|
+
|
320
|
+
x_i = position[0] * 16
|
321
|
+
y_j = position[1] * 16
|
322
|
+
|
323
|
+
if room_structure[position[0], position[1]] == 2:
|
324
|
+
room_rgb[x_i : (x_i + 16), y_j : (y_j + 16), :] = player_on_target
|
325
|
+
|
326
|
+
else:
|
327
|
+
room_rgb[x_i : (x_i + 16), y_j : (y_j + 16), :] = player
|
328
|
+
|
329
|
+
return room_rgb
|
330
|
+
|
331
|
+
|
332
|
+
def color_tiny_player_two(room_rgb, position, room_structure, scale=4):
|
333
|
+
x_i = position[0] * scale
|
334
|
+
y_j = position[1] * scale
|
335
|
+
|
336
|
+
if room_structure[position[0], position[1]] == 2:
|
337
|
+
room_rgb[x_i : (x_i + scale), y_j : (y_j + scale), :] = [195, 127, 232]
|
338
|
+
|
339
|
+
else:
|
340
|
+
room_rgb[x_i : (x_i + scale), y_j : (y_j + scale), :] = [96, 5, 145]
|
341
|
+
|
342
|
+
return room_rgb
|
343
|
+
|
344
|
+
|
345
|
+
TYPE_LOOKUP = {
|
346
|
+
0: "wall",
|
347
|
+
1: "empty space",
|
348
|
+
2: "box target",
|
349
|
+
3: "box on target",
|
350
|
+
4: "box not on target",
|
351
|
+
5: "player",
|
352
|
+
}
|
353
|
+
|
354
|
+
ACTION_LOOKUP = {
|
355
|
+
0: "push up",
|
356
|
+
1: "push down",
|
357
|
+
2: "push left",
|
358
|
+
3: "push right",
|
359
|
+
4: "move up",
|
360
|
+
5: "move down",
|
361
|
+
6: "move left",
|
362
|
+
7: "move right",
|
363
|
+
}
|
364
|
+
|
365
|
+
# Moves are mapped to coordinate changes as follows
|
366
|
+
# 0: Move up
|
367
|
+
# 1: Move down
|
368
|
+
# 2: Move left
|
369
|
+
# 3: Move right
|
370
|
+
CHANGE_COORDINATES = {0: (-1, 0), 1: (1, 0), 2: (0, -1), 3: (0, 1)}
|