Browse Source

Pheromones: explo AND home

Bastien Sevajol 9 years ago
parent
commit
acb58c4573

+ 18 - 3
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
 import pygame
2
 import pygame
3
-from intelligine.cst import PHEROMON_INFOS, PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_POSITIONS
4
-from intelligine.synergy.object.ant.Pheromon import Pheromon
3
+from intelligine.cst import PHEROMON_INFOS, PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
4
+from intelligine.synergy.object.ant.PheromonExploration import PheromonExploration
5
+from intelligine.synergy.object.ant.PheromonHome import PheromonHome
5
 
6
 
6
 
7
 
7
 class Pygame(XyzPygame):
8
 class Pygame(XyzPygame):
27
             for direction in exploration_info:
28
             for direction in exploration_info:
28
                 intensity = exploration_info[direction]
29
                 intensity = exploration_info[direction]
29
                 # TODO: ne pas avoir a creer d'objet, voir comment dans display
30
                 # TODO: ne pas avoir a creer d'objet, voir comment dans display
30
-                pheromon = Pheromon(object(), context)
31
+                pheromon = PheromonHome(object(), context)
32
+                pheromon.set_direction(direction)
33
+                self._draw_objects_with_decal(point, [pheromon])
34
+
35
+
36
+            exploration_info = context.pheromones().get_info(point,
37
+                                                             [PHEROMON_DIRECTION,
38
+                                                              PHEROMON_DIR_EXPLO],
39
+                                                             allow_empty=True,
40
+                                                             empty_value={})
41
+
42
+            for direction in exploration_info:
43
+                intensity = exploration_info[direction]
44
+                # TODO: ne pas avoir a creer d'objet, voir comment dans display
45
+                pheromon = PheromonExploration(object(), context)
31
                 pheromon.set_direction(direction)
46
                 pheromon.set_direction(direction)
32
                 self._draw_objects_with_decal(point, [pheromon])
47
                 self._draw_objects_with_decal(point, [pheromon])
33
 
48
 

BIN
intelligine/display/pygame/image/pheb.png View File


BIN
intelligine/display/pygame/image/phee.png View File


BIN
intelligine/display/pygame/image/pheh.png View File


+ 13 - 3
intelligine/display/pygame/visualisation.py View File

32
 eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
32
 eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
33
 
33
 
34
 
34
 
35
-from intelligine.synergy.object.ant.Pheromon import Pheromon
35
+from intelligine.synergy.object.ant.PheromonExploration import PheromonExploration
36
+from intelligine.synergy.object.ant.PheromonHome import PheromonHome
36
 phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
37
 phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
37
-dir_phee = directions_ant = DirectionnedImage(phee)
38
+pheh = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/pheh.png')
39
+dir_phee = DirectionnedImage(phee)
40
+dir_pheh = DirectionnedImage(pheh)
38
 
41
 
39
 
42
 
40
 directions_ant = DirectionnedImage(ant)
43
 directions_ant = DirectionnedImage(ant)
45
 def phee_direction(phee, context):
48
 def phee_direction(phee, context):
46
     return dir_phee.get_for_direction(phee.get_direction())
49
     return dir_phee.get_for_direction(phee.get_direction())
47
 
50
 
51
+def pheh_direction(pheh, context):
52
+    return dir_pheh.get_for_direction(pheh.get_direction())
53
+
48
 def bug_direction(bug, context):
54
 def bug_direction(bug, context):
49
     if bug.get_life_points() <= 0:
55
     if bug.get_life_points() <= 0:
50
         return dead_ant
56
         return dead_ant
133
         Food: {
139
         Food: {
134
             'default': food
140
             'default': food
135
         },
141
         },
136
-        Pheromon: {
142
+        PheromonExploration: {
137
             'default': phee,
143
             'default': phee,
138
             'callbacks': [phee_direction]
144
             'callbacks': [phee_direction]
139
         },
145
         },
146
+        PheromonHome: {
147
+            'default': pheh,
148
+            'callbacks': [pheh_direction]
149
+        },
140
     }
150
     }
141
 }
151
 }

+ 4 - 1
intelligine/synergy/event/pheromone/ApposeDirection.py View File

1
 from synergine.synergy.event.Action import Action
1
 from synergine.synergy.event.Action import Action
2
 from intelligine.synergy.event.pheromone.PheromoneEvent import PheromoneEvent
2
 from intelligine.synergy.event.pheromone.PheromoneEvent import PheromoneEvent
3
 from xyzworld.cst import POSITION
3
 from xyzworld.cst import POSITION
4
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_POSITIONS, MOVE_MODE_EXPLO
4
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_POSITIONS, MOVE_MODE_EXPLO, \
5
+    MOVE_MODE_GOHOME, PHEROMON_DIR_EXPLO
5
 from xyzworld.geometry import get_degree_from_north
6
 from xyzworld.geometry import get_degree_from_north
6
 from intelligine.synergy.event.move.direction import get_direction_for_degrees, get_direction_opposite
7
 from intelligine.synergy.event.move.direction import get_direction_for_degrees, get_direction_opposite
7
 from intelligine.core.exceptions import SamePosition
8
 from intelligine.core.exceptions import SamePosition
59
     def _get_pheromone_direction_type(self, obj):
60
     def _get_pheromone_direction_type(self, obj):
60
         if obj.get_movement_mode() == MOVE_MODE_EXPLO:
61
         if obj.get_movement_mode() == MOVE_MODE_EXPLO:
61
             return PHEROMON_DIR_HOME
62
             return PHEROMON_DIR_HOME
63
+        if obj.get_movement_mode() == MOVE_MODE_GOHOME:
64
+            return PHEROMON_DIR_EXPLO
62
         raise NotImplementedError()
65
         raise NotImplementedError()

+ 7 - 1
intelligine/synergy/object/ant/Ant.py View File

1
 from intelligine.synergy.object.Bug import Bug
1
 from intelligine.synergy.object.Bug import Bug
2
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
2
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
3
                             COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
3
                             COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
-                            COL_FIGHTER, MOVE_MODE_EXPLO
4
+                            COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, \
5
+                            PHEROMON_DIR_EXPLO
6
+from intelligine.synergy.object.Food import Food
5
 
7
 
6
 
8
 
7
 class Ant(Bug):
9
 class Ant(Bug):
30
     def carry(self, obj):
32
     def carry(self, obj):
31
         self._carried.append(obj)
33
         self._carried.append(obj)
32
         self._context.metas.states.add(self.get_id(), CARRYING)
34
         self._context.metas.states.add(self.get_id(), CARRYING)
35
+        # TODO: pour le moment hardcode
36
+        if isinstance(obj, Food):
37
+            self.set_movement_mode(MOVE_MODE_GOHOME)
38
+            self.set_last_pheromone_point(PHEROMON_DIR_EXPLO, obj.get_position())
33
 
39
 
34
     def is_carrying(self):
40
     def is_carrying(self):
35
         if len(self._carried):
41
         if len(self._carried):

+ 5 - 0
intelligine/synergy/object/ant/PheromonExploration.py View File

1
+from intelligine.synergy.object.ant.Pheromon import Pheromon
2
+
3
+
4
+class PheromonExploration(Pheromon):
5
+    pass

+ 5 - 0
intelligine/synergy/object/ant/PheromonHome.py View File

1
+from intelligine.synergy.object.ant.Pheromon import Pheromon
2
+
3
+
4
+class PheromonHome(Pheromon):
5
+    pass