Browse Source

Sandbox with blue and red colonys

Bastien Sevajol 9 years ago
parent
commit
24be866059

+ 3 - 7
config.py View File

@@ -1,12 +1,8 @@
1 1
 from xyzworld.Context import Context as XyzContext
2 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 3
 from socialintengine.display.Pygame import Pygame
8 4
 from socialintengine.display.pygame.visualisation import visualisation as pygame_visualisation
9
-
5
+from socialintengine.sandbox.redblue.red_blue_colonys import collections
10 6
 
11 7
 config = {
12 8
     'app': {
@@ -18,11 +14,11 @@ config = {
18 14
     'engine': {
19 15
         'fpsmax': 5,
20 16
         'debug': {
21
-            'mainprocess': False,
17
+            'mainprocess': True,
22 18
             'cycles': -1
23 19
         }
24 20
     },
25
-    'simulations' : [Simulation([Colony(ColonyConfiguration()), Rocks(RocksConfiguration())])],
21
+    'simulations' : [Simulation(collections)],
26 22
     'connections': [Pygame],
27 23
     'terminal': {
28 24
       'pygame': {

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


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


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

@@ -2,16 +2,22 @@ from xyworld.display.object.pygame.PygameImage import PygameImage
2 2
 from xyworld.display.object.pygame.DirectionnedImage import DirectionnedImage
3 3
 from socialintengine.synergy.object.Bug import Bug
4 4
 from socialintengine.synergy.object.ant.Ant import Ant
5
+from socialintengine.sandbox.redblue.BlueAnt import BlueAnt
6
+from socialintengine.sandbox.redblue.RedAnt import RedAnt
5 7
 from socialintengine.synergy.object.Rock import Rock
6 8
 from os import getcwd
7 9
 from synergine.metas import metas
8 10
 from socialintengine.cst import PREVIOUS_DIRECTION
9 11
 
10 12
 ant = PygameImage.from_filepath(getcwd()+'/socialintengine/display/pygame/image/ant.png')
13
+red_ant = PygameImage.from_filepath(getcwd()+'/socialintengine/display/pygame/image/red_ant.png')
14
+blue_ant = PygameImage.from_filepath(getcwd()+'/socialintengine/display/pygame/image/blue_ant.png')
11 15
 bug = PygameImage.from_filepath(getcwd()+'/socialintengine/display/pygame/image/ant.png')
12 16
 rock = PygameImage.from_filepath(getcwd()+'/socialintengine/display/pygame/image/rock.png')
13 17
 
14 18
 directions_ant = DirectionnedImage(ant)
19
+directions_red_ant = DirectionnedImage(red_ant)
20
+directions_blue_ant = DirectionnedImage(blue_ant)
15 21
 
16 22
 def bug_direction(bug):
17 23
     try:
@@ -20,9 +26,31 @@ def bug_direction(bug):
20 26
         previous_direction = 14
21 27
     return directions_ant.get_for_direction(previous_direction)
22 28
 
29
+def red_ant_direction(bug):
30
+    try:
31
+        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
32
+    except KeyError:
33
+        previous_direction = 14
34
+    return directions_red_ant.get_for_direction(previous_direction)
35
+
36
+def blue_ant_direction(bug):
37
+    try:
38
+        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
39
+    except KeyError:
40
+        previous_direction = 14
41
+    return directions_blue_ant.get_for_direction(previous_direction)
42
+
23 43
 visualisation = {
24 44
     'window': {},
25 45
     'objects': {
46
+        RedAnt: {
47
+            'default': red_ant,
48
+            'callbacks': [red_ant_direction]
49
+        },
50
+        BlueAnt: {
51
+            'default': blue_ant,
52
+            'callbacks': [blue_ant_direction]
53
+        },
26 54
         Ant: {
27 55
             'default': ant,
28 56
             'callbacks': [bug_direction]

+ 4 - 0
socialintengine/sandbox/redblue/BlueAnt.py View File

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

+ 8 - 0
socialintengine/sandbox/redblue/BlueColonyConfiguration.py View File

@@ -0,0 +1,8 @@
1
+from socialintengine.synergy.ColonyConfiguration import ColonyConfiguration
2
+from socialintengine.sandbox.redblue.BlueAnt import BlueAnt
3
+
4
+
5
+class BlueColonyConfiguration(ColonyConfiguration):
6
+
7
+    _start_position = (0, 20, 20)
8
+    _ant_class = BlueAnt

+ 4 - 0
socialintengine/sandbox/redblue/RedAnt.py View File

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

+ 8 - 0
socialintengine/sandbox/redblue/RedColonyConfiguration.py View File

@@ -0,0 +1,8 @@
1
+from socialintengine.synergy.ColonyConfiguration import ColonyConfiguration
2
+from socialintengine.sandbox.redblue.RedAnt import RedAnt
3
+
4
+
5
+class RedColonyConfiguration(ColonyConfiguration):
6
+
7
+    _start_position = (0, 70, 20)
8
+    _ant_class = RedAnt

+ 7 - 0
socialintengine/sandbox/redblue/red_blue_colonys.py View File

@@ -0,0 +1,7 @@
1
+from socialintengine.sandbox.redblue.RedColonyConfiguration import RedColonyConfiguration
2
+from socialintengine.sandbox.redblue.BlueColonyConfiguration import BlueColonyConfiguration
3
+from socialintengine.synergy.Colony import Colony
4
+from socialintengine.synergy.Rocks import Rocks
5
+from socialintengine.synergy.RocksConfiguration import RocksConfiguration
6
+
7
+collections = [Colony(BlueColonyConfiguration()), Colony(RedColonyConfiguration()), Rocks(RocksConfiguration())]

+ 6 - 3
socialintengine/synergy/ColonyConfiguration.py View File

@@ -7,12 +7,15 @@ from synergine.synergy.Simulation import Simulation
7 7
 
8 8
 class ColonyConfiguration(Configuration):
9 9
 
10
+    _start_position = (0, 20, 20)
11
+    _ant_class = Ant
12
+
10 13
     def get_start_objects(self):
11 14
 
12 15
       ants = []
13
-      for i in range(10):
14
-          ant = Ant()
15
-          ant.set_position((0, 20, 20))
16
+      for i in range(100):
17
+          ant = self._ant_class()
18
+          ant.set_position(self._start_position)
16 19
           metas.list.add(Simulation.STATE, ant.get_id(), ALIVE)
17 20
           ants.append(ant)
18 21
 

+ 15 - 3
socialintengine/synergy/RocksConfiguration.py View File

@@ -11,13 +11,13 @@ class RocksConfiguration(Configuration):
11 11
 
12 12
       rocks = []
13 13
 
14
-      for i in range(50):
14
+      for i in range(100):
15 15
           rock = Rock()
16 16
           metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
17 17
           rock.set_position((0, 0+i, 0))
18 18
           rocks.append(rock)
19 19
 
20
-      for i in range(50):
20
+      for i in range(100):
21 21
           rock = Rock()
22 22
           metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
23 23
           rock.set_position((0, 0+i, 50))
@@ -30,8 +30,15 @@ class RocksConfiguration(Configuration):
30 30
           rocks.append(rock)
31 31
 
32 32
       for i in range(50):
33
+          if i is not 25:
34
+            rock = Rock()
35
+            rock.set_position((0, 50, 0+i))
36
+            metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
37
+            rocks.append(rock)
38
+
39
+      for i in range(50):
33 40
           rock = Rock()
34
-          rock.set_position((0, 50, 0+i))
41
+          rock.set_position((0, 100, 0+i))
35 42
           metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
36 43
           rocks.append(rock)
37 44
 
@@ -40,4 +47,9 @@ class RocksConfiguration(Configuration):
40 47
       metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
41 48
       rocks.append(rock)
42 49
 
50
+      rock = Rock()
51
+      rock.set_position((0, 100, 50))
52
+      metas.list.add(Simulation.STATE, rock.get_id(), IMPENETRABLE)
53
+      rocks.append(rock)
54
+
43 55
       return rocks

+ 6 - 1
socialintengine/synergy/Simulation.py View File

@@ -1,4 +1,9 @@
1 1
 from synergine.synergy.Simulation import Simulation as BaseSimulation
2
+from xyzworld.cst import POSITION, POSITIONS
3
+
2 4
 
3 5
 class Simulation(BaseSimulation):
4
-  pass
6
+
7
+    def end_cycle(self, context):
8
+        if context.get_cycle() % 100 is 0:
9
+            context.metas.list.clean(POSITIONS)