Browse Source

use STATE shorcuts

Bastien Sevajol 9 years ago
parent
commit
7ce497d88b

+ 1 - 3
intelligine/synergy/event/CycleEvent.py View File

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from intelligine.cst import CANT_CARRY_STILL, TRANSPORTER, ALIVE
2
 from intelligine.cst import CANT_CARRY_STILL, TRANSPORTER, ALIVE
3
-from intelligine.synergy.Simulation import Simulation
4
 
3
 
5
 
4
 
6
 class CycleEvent(Event):
5
 class CycleEvent(Event):
7
 
6
 
8
     def concern(self, object_id, context):
7
     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)
8
+        return context.metas.states.have(object_id, [TRANSPORTER, ALIVE])
11
 
9
 
12
     def _object_match(self, object_id, context, parameters):
10
     def _object_match(self, object_id, context, parameters):
13
         return True
11
         return True

+ 2 - 3
intelligine/synergy/event/attack/NearAttackableAction.py View File

1
 from synergine.synergy.event.Action import Action
1
 from synergine.synergy.event.Action import Action
2
 from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
2
 from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
3
 from random import randint
3
 from random import randint
4
-from intelligine.synergy.Simulation import Simulation
5
 from intelligine.cst import ALIVE, ATTACKABLE
4
 from intelligine.cst import ALIVE, ATTACKABLE
6
 
5
 
7
 
6
 
22
             obj_attackable.hurted(randint(0, 2))
21
             obj_attackable.hurted(randint(0, 2))
23
             if obj_attackable.get_life_points() <= 0:
22
             if obj_attackable.get_life_points() <= 0:
24
                 try:
23
                 try:
25
-                    context.metas.list.remove(Simulation.STATE, obj_id_attackable, ALIVE)
26
-                    context.metas.list.remove(Simulation.STATE, obj_id_attackable, ATTACKABLE)
24
+                    # TODO: Doit etre dans l'objet, lui sais cz qu'il perd comme etat
25
+                    context.metas.states.remove_list(obj_id_attackable, [ALIVE, ATTACKABLE])
27
                 except ValueError:  # Ant maybed killed by other ant at same turn
26
                 except ValueError:  # Ant maybed killed by other ant at same turn
28
                     pass
27
                     pass

+ 2 - 4
intelligine/synergy/event/attack/NearAttackableEvent.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 synergine.synergy.Simulation import Simulation
4
 from intelligine.cst import ATTACKER, ATTACKABLE, COLONY, ALIVE
3
 from intelligine.cst import ATTACKER, ATTACKABLE, COLONY, ALIVE
5
 
4
 
6
 
5
 
7
 class NearAttackableEvent(Event):
6
 class NearAttackableEvent(Event):
8
 
7
 
9
     def concern(self, object_id, context):
8
     def concern(self, object_id, context):
10
-        return context.metas.list.have(Simulation.STATE, object_id, ATTACKER) and \
11
-               context.metas.list.have(Simulation.STATE, object_id, ALIVE)
9
+        return context.metas.states.have(object_id, [ATTACKER, ALIVE])
12
 
10
 
13
     def __init__(self, actions):
11
     def __init__(self, actions):
14
         super().__init__(actions)
12
         super().__init__(actions)
18
         # TODO: nettoyer
16
         # TODO: nettoyer
19
         obj_colony_id = context.metas.value.get(COLONY, object_id)
17
         obj_colony_id = context.metas.value.get(COLONY, object_id)
20
         for obj_near_id in parameters['objects_ids_near']:
18
         for obj_near_id in parameters['objects_ids_near']:
21
-            if context.metas.list.have(Simulation.STATE, obj_near_id, ATTACKABLE):
19
+            if context.metas.states.have(obj_near_id, [ATTACKABLE]):
22
                 if obj_colony_id != context.metas.value.get(COLONY, obj_near_id):
20
                 if obj_colony_id != context.metas.value.get(COLONY, obj_near_id):
23
                     if 'objects_ids_attackable' not in parameters:
21
                     if 'objects_ids_attackable' not in parameters:
24
                         parameters['objects_ids_attackable'] = []
22
                         parameters['objects_ids_attackable'] = []

+ 1 - 2
intelligine/synergy/event/move/MoveAction.py View File

3
 from random import randint, choice
3
 from random import randint, choice
4
 from xyzworld.cst import POSITION, POSITIONS
4
 from xyzworld.cst import POSITION, POSITIONS
5
 from intelligine.cst import IMPENETRABLE, PREVIOUS_DIRECTION, BLOCKED_SINCE
5
 from intelligine.cst import IMPENETRABLE, PREVIOUS_DIRECTION, BLOCKED_SINCE
6
-from synergine.synergy.Simulation import Simulation
7
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
6
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
8
 
7
 
9
 
8
 
54
     def _direction_point_is_possible(self, context, direction_point):
