Browse Source

WORKING: pheromones appose infos

Bastien Sevajol 9 years ago
parent
commit
1bf361d698

+ 5 - 1
intelligine/cst.py View File

14
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
14
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
15
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
16
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
16
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
17
+PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
18
+PHEROMON_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
19
+PHEROMON_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
20
+PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
17
 
21
 
18
 COL_ALIVE = IncrementedNamedInt.get('intelligine.col.alive')
22
 COL_ALIVE = IncrementedNamedInt.get('intelligine.col.alive')
19
 COL_WALKER = IncrementedNamedInt.get('intelligine.col.walker')
23
 COL_WALKER = IncrementedNamedInt.get('intelligine.col.walker')
20
 COL_FIGHTER = IncrementedNamedInt.get('intelligine.col.walker')
24
 COL_FIGHTER = IncrementedNamedInt.get('intelligine.col.walker')
21
 COL_TRANSPORTER = IncrementedNamedInt.get('intelligine.col.transporter')
25
 COL_TRANSPORTER = IncrementedNamedInt.get('intelligine.col.transporter')
22
 COL_TRANSPORTER_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_carrying')
26
 COL_TRANSPORTER_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_carrying')
23
-COL_TRANSPORTER_NOT_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_not_carrying')
27
+COL_TRANSPORTER_NOT_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_not_carrying')

+ 29 - 1
intelligine/display/Pygame.py View File

1
 from xyzworld.display.Pygame import Pygame as XyzPygame
1
 from xyzworld.display.Pygame import Pygame as XyzPygame
2
+from intelligine.cst import PHEROMON_INFOS, PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
3
+from intelligine.synergy.object.ant.Pheromon import Pheromon
2
 
4
 
3
 
5
 
4
 class Pygame(XyzPygame):
6
 class Pygame(XyzPygame):
5
-  pass
7
+
8
+    def receive(self, synergy_object_manager, context):
9
+        super().receive(synergy_object_manager, context)
10
+        self._display_pheromones(context.metas.list.get(PHEROMON_POSITIONS, PHEROMON_POSITIONS, allow_empty=True), context)
11
+
12
+    def _display_pheromones(self, pheromones_positions, context):
13
+        for point in pheromones_positions:
14
+            ######
15
+            # refact
16
+            point_pheromones_infos = context.metas.value.get(PHEROMON_INFOS, point, allow_empty=True,
17
+                                                             empty_value={})
18
+            # TODO: Tout ca dans un get_pheromone_info(PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, direction)
19
+            #point_pheromones_infos={}
20
+            if PHEROMON_DIRECTION not in point_pheromones_infos:
21
+                point_pheromones_infos[PHEROMON_DIRECTION] = {}
22
+            direction_pheromone = point_pheromones_infos[PHEROMON_DIRECTION]
23
+            if PHEROMON_DIR_EXPLO not in direction_pheromone:
24
+                 direction_pheromone[PHEROMON_DIR_EXPLO] = {}
25
+            exploration_info = direction_pheromone[PHEROMON_DIR_EXPLO]
26
+            ########
27
+
28
+            for direction in exploration_info:
29
+                intensity = exploration_info[direction]
30
+                # TODO: ne pas avoir a creer d'objet, voir comment dans display
31
+                pheromon = Pheromon(object(), context)
32
+                pheromon.set_direction(direction)
33
+                self._draw_objects_with_decal(point, [pheromon])

+ 14 - 1
intelligine/display/pygame/visualisation.py View File

29
 eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c5.png')
29
 eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c5.png')
30
 eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
30
 eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
31
 
31
 
32
+
33
+from intelligine.synergy.object.ant.Pheromon import Pheromon
34
+phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
35
+dir_phee = directions_ant = DirectionnedImage(phee)
36
+
37
+
32
 directions_ant = DirectionnedImage(ant)
38
 directions_ant = DirectionnedImage(ant)
33
 directions_red_ant = DirectionnedImage(red_ant)
39
 directions_red_ant = DirectionnedImage(red_ant)
34
 directions_blue_ant = DirectionnedImage(blue_ant)
40
 directions_blue_ant = DirectionnedImage(blue_ant)
35
 directions_green_ant = DirectionnedImage(green_ant)
41
 directions_green_ant = DirectionnedImage(green_ant)
36
 
42
 
43
+def phee_direction(phee, context):
44
+    return dir_phee.get_for_direction(phee.get_direction())
45
+
37
 def bug_direction(bug, context):
46
 def bug_direction(bug, context):
38
     if bug.get_life_points() <= 0:
47
     if bug.get_life_points() <= 0:
39
         return dead_ant
48
         return dead_ant
118
         },
127
         },
119
         Rock: {
128
         Rock: {
120
             'default': rock
129
             'default': rock
121
-        }
130
+        },
131
+        Pheromon: {
132
+            'default': phee,
133
+            'callbacks': [phee_direction]
134
+        },
122
     }
135
     }
123
 }
136
 }

+ 3 - 1
intelligine/synergy/Colony.py View File

4
 from intelligine.synergy.event.transport.TakeableAction import TakeableAction
4
 from intelligine.synergy.event.transport.TakeableAction import TakeableAction
5
 from intelligine.synergy.event.transport.PutableAction import PutableAction
5
 from intelligine.synergy.event.transport.PutableAction import PutableAction
6
 from intelligine.synergy.event.CycleAction import CycleAction
6
 from intelligine.synergy.event.CycleAction import CycleAction
7
+from intelligine.synergy.event.pheromone.ApposeDirection import ApposeDirection
7
 
8
 
8
 
9
 
9
 class Colony(SynergyCollection):
