Browse Source

Transport of eggs (non refactorised)

Bastien Sevajol 9 years ago
parent
commit
d506cbeafc

+ 3 - 1
config.py View File

8
  TODO:
8
  TODO:
9
  * AttackAction :: comment choisir entre les actions ?
9
  * AttackAction :: comment choisir entre les actions ?
10
  * TakeAction, PutAction, Object Egg
10
  * TakeAction, PutAction, Object Egg
11
+ * --> frameworkiser les usage de states, metas etc ?
11
  * Plusieurs objets au mm endroit; Cinq oeuf => dessein de cinq oeuf; etc (image dynamique (param max_supperposer ?)
12
  * Plusieurs objets au mm endroit; Cinq oeuf => dessein de cinq oeuf; etc (image dynamique (param max_supperposer ?)
12
  * 3d
13
  * 3d
14
+ * Optimisation display pygame: ne pas tout reafficher; opt google
13
 """
15
 """
14
 
16
 
15
 config = {
17
 config = {
20
         }
22
         }
21
     },
23
     },
22
     'engine': {
24
     'engine': {
23
-        'fpsmax': 225,
25
+        'fpsmax': 25,
24
         'debug': {
26
         'debug': {
25
             'mainprocess': True,
27
             'mainprocess': True,
26
             'cycles': -1
28
             'cycles': -1

+ 3 - 1
intelligine/cst.py View File

10
 COLONY = IncrementedNamedInt.get('intelligine.colony')
10
 COLONY = IncrementedNamedInt.get('intelligine.colony')
11
 TRANSPORTABLE = IncrementedNamedInt.get('intelligine.transportable')
11
 TRANSPORTABLE = IncrementedNamedInt.get('intelligine.transportable')
12
 TRANSPORTER = IncrementedNamedInt.get('intelligine.transporter')
12
 TRANSPORTER = IncrementedNamedInt.get('intelligine.transporter')
13
-CARRYING = IncrementedNamedInt.get('intelligine.carrying')
13
+CARRYING = IncrementedNamedInt.get('intelligine.carrying')
14
+CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
15
+CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')

+ 1 - 1
intelligine/sandbox/colored/RedColonyConfiguration.py View File

15
 
15
 
16
         for x in range(50):
16
         for x in range(50):
17
           for y in range(1, 50):
17
           for y in range(1, 50):
18
-            if x % 2 == 0 and y % 2 == 0:
18
+            if x % 3 == 0 and y % 3 == 0:
19
               egg = Egg()
19
               egg = Egg()
20
               egg.set_position((0, 1+x, 50+y))
20
               egg.set_position((0, 1+x, 50+y))
21
               # TODO: Ce COLONY doit devenir un truc automatise au niveau de la collection (qd get_object)
21
               # TODO: Ce COLONY doit devenir un truc automatise au niveau de la collection (qd get_object)

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

2
 from intelligine.synergy.event.move.MoveAction import MoveAction
2
 from intelligine.synergy.event.move.MoveAction import MoveAction
3
 from intelligine.synergy.event.attack.NearAttackableAction import NearAttackableAction
3
 from intelligine.synergy.event.attack.NearAttackableAction import NearAttackableAction
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
6
+from intelligine.synergy.event.CycleAction import CycleAction
5
 
7
 
6
 
8
 
7
 class Colony(SynergyCollection):
9
 class Colony(SynergyCollection):
9
 
11
 
10
     def __init__(self, configuration):
12
     def __init__(self, configuration):
11
         super().__init__(configuration)
13
         super().__init__(configuration)
12
-        self._actions = [MoveAction, NearAttackableAction, TakeableAction]
14
+        self._actions = [MoveAction, NearAttackableAction, TakeableAction, PutableAction, CycleAction]

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

12
     def get_start_objects(self, collection):
12
     def get_start_objects(self, collection):
13
 
13
 
14
       ants = []
14
       ants = []
15
-      for i in range(100):
15
+      for i in range(20):
16
           ant = self._ant_class()
16
           ant = self._ant_class()
17
           metas.value.set(COLONY, ant.get_id(), collection.get_id())
17
           metas.value.set(COLONY, ant.get_id(), collection.get_id())
18
           ant.set_position(self._start_position)
18
           ant.set_position(self._start_position)

+ 18 - 0
intelligine/synergy/event/CycleAction.py View File

1
+from synergine.synergy.event.Action import Action
2
+from intelligine.synergy.event.CycleEvent import CycleEvent
3
+from intelligine.cst import CANT_CARRY_STILL, CANT_PUT_STILL
4
+
5
+
6
+class CycleAction(Action):
7
+
8
+    _listen = CycleEvent
9
+
10
+    def run(self, obj, collection, context, synergy_manager):
11
+      # TODO: refact ...
12
+      cant_carry_still = context.metas.value.get(CANT_CARRY_STILL, obj.get_id(), allow_empty=True, empty_value=0)
13
+      if cant_carry_still > 0:
14
+        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), cant_carry_still-1)
15
+
16
+      cant_put_still = context.metas.value.get(CANT_PUT_STILL, obj.get_id(), allow_empty=True, empty_value=0)
17
+      if cant_put_still > 0:
18
+        context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still-1)

+ 13 - 0
intelligine/synergy/event/CycleEvent.py View File

1
+from synergine.synergy.event.Event import Event
2
+from intelligine.cst import CANT_CARRY_STILL, TRANSPORTER, ALIVE
3
+from intelligine.synergy.Simulation import Simulation
4
+
5
+
6
+class CycleEvent(Event):
7
+
8
+    def concern(self, object_id, context):
9
+        return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
10
+               context.metas.list.have(Simulation.STATE, object_id, ALIVE)
11
+
12
+    def _object_match(self, object_id, context, parameters):
13
+        return True

+ 29 - 0
intelligine/synergy/event/transport/PutableAction.py View File

1
+from synergine.synergy.event.Action import Action
2
+from intelligine.synergy.event.transport.PutableEvent import PutableEvent
3
+from intelligine.cst import CANT_CARRY_STILL
4
+
5
+
6
+class PutableAction(Action):
7
+
8
+    _listen = PutableEvent
9
+
10
+    def __init__(self, object_id, parameters):
11
+        super().__init__(object_id, parameters)
12
+
13
+    def prepare(self, context):
14
+        pass
15
+
16
+    def run(self, obj, collection, context, synergy_manager):
17
+        # TODO: TEST
18
+        # TODO: Enlever le state de transportable a ce qui est transporte
19
+        # ?! Comment gerer lorsque deux obj vont vouloir transporter le meme objet ? process !
20
+        obj_id_transportable = self._parameters['objects_ids_transportable'][0]
21
+        obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
22
+        # TODO: Doit etre du meme type que ce qui est transporte !
23
+        obj_transported = obj.get_carried()
24
+        obj_transported.set_carried_by(None)
25
+        obj.put_carry(obj_transported)
26
+        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
27
+        # TODO: Il faut interdire cette action pendant un temps pour eviter que le fourmis deplace
28
+        # les memes objets direct apres
29
+        # Utiliser les metas pour ca ?

+ 13 - 0
intelligine/synergy/event/transport/PutableEvent.py View File

1
+from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
+from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
+from intelligine.synergy.Simulation import Simulation
4
+from intelligine.cst import TRANSPORTER, ALIVE, CARRYING, CANT_PUT_STILL
5
+
6
+
7
+class PutableEvent(TakeableEvent):
8
+
9
+    def concern(self, object_id, context):
10
+        return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
11
+               context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
12
+               context.metas.list.have(Simulation.STATE, object_id, CARRYING) and \
13
+               not context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True)