53
     def _direction_point_is_possible(self, context, direction_point):
55
         objects_ids_on_this_point = context.metas.list.get(POSITIONS, direction_point, allow_empty=True)
54
         objects_ids_on_this_point = context.metas.list.get(POSITIONS, direction_point, allow_empty=True)
56
         for object_id_on_this_point in objects_ids_on_this_point:
55
         for object_id_on_this_point in objects_ids_on_this_point:
57
-          if context.metas.list.have(Simulation.STATE, object_id_on_this_point, IMPENETRABLE):
56
+          if context.metas.states.have(object_id_on_this_point, [IMPENETRABLE]):
58
             return False
57
             return False
59
         return True
58
         return True
60
 
59
 

+ 1 - 3
intelligine/synergy/event/move/MoveEvent.py View File

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from synergine.core.simulation.mechanism.Mechanism import Mechanism
2
 from synergine.core.simulation.mechanism.Mechanism import Mechanism
3
-from intelligine.synergy.Simulation import Simulation
4
 from intelligine.cst import ALIVE, WALKER
3
 from intelligine.cst import ALIVE, WALKER
5
 
4
 
6
 
5
 
7
 class MoveEvent(Event):
6
 class MoveEvent(Event):
8
 
7
 
9
     def concern(self, object_id, context):
8
     def concern(self, object_id, context):
10
-        return context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
11
-               context.metas.list.have(Simulation.STATE, object_id, WALKER)
9
+        return context.metas.states.have(object_id, [ALIVE, WALKER])
12
 
10
 
13
     def __init__(self, actions):
11
     def __init__(self, actions):
14
         super().__init__(actions)
12
         super().__init__(actions)

+ 2 - 5
intelligine/synergy/event/transport/PutableEvent.py View File

1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
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
3
 from intelligine.cst import TRANSPORTER, ALIVE, CARRYING, CANT_PUT_STILL
5
 
4
 
6
 
5
 
7
 class PutableEvent(TakeableEvent):
6
 class PutableEvent(TakeableEvent):
8
 
7
 
9
     def concern(self, object_id, context):
8
     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
+        return context.metas.states.have(object_id, [TRANSPORTER, ALIVE, CARRYING]) \
10
+               and not context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True)

+ 4 - 6
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
4
 from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING, CANT_CARRY_STILL
3
 from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING, CANT_CARRY_STILL
5
 
4
 
6
 
5
 
7
 class TakeableEvent(Event):
6
 class TakeableEvent(Event):
8
 
7
 
9
     def concern(self, object_id, context):
8
     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
-               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)
9
+        return context.metas.states.have(object_id, [TRANSPORTER, ALIVE]) and \
10
+               context.metas.states.dont_have(object_id, [CARRYING]) and not \
11
+               context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True)
14
 
12
 
15
     def __init__(self, actions):
13
     def __init__(self, actions):
16
         super().__init__(actions)
14
         super().__init__(actions)
19
     def _object_match(self, object_id, context, parameters={}):
17
     def _object_match(self, object_id, context, parameters={}):
20
         # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
18
         # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
21
         for obj_near_id in parameters['objects_ids_near']:
19
         for obj_near_id in parameters['objects_ids_near']:
22
-            if context.metas.list.have(Simulation.STATE, obj_near_id, TRANSPORTABLE):
20
+            if context.metas.states.have(obj_near_id, [TRANSPORTABLE]):
23
                 if 'objects_ids_transportable' not in parameters:
21
                 if 'objects_ids_transportable' not in parameters:
24
                     parameters['objects_ids_transportable'] = []
22
                     parameters['objects_ids_transportable'] = []
25
                 parameters['objects_ids_transportable'].append(obj_near_id)
23
                 parameters['objects_ids_transportable'].append(obj_near_id)

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

1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
 from synergine.metas import metas
2
 from synergine.metas import metas
3
 from intelligine.cst import ALIVE, ATTACKABLE, TRANSPORTABLE
3
 from intelligine.cst import ALIVE, ATTACKABLE, TRANSPORTABLE
4
-from synergine.synergy.Simulation import Simulation
5
 
4
 
6
 
5
 
7
 class BaseBug(XyzSynergyObject):
6
 class BaseBug(XyzSynergyObject):
8
 
7
 
9
     def __init__(self):
8
     def __init__(self):
10
         super().__init__()
9
         super().__init__()
11
-        metas.list.add(Simulation.STATE, self.get_id(), ALIVE)
12
-        metas.list.add(Simulation.STATE, self.get_id(), ATTACKABLE)
10
+        metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
13
         self._life_points = 10
11
         self._life_points = 10
14
         self._carried_by = None
12
         self._carried_by = None
15
 
13
 
23
         if obj is not None:
21
         if obj is not None:
24
             assert self._carried_by is None
22
             assert self._carried_by is None
