|
@@ -1,34 +1,35 @@
|
|
1
|
+import pygame
|
|
2
|
+from intelligine.synergy.Colony import Colony
|
|
3
|
+from intelligine.synergy.Rocks import Rocks
|
|
4
|
+from synergine.synergy.Simulation import Simulation
|
|
5
|
+from synergine_xyz.display.PygameImageRotate import PygameImageRotate
|
|
6
|
+from synergine_xyz.display.PygameVisualisation import PygameVisualisation
|
1
|
7
|
from synergine_xyz.display.object.pygame.PygameImage import PygameImage
|
2
|
|
-from synergine_xyz.display.object.pygame.DirectionnedImage import DirectionnedImage
|
3
|
|
-from intelligine.synergy.object.Bug import Bug
|
4
|
8
|
from intelligine.synergy.object.Food import Food
|
5
|
|
-from intelligine.synergy.object.Hole import Hole
|
6
|
9
|
from intelligine.synergy.object.ant.Ant import Ant
|
7
|
|
-from intelligine.sandbox.colored.BlueAnt import BlueAnt
|
8
|
|
-from intelligine.sandbox.colored.RedAnt import RedAnt
|
9
|
|
-from intelligine.sandbox.colored.GreenAnt import GreenAnt
|
10
|
10
|
from intelligine.synergy.object.Rock import Rock
|
11
|
11
|
from intelligine.synergy.object.ant.Egg import Egg
|
12
|
12
|
from os import getcwd
|
13
|
13
|
from synergine_xyz.cst import PREVIOUS_DIRECTION
|
|
14
|
+from synergine_xyz.tmx.TileMapConnector import TileMapConnector
|
14
|
15
|
|
15
|
16
|
SURFACE_PHEROMONE_HOME = 'pheromone_home'
|
16
|
17
|
SURFACE_PHEROMONE_EXPLORATION = 'pheromone_exploration'
|
17
|
18
|
|
18
|
19
|
# TODO: Analyser les procedes ici pour proposer des outils dans le framework
|
19
|
20
|
|
20
|
|
-ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
|
21
|
|
-food = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/food.png')
|
22
|
|
-hole = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/hole.png')
|
23
|
|
-dead_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_ant.png')
|
24
|
|
-red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
|
25
|
|
-green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/green_ant.png')
|
26
|
|
-blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
|
27
|
|
-dead_red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_red_ant.png')
|
28
|
|
-dead_green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_green_ant.png')
|
29
|
|
-dead_blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_blue_ant.png')
|
30
|
|
-bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
|
31
|
|
-rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
|
|
21
|
+# ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
|
|
22
|
+# food = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/food.png')
|
|
23
|
+# hole = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/hole.png')
|
|
24
|
+# dead_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_ant.png')
|
|
25
|
+# red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
|
|
26
|
+# green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/green_ant.png')
|
|
27
|
+# blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
|
|
28
|
+# dead_red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_red_ant.png')
|
|
29
|
+# dead_green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_green_ant.png')
|
|
30
|
+# dead_blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_blue_ant.png')
|
|
31
|
+# bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
|
|
32
|
+# rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
|
32
|
33
|
egg = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg.png')
|
33
|
34
|
eggc2 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c2.png')
|
34
|
35
|
eggc3 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c3.png')
|
|
@@ -37,49 +38,49 @@ eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/eg
|
37
|
38
|
eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
|
38
|
39
|
phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
|
39
|
40
|
pheh = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/pheh.png')
|
40
|
|
-
|
41
|
|
-directions_ant = DirectionnedImage(ant)
|
42
|
|
-directions_red_ant = DirectionnedImage(red_ant)
|
43
|
|
-directions_blue_ant = DirectionnedImage(blue_ant)
|
44
|
|
-directions_green_ant = DirectionnedImage(green_ant)
|
45
|
|
-
|
46
|
|
-def bug_direction(bug, context):
|
47
|
|
- if bug.get_life_points() <= 0:
|
48
|
|
- return dead_ant
|
49
|
|
- try:
|
50
|
|
- previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
51
|
|
- except KeyError:
|
52
|
|
- previous_direction = 14
|
53
|
|
- return directions_ant.get_for_direction(previous_direction)
|
54
|
|
-
|
55
|
|
-def red_ant_direction(bug, context):
|
56
|
|
- if bug.get_life_points() <= 0:
|
57
|
|
- return dead_red_ant
|
58
|
|
- try:
|
59
|
|
- previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
60
|
|
- except KeyError:
|
61
|
|
- previous_direction = 14
|
62
|
|
- return directions_red_ant.get_for_direction(previous_direction)
|
63
|
|
-
|
64
|
|
-def blue_ant_direction(bug, context):
|
65
|
|
- if bug.get_life_points() <= 0:
|
66
|
|
- return dead_blue_ant
|
67
|
|
- try:
|
68
|
|
- previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
69
|
|
- except KeyError:
|
70
|
|
- previous_direction = 14
|
71
|
|
- return directions_blue_ant.get_for_direction(previous_direction)
|
72
|
|
-
|
73
|
|
-def green_ant_direction(bug, context):
|
74
|
|
- if bug.get_life_points() <= 0:
|
75
|
|
- return dead_green_ant
|
76
|
|
- try:
|
77
|
|
- previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
78
|
|
- except KeyError:
|
79
|
|
- previous_direction = 14
|
80
|
|
- return directions_green_ant.get_for_direction(previous_direction)
|
81
|
|
-
|
82
|
|
-
|
|
41
|
+#
|
|
42
|
+# directions_ant = DirectionnedImage(ant)
|
|
43
|
+# directions_red_ant = DirectionnedImage(red_ant)
|
|
44
|
+# directions_blue_ant = DirectionnedImage(blue_ant)
|
|
45
|
+# directions_green_ant = DirectionnedImage(green_ant)
|
|
46
|
+#
|
|
47
|
+# def bug_direction(bug, context):
|
|
48
|
+# if bug.get_life_points() <= 0:
|
|
49
|
+# return dead_ant
|
|
50
|
+# try:
|
|
51
|
+# previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
|
52
|
+# except KeyError:
|
|
53
|
+# previous_direction = 14
|
|
54
|
+# return directions_ant.get_for_direction(previous_direction)
|
|
55
|
+#
|
|
56
|
+# def red_ant_direction(bug, context):
|
|
57
|
+# if bug.get_life_points() <= 0:
|
|
58
|
+# return dead_red_ant
|
|
59
|
+# try:
|
|
60
|
+# previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
|
61
|
+# except KeyError:
|
|
62
|
+# previous_direction = 14
|
|
63
|
+# return directions_red_ant.get_for_direction(previous_direction)
|
|
64
|
+#
|
|
65
|
+# def blue_ant_direction(bug, context):
|
|
66
|
+# if bug.get_life_points() <= 0:
|
|
67
|
+# return dead_blue_ant
|
|
68
|
+# try:
|
|
69
|
+# previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
|
70
|
+# except KeyError:
|
|
71
|
+# previous_direction = 14
|
|
72
|
+# return directions_blue_ant.get_for_direction(previous_direction)
|
|
73
|
+#
|
|
74
|
+# def green_ant_direction(bug, context):
|
|
75
|
+# if bug.get_life_points() <= 0:
|
|
76
|
+# return dead_green_ant
|
|
77
|
+# try:
|
|
78
|
+# previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
|
|
79
|
+# except KeyError:
|
|
80
|
+# previous_direction = 14
|
|
81
|
+# return directions_green_ant.get_for_direction(previous_direction)
|
|
82
|
+#
|
|
83
|
+#
|
83
|
84
|
def for_position(position, objects, context):
|
84
|
85
|
# TODO: DEV TMP: refact, etc
|
85
|
86
|
eggs = []
|
|
@@ -95,54 +96,135 @@ def for_position(position, objects, context):
|
95
|
96
|
if len(eggs) > 4:
|
96
|
97
|
return (eggc7, eggs)
|
97
|
98
|
return (None, [])
|
|
99
|
+#
|
|
100
|
+# visualisation = {
|
|
101
|
+# 'window': {},
|
|
102
|
+# 'callbacks': {
|
|
103
|
+# 'position': for_position
|
|
104
|
+# },
|
|
105
|
+# 'surfaces': {
|
|
106
|
+# SURFACE_PHEROMONE_EXPLORATION: {
|
|
107
|
+# 'default': phee,
|
|
108
|
+# 'callbacks': []
|
|
109
|
+# },
|
|
110
|
+# SURFACE_PHEROMONE_HOME: {
|
|
111
|
+# 'default': pheh,
|
|
112
|
+# 'callbacks': []
|
|
113
|
+# },
|
|
114
|
+# },
|
|
115
|
+# 'objects': {
|
|
116
|
+# RedAnt: {
|
|
117
|
+# 'default': red_ant,
|
|
118
|
+# 'callbacks': [red_ant_direction]
|
|
119
|
+# },
|
|
120
|
+# BlueAnt: {
|
|
121
|
+# 'default': blue_ant,
|
|
122
|
+# 'callbacks': [blue_ant_direction]
|
|
123
|
+# },
|
|
124
|
+# GreenAnt: {
|
|
125
|
+# 'default': green_ant,
|
|
126
|
+# 'callbacks': [green_ant_direction]
|
|
127
|
+# },
|
|
128
|
+# Ant: {
|
|
129
|
+# 'default': ant,
|
|
130
|
+# 'callbacks': [bug_direction]
|
|
131
|
+# },
|
|
132
|
+# Bug: {
|
|
133
|
+# 'default': bug,
|
|
134
|
+# 'callbacks': [bug_direction]
|
|
135
|
+# },
|
|
136
|
+# Egg: {
|
|
137
|
+# 'default': egg
|
|
138
|
+# },
|
|
139
|
+# Rock: {
|
|
140
|
+# 'default': rock
|
|
141
|
+# },
|
|
142
|
+# Food: {
|
|
143
|
+# 'default': food
|
|
144
|
+# },
|
|
145
|
+# Hole: {
|
|
146
|
+# 'default': hole
|
|
147
|
+# }
|
|
148
|
+# }
|
|
149
|
+# }
|
|
150
|
+
|
|
151
|
+#############################
|
|
152
|
+# Behind, new
|
|
153
|
+#############################
|
98
|
154
|
|
99
|
|
-visualisation = {
|
100
|
|
- 'window': {},
|
101
|
|
- 'callbacks': {
|
102
|
|
- 'position': for_position
|
|
155
|
+map_config = {
|
|
156
|
+ 'simulation': {
|
|
157
|
+ 'base': Simulation
|
103
|
158
|
},
|
104
|
|
- 'surfaces': {
|
105
|
|
- SURFACE_PHEROMONE_EXPLORATION: {
|
106
|
|
- 'default': phee,
|
107
|
|
- 'callbacks': []
|
108
|
|
- },
|
109
|
|
- SURFACE_PHEROMONE_HOME: {
|
110
|
|
- 'default': pheh,
|
111
|
|
- 'callbacks': []
|
112
|
|
- },
|
|
159
|
+ 'collection': {
|
|
160
|
+ 'ant': Colony,
|
|
161
|
+ 'env': Rocks # TODO: Nom plus generique
|
113
|
162
|
},
|
114
|
|
- 'objects': {
|
115
|
|
- RedAnt: {
|
116
|
|
- 'default': red_ant,
|
117
|
|
- 'callbacks': [red_ant_direction]
|
118
|
|
- },
|
119
|
|
- BlueAnt: {
|
120
|
|
- 'default': blue_ant,
|
121
|
|
- 'callbacks': [blue_ant_direction]
|
122
|
|
- },
|
123
|
|
- GreenAnt: {
|
124
|
|
- 'default': green_ant,
|
125
|
|
- 'callbacks': [green_ant_direction]
|
126
|
|
- },
|
127
|
|
- Ant: {
|
128
|
|
- 'default': ant,
|
129
|
|
- 'callbacks': [bug_direction]
|
130
|
|
- },
|
131
|
|
- Bug: {
|
132
|
|
- 'default': bug,
|
133
|
|
- 'callbacks': [bug_direction]
|
134
|
|
- },
|
135
|
|
- Egg: {
|
136
|
|
- 'default': egg
|
137
|
|
- },
|
138
|
|
- Rock: {
|
139
|
|
- 'default': rock
|
140
|
|
- },
|
141
|
|
- Food: {
|
142
|
|
- 'default': food
|
|
163
|
+ 'object': {
|
|
164
|
+ 'ant': Ant,
|
|
165
|
+ 'egg': Egg,
|
|
166
|
+ 'rock': Rock,
|
|
167
|
+ 'food': Food
|
|
168
|
+ }
|
|
169
|
+}
|
|
170
|
+image_rotate = PygameImageRotate()
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+def dead_ant_callback_container(map_connector, production_class):
|
|
174
|
+ tile_set_id = map_connector.get_dynamic_classes().get_production_class_collection_id(production_class)
|
|
175
|
+ pil_image = map_connector.extract_image_with_class(tile_set_id, 'dead_ant')
|
|
176
|
+ image_bytes = pil_image.tobytes()
|
|
177
|
+ pygame_surface = pygame.image.fromstring(image_bytes, pil_image.size, pil_image.mode)
|
|
178
|
+ pygame_image = PygameImage(pygame_surface)
|
|
179
|
+
|
|
180
|
+ def dead_ant_callback(obj, context):
|
|
181
|
+ # TODO: obj dans le col ALIVE truc comme ça
|
|
182
|
+ if obj.get_life_points() <= 0:
|
|
183
|
+ return pygame_image
|
|
184
|
+ # TODO: raise, ou dans objectVisual.get_visual tests si bool plutot que is
|
|
185
|
+ return False
|
|
186
|
+
|
|
187
|
+ return dead_ant_callback
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+def ant_direction_modifier(obj, context, visual):
|
|
191
|
+ try:
|
|
192
|
+ previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, obj.get_id())
|
|
193
|
+ except KeyError:
|
|
194
|
+ previous_direction = 14
|
|
195
|
+ return image_rotate.get_for_direction(visual, previous_direction)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+def get_standard_extract_from_map(map_file_path, map_config):
|
|
199
|
+ map_connector = TileMapConnector.from_file(map_file_path, dict(map_config))
|
|
200
|
+ visualisation = PygameVisualisation.get_default_visualisation()
|
|
201
|
+
|
|
202
|
+ simulations = map_connector.create_simulations()
|
|
203
|
+ visualizer = PygameVisualisation(visualisation)
|
|
204
|
+
|
|
205
|
+ objects_images = map_connector.extract_objects_images()
|
|
206
|
+ visualizer.update_objects_images(objects_images)
|
|
207
|
+
|
|
208
|
+ map_connector.add_object_callback_to_visualisation(visualizer, [Ant], dead_ant_callback_container)
|
|
209
|
+ ant_production_classes = map_connector.get_dynamic_classes().get_production_classes(Ant)
|
|
210
|
+
|
|
211
|
+ for ant_production_class in ant_production_classes:
|
|
212
|
+ visualizer.add_modifier(ant_production_class, ant_direction_modifier)
|
|
213
|
+
|
|
214
|
+ visualisation.update({
|
|
215
|
+ 'callbacks': {
|
|
216
|
+ 'position': for_position
|
143
|
217
|
},
|
144
|
|
- Hole: {
|
145
|
|
- 'default': hole
|
|
218
|
+ 'surfaces': {
|
|
219
|
+ SURFACE_PHEROMONE_EXPLORATION: {
|
|
220
|
+ 'default': phee,
|
|
221
|
+ 'callbacks': []
|
|
222
|
+ },
|
|
223
|
+ SURFACE_PHEROMONE_HOME: {
|
|
224
|
+ 'default': pheh,
|
|
225
|
+ 'callbacks': []
|
|
226
|
+ },
|
146
|
227
|
}
|
147
|
|
- }
|
148
|
|
-}
|
|
228
|
+ })
|
|
229
|
+
|
|
230
|
+ return simulations, visualisation
|