Browse Source

Initial project files

Bastien Sevajol 9 years ago
commit
c2a506835b

+ 2 - 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+.idea
2
+__pycache__

+ 45 - 0
config.py View File

@@ -0,0 +1,45 @@
1
+from xyzworld.Context import Context as XyzContext
2
+from socialintengine.synergy.Simulation import Simulation
3
+from socialintengine.synergy.Colony import Colony
4
+from socialintengine.synergy.ColonyConfiguration import ColonyConfiguration
5
+from socialintengine.synergy.Rocks import Rocks
6
+from socialintengine.synergy.RocksConfiguration import RocksConfiguration
7
+from socialintengine.display.Pygame import Pygame
8
+from socialintengine.display.pygame.visualisation import visualisation as pygame_visualisation
9
+
10
+
11
+config = {
12
+    'app': {
13
+        'name': 'StigEngine',
14
+        'classes': {
15
+          'Context': XyzContext
16
+        }
17
+    },
18
+    'engine': {
19
+        'fpsmax': 5,
20
+        'debug': {
21
+            'mainprocess': False,
22
+            'cycles': -1
23
+        }
24
+    },
25
+    'simulations' : [Simulation([Colony(ColonyConfiguration()), Rocks(RocksConfiguration())])],
26
+    'connections': [Pygame],
27
+    'terminal': {
28
+      'pygame': {
29
+            'visualisation': pygame_visualisation,
30
+            'window_size': (800, 600),
31
+            'app': {
32
+                'name': 'SocialIntengine'
33
+            },
34
+            'display': {
35
+                'grid': {
36
+                    'size': 20
37
+                }
38
+            },
39
+            'font': {
40
+                'name': 'arial',
41
+                'size': 13
42
+            }
43
+        }
44
+    }
45
+}

+ 1 - 0
modules/lifegame View File

@@ -0,0 +1 @@
1
+../../synergine/modules/lifegame

+ 1 - 0
modules/stigengine View File

@@ -0,0 +1 @@
1
+../../stigengine/stigengine

+ 1 - 0
modules/synergine View File

@@ -0,0 +1 @@
1
+../../synergine/synergine

+ 1 - 0
modules/xyworld View File

@@ -0,0 +1 @@
1
+../../synergine/modules/xyworld

+ 1 - 0
modules/xyzworld View File

@@ -0,0 +1 @@
1
+../../synergine/modules/xyzworld

+ 18 - 0
run.py View File

@@ -0,0 +1,18 @@
1
+from os import getcwd
2
+from sys import path as ppath
3
+ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
4
+
5
+
6
+"""
7
+TODO:
8
+ * Objects "dur" (terre); ne pas les avoir dans les objet a calculer sans cesse (INERTE)
9
+ * SlightyTurn
10
+"""
11
+
12
+
13
+
14
+from synergine.core.Core import Core
15
+from config import config
16
+
17
+if __name__ == '__main__':
18
+    Core.start_core(config, modules_path='modules')

+ 4 - 0
socialintengine/cst.py View File

@@ -0,0 +1,4 @@
1
+from synergine.lib.eint import IncrementedNamedInt
2
+
3
+ALIVE = IncrementedNamedInt.get('socialintengine.alive')
4
+IMPENETRABLE = IncrementedNamedInt.get('socialintengine.impenetrable')

+ 5 - 0
socialintengine/display/Pygame.py View File

@@ -0,0 +1,5 @@
1
+from xyzworld.display.Pygame import Pygame as XyzPygame
2
+
3
+
4
+class Pygame(XyzPygame):
5
+  pass

BIN
socialintengine/display/pygame/image/ant.png View File


BIN
socialintengine/display/pygame/image/bug.png View File


BIN
socialintengine/display/pygame/image/rock.png View File


+ 25 - 0
socialintengine/display/pygame/visualisation.py View File

@@ -0,0 +1,25 @@
1
+from xyworld.display.object.pygame.PygameImage import PygameImage
2
+from socialintengine.synergy.object.Bug import Bug
3
+from socialintengine.synergy.object.ant.Ant import Ant
4
+from socialintengine.synergy.object.Rock import Rock
5
+from os import getcwd
6
+
7
+# TODO: Url relative au fichier
8
+ant = PygameImage(getcwd()+'/socialintengine/display/pygame/image/ant.png')
9
+bug = PygameImage(getcwd()+'/socialintengine/display/pygame/image/bug.png')
10
+rock = PygameImage(getcwd()+'/socialintengine/display/pygame/image/rock.png')
11
+
12
+visualisation = {
13
+    'window': {},
14
+    'objects': {
15
+        Ant: {
16
+            'default': ant
17
+        },
18
+        Bug: {
19
+            'default': bug
20
+        },
21
+        Rock: {
22
+            'default': rock
23
+        }
24
+    }
25
+}

+ 10 - 0
socialintengine/synergy/Colony.py View File

@@ -0,0 +1,10 @@
1
+from synergine.synergy.collection.SynergyCollection import SynergyCollection
2
+from socialintengine.synergy.event.move.MoveAction import MoveAction
3
+
4
+
5
+class Colony(SynergyCollection):
6
+
7
+
8
+    def __init__(self, configuration):
9
+        super().__init__(configuration)
10
+        self._actions = [MoveAction]

+ 19 - 0
socialintengine/synergy/ColonyConfiguration.py View File