+ 9 - 7
intelligine/synergy/event/transport/TakeableAction.py View File

1
 from synergine.synergy.event.Action import Action
1
 from synergine.synergy.event.Action import Action
2
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
3
-from random import randint
3
+from intelligine.cst import CANT_PUT_STILL
4
 
4
 
5
 
5
 
6
 class TakeableAction(Action):
6
 class TakeableAction(Action):
19
         # ?! Comment gerer lorsque deux obj vont vouloir transporter le meme objet ? process !
19
         # ?! Comment gerer lorsque deux obj vont vouloir transporter le meme objet ? process !
20
         obj_id_transportable = self._parameters['objects_ids_transportable'][0]
20
         obj_id_transportable = self._parameters['objects_ids_transportable'][0]
21
         obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
21
         obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
22
-        try:
23
-            obj_transportable.set_carried_by(obj)
24
-            obj.carry(obj_transportable)
25
-        except ValueError: # Une NotCarriableError serais pus approprie
26
-            # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.
27
-            pass
22
+        if not obj_transportable.is_carried():
23
+            try:
24
+                obj_transportable.set_carried_by(obj)
25
+                obj.carry(obj_transportable)
26
+                context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
27
+            except ValueError: # Une NotCarriableError serais pus approprie
28
+                # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.
29
+                pass