10
 class Colony(SynergyCollection):
11
 
12
 
12
     def __init__(self, configuration):
13
     def __init__(self, configuration):
13
         super().__init__(configuration)
14
         super().__init__(configuration)
14
-        self._actions = [MoveAction, NearAttackableAction, TakeableAction, PutableAction, CycleAction]
15
+        self._actions = [MoveAction, NearAttackableAction, TakeableAction, PutableAction,
16
+                         CycleAction, ApposeDirection]

+ 4 - 1
intelligine/synergy/ColonyConfiguration.py View File

1
 from synergine.synergy.collection.Configuration import Configuration
1
 from synergine.synergy.collection.Configuration import Configuration
2
 from intelligine.synergy.object.ant.Ant import Ant
2
 from intelligine.synergy.object.ant.Ant import Ant
3
 from intelligine.cst import ALIVE, COLONY
3
 from intelligine.cst import ALIVE, COLONY
4
+from xyzworld.cst import POSITION
4
 
5
 
5
 
6
 
6
 class ColonyConfiguration(Configuration):
7
 class ColonyConfiguration(Configuration):
7
 
8
 
8
     _start_position = (0, 20, 20)
9
     _start_position = (0, 20, 20)
9
     _ant_class = Ant
10
     _ant_class = Ant
11
+    _ant_count = 50
10
 
12
 
11
     def get_start_objects(self, collection, context):
13
     def get_start_objects(self, collection, context):
14
+      context.metas.value.set(POSITION, collection.get_id(), self._start_position)
12
 
15
 
13
       ants = []
16
       ants = []
14
-      for i in range(50):
17
+      for i in range(self._ant_count):
15
           ant = self._ant_class(collection, context)
18
           ant = self._ant_class(collection, context)
16
           context.metas.value.set(COLONY, ant.get_id(), collection.get_id())
19
           context.metas.value.set(COLONY, ant.get_id(), collection.get_id())
17
           ant.set_position(self._start_position)
20
           ant.set_position(self._start_position)

+ 40 - 0
intelligine/synergy/event/move/direction.py View File

97
   26: (25, 26, 27, 16, 17, 18),
97
   26: (25, 26, 27, 16, 17, 18),
98
   27: (24, 27, 26, 15, 18, 17),
98
   27: (24, 27, 26, 15, 18, 17),
99
 }
99
 }
100
+
101
+directions_degrees = {
102
+    (0, 22): 11,
103
+    (22, 67): 12,
104
+    (68, 112): 15,
105
+    (112, 158): 18,
106
+    (158, 201): 17,
107
+    (201, 246): 16,
108
+    (246, 291): 13,
109
+    (291, 338): 10,
110
+    (338, 0): 11
111
+}
112
+
113
+def get_direction_for_degrees(degrees):
114
+    if degrees < 0:
115
+        degrees = 360 - degrees - degrees - degrees # TODO: math absolute !!!
116
+    for plage in directions_degrees:
117
+        if degrees >= plage[0] and degrees <= plage[1]:
118
+            return directions_degrees[plage]
119
+    raise IndexError()  # TODO: personnalised exception
120
+
121
+"""
122
+niv 0:   10 11 12
123
+         13 14 15
124
+         16 17 18
125
+"""
126
+
127
+directions_opposites = {
128
+    10: 18,
129
+    11: 17,
130
+    12: 16,
131
+    13: 15,
132
+    15: 13,
133
+    16: 12,
134
+    17: 11,
135
+    18: 10
136
+}
137
+
138
+def get_direction_opposite(direction):
139
+    return directions_opposites[direction]

+ 9 - 1
intelligine/synergy/object/BaseBug.py View File

10
         context.metas.collections.add(self.get_id(), COL_ALIVE)
10
         context.metas.collections.add(self.get_id(), COL_ALIVE)
11
         self._life_points = 10
11
         self._life_points = 10
12
         self._carried_by = None
12
         self._carried_by = None
13
+        self._movements_count = -1
13
 
14
 
14
     def hurted(self, points):
15
     def hurted(self, points):
15
         self._life_points -= points
16
         self._life_points -= points
30
     def is_carried(self):
31
     def is_carried(self):
31
         if self._carried_by:
32
         if self._carried_by:
32
             return True
33
             return True
33
-        return False
34
+        return False
35
+
36
+    def set_position(self, point):
37
+        super().set_position(point)
38
+        self._movements_count += 1
39
+
40
+    def get_movements_count(self):
41
+        return self._movements_count

+ 9 - 0
intelligine/synergy/object/ant/Ant.py View File

12
                                                            COL_TRANSPORTER_NOT_CARRYING,
12
                                                            COL_TRANSPORTER_NOT_CARRYING,
13
                                                            COL_FIGHTER])
13
                                                            COL_FIGHTER])
14
         self._carried = []
14
         self._carried = []
15
+        self._last_pheromones_points = {}
15
 
16
 
16
     def put_carry(self, obj, position=None):
17
     def put_carry(self, obj, position=None):
17
         if position is None:
18
         if position is None:
39
         if self.is_carrying():
40
         if self.is_carrying():
40
             for obj_carried in self._carried:
41
             for obj_carried in self._carried:
41
                 obj_carried.set_position(position)
42
                 obj_carried.set_position(position)
43
+
44
+    def get_last_pheromone_point(self, pheromone_name):
45
+        if pheromone_name in self._last_pheromones_points:
46
+            return self._last_pheromones_points[pheromone_name]
47
+        return self._start_position
48
+
49
+    def set_last_pheromone_point(self, pheromone_name, position):
50
+        self._last_pheromones_points[pheromone_name] = position