Browse Source

Pheromones: explo AND home

Bastien Sevajol 9 years ago
parent
commit
acb58c4573

+ 18 - 3
intelligine/display/Pygame.py View File

@@ -1,7 +1,8 @@
1 1
 from xyzworld.display.Pygame import Pygame as XyzPygame
2 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 8
 class Pygame(XyzPygame):
@@ -27,7 +28,21 @@ class Pygame(XyzPygame):
27 28
             for direction in exploration_info:
28 29
                 intensity = exploration_info[direction]
29 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 46
                 pheromon.set_direction(direction)
32 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,9 +32,12 @@ eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/eg
32 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 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 43
 directions_ant = DirectionnedImage(ant)
@@ -45,6 +48,9 @@ directions_green_ant = DirectionnedImage(green_ant)
45 48
 def phee_direction(phee, context):
46 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 54
 def bug_direction(bug, context):
49 55
     if bug.get_life_points() <= 0:
50 56
         return dead_ant
@@ -133,9 +139,13 @@ visualisation = {
133 139
         Food: {
134 140
             'default': food
135 141
         },
136
-        Pheromon: {
142
+        PheromonExploration: {
137 143
             'default': phee,
138 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,7 +1,8 @@
1 1
 from synergine.synergy.event.Action import Action
2 2
 from intelligine.synergy.event.pheromone.PheromoneEvent import PheromoneEvent
3 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 6
 from xyzworld.geometry import get_degree_from_north
6 7
 from intelligine.synergy.event.move.direction import get_direction_for_degrees, get_direction_opposite
7 8
 from intelligine.core.exceptions import SamePosition
@@ -59,4 +60,6 @@ class ApposeDirection(Action):
59 60
     def _get_pheromone_direction_type(self, obj):
60 61
         if obj.get_movement_mode() == MOVE_MODE_EXPLO:
61 62
             return PHEROMON_DIR_HOME
63
+        if obj.get_movement_mode() == MOVE_MODE_GOHOME:
64
+            return PHEROMON_DIR_EXPLO
62 65
         raise NotImplementedError()

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

@@ -1,7 +1,9 @@
1 1
 from intelligine.synergy.object.Bug import Bug
2 2
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
3 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 9
 class Ant(Bug):
@@ -30,6 +32,10 @@ class Ant(Bug):
30 32
     def carry(self, obj):
31 33
         self._carried.append(obj)
32 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 40
     def is_carrying(self):
35 41
         if len(self._carried):

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

@@ -0,0 +1,5 @@
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

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