synth-ai 0.2.4.dev4__py3-none-any.whl → 0.2.4.dev6__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.
Files changed (123) hide show
  1. synth_ai/environments/examples/__init__.py +1 -0
  2. synth_ai/environments/examples/crafter_classic/__init__.py +8 -0
  3. synth_ai/environments/examples/crafter_classic/config_logging.py +111 -0
  4. synth_ai/environments/examples/crafter_classic/debug_translation.py +0 -0
  5. synth_ai/environments/examples/crafter_classic/engine.py +579 -0
  6. synth_ai/environments/examples/crafter_classic/engine_deterministic_patch.py +63 -0
  7. synth_ai/environments/examples/crafter_classic/engine_helpers/action_map.py +5 -0
  8. synth_ai/environments/examples/crafter_classic/engine_helpers/serialization.py +74 -0
  9. synth_ai/environments/examples/crafter_classic/engine_serialization_patch_v3.py +266 -0
  10. synth_ai/environments/examples/crafter_classic/environment.py +364 -0
  11. synth_ai/environments/examples/crafter_classic/taskset.py +233 -0
  12. synth_ai/environments/examples/crafter_classic/trace_hooks_v3.py +229 -0
  13. synth_ai/environments/examples/crafter_classic/world_config_patch_simple.py +298 -0
  14. synth_ai/environments/examples/crafter_custom/__init__.py +4 -0
  15. synth_ai/environments/examples/crafter_custom/crafter/__init__.py +7 -0
  16. synth_ai/environments/examples/crafter_custom/crafter/config.py +182 -0
  17. synth_ai/environments/examples/crafter_custom/crafter/constants.py +8 -0
  18. synth_ai/environments/examples/crafter_custom/crafter/engine.py +269 -0
  19. synth_ai/environments/examples/crafter_custom/crafter/env.py +266 -0
  20. synth_ai/environments/examples/crafter_custom/crafter/objects.py +418 -0
  21. synth_ai/environments/examples/crafter_custom/crafter/recorder.py +187 -0
  22. synth_ai/environments/examples/crafter_custom/crafter/worldgen.py +119 -0
  23. synth_ai/environments/examples/crafter_custom/dataset_builder.py +373 -0
  24. synth_ai/environments/examples/crafter_custom/environment.py +312 -0
  25. synth_ai/environments/examples/crafter_custom/run_dataset.py +305 -0
  26. synth_ai/environments/examples/enron/art_helpers/email_search_tools.py +156 -0
  27. synth_ai/environments/examples/enron/art_helpers/local_email_db.py +280 -0
  28. synth_ai/environments/examples/enron/art_helpers/types_enron.py +24 -0
  29. synth_ai/environments/examples/enron/engine.py +291 -0
  30. synth_ai/environments/examples/enron/environment.py +165 -0
  31. synth_ai/environments/examples/enron/taskset.py +112 -0
  32. synth_ai/environments/examples/minigrid/__init__.py +48 -0
  33. synth_ai/environments/examples/minigrid/engine.py +589 -0
  34. synth_ai/environments/examples/minigrid/environment.py +274 -0
  35. synth_ai/environments/examples/minigrid/environment_mapping.py +242 -0
  36. synth_ai/environments/examples/minigrid/puzzle_loader.py +416 -0
  37. synth_ai/environments/examples/minigrid/taskset.py +583 -0
  38. synth_ai/environments/examples/nethack/__init__.py +7 -0
  39. synth_ai/environments/examples/nethack/achievements.py +337 -0
  40. synth_ai/environments/examples/nethack/engine.py +738 -0
  41. synth_ai/environments/examples/nethack/environment.py +255 -0
  42. synth_ai/environments/examples/nethack/helpers/__init__.py +42 -0
  43. synth_ai/environments/examples/nethack/helpers/action_mapping.py +301 -0
  44. synth_ai/environments/examples/nethack/helpers/nle_wrapper.py +401 -0
  45. synth_ai/environments/examples/nethack/helpers/observation_utils.py +433 -0
  46. synth_ai/environments/examples/nethack/helpers/recording_wrapper.py +201 -0
  47. synth_ai/environments/examples/nethack/helpers/trajectory_recorder.py +268 -0
  48. synth_ai/environments/examples/nethack/helpers/visualization/replay_viewer.py +308 -0
  49. synth_ai/environments/examples/nethack/helpers/visualization/visualizer.py +430 -0
  50. synth_ai/environments/examples/nethack/taskset.py +323 -0
  51. synth_ai/environments/examples/red/__init__.py +7 -0
  52. synth_ai/environments/examples/red/config_logging.py +110 -0
  53. synth_ai/environments/examples/red/engine.py +693 -0
  54. synth_ai/environments/examples/red/engine_helpers/__init__.py +1 -0
  55. synth_ai/environments/examples/red/engine_helpers/memory_map.py +28 -0
  56. synth_ai/environments/examples/red/engine_helpers/reward_components.py +275 -0
  57. synth_ai/environments/examples/red/engine_helpers/reward_library/__init__.py +142 -0
  58. synth_ai/environments/examples/red/engine_helpers/reward_library/adaptive_rewards.py +56 -0
  59. synth_ai/environments/examples/red/engine_helpers/reward_library/battle_rewards.py +283 -0
  60. synth_ai/environments/examples/red/engine_helpers/reward_library/composite_rewards.py +149 -0
  61. synth_ai/environments/examples/red/engine_helpers/reward_library/economy_rewards.py +137 -0
  62. synth_ai/environments/examples/red/engine_helpers/reward_library/efficiency_rewards.py +56 -0
  63. synth_ai/environments/examples/red/engine_helpers/reward_library/exploration_rewards.py +330 -0
  64. synth_ai/environments/examples/red/engine_helpers/reward_library/novelty_rewards.py +120 -0
  65. synth_ai/environments/examples/red/engine_helpers/reward_library/pallet_town_rewards.py +558 -0
  66. synth_ai/environments/examples/red/engine_helpers/reward_library/pokemon_rewards.py +312 -0
  67. synth_ai/environments/examples/red/engine_helpers/reward_library/social_rewards.py +147 -0
  68. synth_ai/environments/examples/red/engine_helpers/reward_library/story_rewards.py +246 -0
  69. synth_ai/environments/examples/red/engine_helpers/screen_analysis.py +367 -0
  70. synth_ai/environments/examples/red/engine_helpers/state_extraction.py +139 -0
  71. synth_ai/environments/examples/red/environment.py +235 -0
  72. synth_ai/environments/examples/red/taskset.py +77 -0
  73. synth_ai/environments/examples/sokoban/__init__.py +1 -0
  74. synth_ai/environments/examples/sokoban/engine.py +675 -0
  75. synth_ai/environments/examples/sokoban/engine_helpers/__init__.py +1 -0
  76. synth_ai/environments/examples/sokoban/engine_helpers/room_utils.py +656 -0
  77. synth_ai/environments/examples/sokoban/engine_helpers/vendored/__init__.py +17 -0
  78. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/__init__.py +3 -0
  79. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/boxoban_env.py +129 -0
  80. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/render_utils.py +370 -0
  81. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/room_utils.py +331 -0
  82. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env.py +305 -0
  83. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_fixed_targets.py +66 -0
  84. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_pull.py +114 -0
  85. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_two_player.py +122 -0
  86. synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_variations.py +394 -0
  87. synth_ai/environments/examples/sokoban/environment.py +228 -0
  88. synth_ai/environments/examples/sokoban/generate_verified_puzzles.py +438 -0
  89. synth_ai/environments/examples/sokoban/puzzle_loader.py +311 -0
  90. synth_ai/environments/examples/sokoban/taskset.py +425 -0
  91. synth_ai/environments/examples/tictactoe/__init__.py +1 -0
  92. synth_ai/environments/examples/tictactoe/engine.py +368 -0
  93. synth_ai/environments/examples/tictactoe/environment.py +239 -0
  94. synth_ai/environments/examples/tictactoe/taskset.py +214 -0
  95. synth_ai/environments/examples/verilog/__init__.py +10 -0
  96. synth_ai/environments/examples/verilog/engine.py +328 -0
  97. synth_ai/environments/examples/verilog/environment.py +349 -0
  98. synth_ai/environments/examples/verilog/taskset.py +418 -0
  99. synth_ai/environments/examples/wordle/__init__.py +29 -0
  100. synth_ai/environments/examples/wordle/engine.py +391 -0
  101. synth_ai/environments/examples/wordle/environment.py +154 -0
  102. synth_ai/environments/examples/wordle/helpers/generate_instances_wordfreq.py +75 -0
  103. synth_ai/environments/examples/wordle/taskset.py +222 -0
  104. synth_ai/environments/service/app.py +8 -0
  105. synth_ai/environments/service/core_routes.py +38 -0
  106. synth_ai/learning/prompts/banking77_injection_eval.py +163 -0
  107. synth_ai/learning/prompts/hello_world_in_context_injection_ex.py +201 -0
  108. synth_ai/learning/prompts/mipro.py +273 -1
  109. synth_ai/learning/prompts/random_search.py +247 -0
  110. synth_ai/learning/prompts/run_mipro_banking77.py +160 -0
  111. synth_ai/learning/prompts/run_random_search_banking77.py +305 -0
  112. synth_ai/lm/injection.py +81 -0
  113. synth_ai/lm/overrides.py +204 -0
  114. synth_ai/lm/provider_support/anthropic.py +39 -12
  115. synth_ai/lm/provider_support/openai.py +31 -4
  116. synth_ai/lm/vendors/core/anthropic_api.py +16 -0
  117. synth_ai/lm/vendors/openai_standard.py +35 -5
  118. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.dist-info}/METADATA +2 -1
  119. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.dist-info}/RECORD +123 -13
  120. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.dist-info}/WHEEL +0 -0
  121. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.dist-info}/entry_points.txt +0 -0
  122. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.dist-info}/licenses/LICENSE +0 -0
  123. {synth_ai-0.2.4.dev4.dist-info → synth_ai-0.2.4.dev6.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)}