+ 3 - 2
intelligine/synergy/event/transport/TakeableEvent.py View File

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from intelligine.synergy.Simulation import Simulation
3
 from intelligine.synergy.Simulation import Simulation
4
-from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING
4
+from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING, CANT_CARRY_STILL
5
 
5
 
6
 
6
 
7
 class TakeableEvent(Event):
7
 class TakeableEvent(Event):
9
     def concern(self, object_id, context):
9
     def concern(self, object_id, context):
10
         return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
10
         return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
11
                context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
11
                context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
12
-               not context.metas.list.have(Simulation.STATE, object_id, CARRYING)
12
+               not context.metas.list.have(Simulation.STATE, object_id, CARRYING) and \
13
+               not context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True)
13
 
14
 
14
     def __init__(self, actions):
15
     def __init__(self, actions):
15
         super().__init__(actions)
16
         super().__init__(actions)

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

11
         metas.list.add(Simulation.STATE, self.get_id(), ALIVE)
11
         metas.list.add(Simulation.STATE, self.get_id(), ALIVE)
12
         metas.list.add(Simulation.STATE, self.get_id(), ATTACKABLE)
12
         metas.list.add(Simulation.STATE, self.get_id(), ATTACKABLE)
13
         self._life_points = 10
13
         self._life_points = 10
14
-        self._carried_by = []
14
+        self._carried_by = None
15
 
15
 
16
     def hurted(self, points):
16
     def hurted(self, points):
17
         self._life_points -= points
17
         self._life_points -= points
20
         return self._life_points
20
         return self._life_points
21
 
21
 
22
     def set_carried_by(self, obj):
22
     def set_carried_by(self, obj):
23
-        self._carried_by.append(obj)
24
-        metas.list.remove(Simulation.STATE, self.get_id(), TRANSPORTABLE)
23
+        if obj is not None:
24
+            assert self._carried_by is None
25
+            self._carried_by = obj
26
+            metas.list.remove(Simulation.STATE, self.get_id(), TRANSPORTABLE)
27
+        else:
28
+            assert self._carried_by is not None
29
+            self._carried_by = None
30
+            metas.list.add(Simulation.STATE, self.get_id(), TRANSPORTABLE)
25
 
31
 
26
     def is_carried(self):
32
     def is_carried(self):
27
         if self._carried_by:
33
         if self._carried_by:

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

12
         metas.list.add(Simulation.STATE, self.get_id(), ATTACKER)
12
         metas.list.add(Simulation.STATE, self.get_id(), ATTACKER)
13
         self._carried = []
13
         self._carried = []
14
 
14
 
15
+    def put_carry(self, obj):
16
+        self._carried.remove(obj)
17
+        obj.set_position(self.get_position())
18
+        metas.list.remove(Simulation.STATE, self.get_id(), CARRYING)
19
+
20
+    def get_carried(self):
21
+        # TODO: cas ou plusieurs ?
22
+        return self._carried[0]
23
+
15
     def carry(self, obj):
24
     def carry(self, obj):
16
         self._carried.append(obj)
25
         self._carried.append(obj)
17
         metas.list.add(Simulation.STATE, self.get_id(), CARRYING)
26
         metas.list.add(Simulation.STATE, self.get_id(), CARRYING)