@@ -0,0 +1,19 @@
1
+from synergine.synergy.collection.Configuration import Configuration
2
+from socialintengine.synergy.object.ant.Ant import Ant
3
+from synergine.metas import metas
4
+from socialintengine.cst import ALIVE
5
+from synergine.synergy.Simulation import Simulation
6
+
7
+
8
+class ColonyConfiguration(Configuration):
9
+
10
+    def get_start_objects(self):
11
+
12
+      ants = []
13
+      for i in range(20):
14
+          ant = Ant()
15
+          ant.add_trace((0, 20, 20))
16
+          metas.list.add(Simulation.STATE, ant.get_id(), ALIVE)
17
+          ants.append(ant)
18
+
19
+      return ants

+ 5 - 0
socialintengine/synergy/Rocks.py View File

@@ -0,0 +1,5 @@
1
+from synergine.synergy.collection.SynergyCollection import SynergyCollection
2
+
3
+
4
+class Rocks(SynergyCollection):
5
+    pass

+ 26 - 0
socialintengine/synergy/RocksConfiguration.py View File

@@ -0,0 +1,26 @@
1
+from synergine.synergy.collection.Configuration import Configuration
2
+from socialintengine.synergy.object.Rock import Rock
3
+from synergine.metas import metas
4
+from socialintengine.cst import IMPENETRABLE
5
+from synergine.synergy.Simulation import Simulation
6
+
7
+
8
+class RocksConfiguration(Configuration):
9
+
10
+    def get_start_objects(self):
11
+
12
+      rocks = []
13
+
14
+      for i in range(20):
15
+          rock = Rock()
16
+          metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
17
+          rock.add_trace((0, 10+i, 15))
18
+          rocks.append(rock)
19
+
20
+      for i in range(20):
21
+          rock = Rock()
22
+          rock.add_trace((0, 10+i, 25))
23
+          metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
24
+          rocks.append(rock)
25
+
26
+      return rocks

+ 4 - 0
socialintengine/synergy/Simulation.py View File

@@ -0,0 +1,4 @@
1
+from synergine.synergy.Simulation import Simulation as BaseSimulation
2
+
3
+class Simulation(BaseSimulation):
4
+  pass

+ 39 - 0
socialintengine/synergy/event/move/MoveAction.py View File

@@ -0,0 +1,39 @@
1
+from synergine.synergy.event.Action import Action
2
+from socialintengine.synergy.event.move.MoveEvent import MoveEvent
3
+from random import randint
4
+from xyzworld.cst import POSITION, POSITIONS
5
+from socialintengine.cst import IMPENETRABLE
6
+from synergine.synergy.Simulation import Simulation
7
+
8
+
9
+class MoveAction(Action):
10
+
11
+    _listen = MoveEvent
12
+
13
+    def __init__(self, object_id, parameters):
14
+      super().__init__(object_id, parameters)
15
+      self._move_to = None
16
+
17
+    def prepare(self, context):
18
+      object_point = context.metas.value.get(POSITION, self._object_id)
19
+      choosed_direction_point = self._get_random_direction_point(object_point)
20
+      if self._direction_point_is_possible(context, choosed_direction_point):
21
+        self._move_to = choosed_direction_point
22
+
23
+    def _get_random_direction_point(self, reference_point):
24
+        z, x, y = reference_point
25
+        new_z = z
26
+        new_x = x + randint(-1, 1)
27
+        new_y = y + randint(-1, 1)
28
+        return (new_z, new_x, new_y)
29
+
30
+    def _direction_point_is_possible(self, context, direction_point):
31
+        objects_ids_on_this_point = context.metas.list.get(POSITIONS, direction_point, allow_empty=True)
32
+        for object_id_on_this_point in objects_ids_on_this_point:
33
+          if context.metas.list.have(Simulation.STATE, object_id_on_this_point, IMPENETRABLE):
34
+            return False
35
+        return True
36
+
37
+    def run(self, obj, collection, context):
38
+        if self._move_to is not None:
39
+            obj.add_trace(self._move_to)

+ 15 - 0
socialintengine/synergy/event/move/MoveEvent.py View File

@@ -0,0 +1,15 @@
1
+from synergine.synergy.event.Event import Event
2
+from xyzworld.mechanism.PositionedArroundMechanism import PositionedArroundMechanism
3
+
4
+
5
+class MoveEvent(Event):
6
+
7
+    def concern(self, object_id, context):
8
+        return True
9
+
10
+    def __init__(self, actions):
11
+        super().__init__(actions)
12
+        self._mechanism = PositionedArroundMechanism
13
+
14
+    def _object_match(self, object_id, context, parameters={}):
15
+      return True

+ 4 - 0
socialintengine/synergy/object/Bug.py View File

@@ -0,0 +1,4 @@
1
+from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
+
3
+class Bug(XyzSynergyObject):
4
+  pass

+ 4 - 0
socialintengine/synergy/object/Rock.py View File

@@ -0,0 +1,4 @@
1
+from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
+
3
+class Rock(XyzSynergyObject):
4
+  pass

+ 4 - 0
socialintengine/synergy/object/ant/Ant.py View File

@@ -0,0 +1,4 @@
1
+from socialintengine.synergy.object.Bug import Bug
2
+
3
+class Ant(Bug):
4
+  pass