25
             self._carried_by = obj
23
             self._carried_by = obj
26
-            metas.list.remove(Simulation.STATE, self.get_id(), TRANSPORTABLE)
24
+            metas.states.remove(self.get_id(), TRANSPORTABLE)
27
         else:
25
         else:
28
             assert self._carried_by is not None
26
             assert self._carried_by is not None
29
             self._carried_by = None
27
             self._carried_by = None
30
-            metas.list.add(Simulation.STATE, self.get_id(), TRANSPORTABLE)
28
+            metas.states.add(self.get_id(), TRANSPORTABLE)
31
 
29
 
32
     def is_carried(self):
30
     def is_carried(self):
33
         if self._carried_by:
31
         if self._carried_by:

+ 1 - 2
intelligine/synergy/object/Bug.py View File

1
 from intelligine.synergy.object.BaseBug import BaseBug
1
 from intelligine.synergy.object.BaseBug import BaseBug
2
 from synergine.metas import metas
2
 from synergine.metas import metas
3
 from intelligine.cst import WALKER
3
 from intelligine.cst import WALKER
4
-from synergine.synergy.Simulation import Simulation
5
 
4
 
6
 
5
 
7
 class Bug(BaseBug):
6
 class Bug(BaseBug):
8
 
7
 
9
     def __init__(self):
8
     def __init__(self):
10
         super().__init__()
9
         super().__init__()
11
-        metas.list.add(Simulation.STATE, self.get_id(), WALKER)
10
+        metas.states.add(self.get_id(), WALKER)

+ 1 - 2
intelligine/synergy/object/Egg.py View File

1
 from intelligine.synergy.object.BaseBug import BaseBug
1
 from intelligine.synergy.object.BaseBug import BaseBug
2
 from synergine.metas import metas
2
 from synergine.metas import metas
3
 from intelligine.cst import ALIVE, TRANSPORTABLE
3
 from intelligine.cst import ALIVE, TRANSPORTABLE
4
-from synergine.synergy.Simulation import Simulation
5
 
4
 
6
 
5
 
7
 class Egg(BaseBug):
6
 class Egg(BaseBug):
8
 
7
 
9
     def __init__(self):
8
     def __init__(self):
10
         super().__init__()
9
         super().__init__()
11
-        metas.list.add(Simulation.STATE, self.get_id(), TRANSPORTABLE)
10
+        metas.states.add(self.get_id(), TRANSPORTABLE)
12
         self._life_points = 1
11
         self._life_points = 1

+ 1 - 2
intelligine/synergy/object/Rock.py View File

1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
 from synergine.metas import metas
2
 from synergine.metas import metas
3
 from intelligine.cst import IMPENETRABLE
3
 from intelligine.cst import IMPENETRABLE
4
-from synergine.synergy.Simulation import Simulation
5
 
4
 
6
 
5
 
7
 class Rock(XyzSynergyObject):
6
 class Rock(XyzSynergyObject):
8
 
7
 
9
     def __init__(self):
8
     def __init__(self):
10
         super().__init__()
9
         super().__init__()
11
-        metas.list.add(Simulation.STATE, self.get_id(), IMPENETRABLE)
10
+        metas.states.add(self.get_id(), IMPENETRABLE)

+ 3 - 5
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 synergine.metas import metas
2
 from synergine.metas import metas
3
-from intelligine.synergy.Simulation import Simulation
4
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER
3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER
5
 
4
 
6
 
5
 
8
 
7
 
9
     def __init__(self):
8
     def __init__(self):
10
         super().__init__()
9
         super().__init__()
11
-        metas.list.add(Simulation.STATE, self.get_id(), TRANSPORTER)
12
-        metas.list.add(Simulation.STATE, self.get_id(), ATTACKER)
10
+        metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
13
         self._carried = []
11
         self._carried = []
14
 
12
 
15
     def put_carry(self, obj):
13
     def put_carry(self, obj):
16
         self._carried.remove(obj)
14
         self._carried.remove(obj)
17
         obj.set_position(self.get_position())
15
         obj.set_position(self.get_position())
18
-        metas.list.remove(Simulation.STATE, self.get_id(), CARRYING)
16
+        metas.states.remove(self.get_id(), CARRYING)
19
 
17
 
20
     def get_carried(self):
18
     def get_carried(self):
21
         # TODO: cas ou plusieurs ?
19
         # TODO: cas ou plusieurs ?
23
 
21
 
24
     def carry(self, obj):
22
     def carry(self, obj):
25
         self._carried.append(obj)
23
         self._carried.append(obj)
26
-        metas.list.add(Simulation.STATE, self.get_id(), CARRYING)
24
+        metas.states.add(self.get_id(), CARRYING)
27
 
25
 
28
     def is_carrying(self):
26
     def is_carrying(self):
29
         if len(self._carried):
27
         if len(self._carried):