Kaynağa Gözat

AI: Put object outside if not enought place inside

Bastien Sevajol 9 yıl önce
ebeveyn
işleme
5905d5c799

+ 3 - 0
TODO Dosyayı Görüntüle

@@ -5,3 +5,6 @@
5 5
 * Poser (nourriture, etc): que si a carre penetrable tout autour (pour pas remplir couloir)
6 6
 * Poser à coté: moins envie de prendre plus le tas est petit, et plus envie de poser si tas grand etc
7 7
 * Poser: Si échoué à poser x fois: Mode "evacuer": Sortie de la zone odorante et poser.
8
+* Les ordres de mouvement doivent dependre des differents bout de brain
9
+* il commence a y avoir grosse embrouille dans les cerveaux :/
10
+* !!! GO_OUTSIDE: Remlacer par EXPLO. Ca evite de vouloir suivreles molecules a l'envers ! Mais QUID des larves ?

+ 3 - 2
config.py Dosyayı Görüntüle

@@ -61,13 +61,14 @@ config = {
61 61
             'cant_put_still': 5
62 62
         },
63 63
         'put': {
64
-            'max_objects_at_same_position': 5
64
+            'max_objects_at_same_position': 1,
65
+            'max_put_fail_count': 20
65 66
         }
66 67
     },
67 68
     'stigmergy': {
68 69
         'molecule': {
69 70
             'evaporate_decrement': 5,
70
-            'evaporate_min_age': 100,
71
+            'evaporate_min_age': 1000,
71 72
             'evaporate_each_cycle': 100
72 73
         }
73 74
     }

+ 14 - 0
intelligine/core/exceptions.py Dosyayı Görüntüle

@@ -13,6 +13,16 @@ class UnableToFoundMovement(MovementException):
13 13
     pass
14 14
 
15 15
 
16
+class MovementModeExpired(MovementException):
17
+
18
+    def __init__(self, *args, mode, **kwargs):
19
+        super().__init__(*args, **kwargs)
20
+        self._switch_to_mode = mode
21
+
22
+    def get_switch_to_mode(self):
23
+        return self._switch_to_mode
24
+
25
+
16 26
 class MoleculeException(Exception):
17 27
     pass
18 28
 
@@ -75,4 +85,8 @@ class NearNothingFound(NearException):
75 85
 
76 86
 
77 87
 class CantFindWhereToPut(ActionException):
88
+    pass
89
+
90
+
91
+class ExplorationAlreadyResolved(DirectionException):
78 92
     pass

+ 6 - 0
intelligine/cst.py Dosyayı Görüntüle

@@ -15,13 +15,18 @@ CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
15 15
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
16 16
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
17 17
 MOLECULE_SEARCHING = IncrementedNamedInt.get('intelligine.molecule_searching')
18
+MOLECULE_SEARCHING_WAY = IncrementedNamedInt.get('intelligine.molecule_searching_way')
18 19
 MOLECULES = IncrementedNamedInt.get('intelligine.molecules')
19 20
 
21
+PUT_FAIL_COUNT = IncrementedNamedInt.get('intelligine.put.fail.count')
22
+
20 23
 MODE = IncrementedNamedInt.get('intelligine.basebug.move')
21 24
 MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.explo')
22 25
 MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.gohome')
23 26
 MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.nurse')
24 27
 MODE_HOME = IncrementedNamedInt.get('intelligine.basebug.move.home')
28
+MODE_GO_OUTSIDE = IncrementedNamedInt.get('intelligine.basebug.move.go_outside')
29
+MODE_SEARCH_AROUND = IncrementedNamedInt.get('intelligine.basebug.move.search_around')
25 30
 
26 31
 MOVE_BYBASS = IncrementedNamedInt.get('intelligine.basebug.move.bypass')
27 32
 MOVE_BYBASS_DISTANCE = IncrementedNamedInt.get('intelligine.basebug.move.bypass.distance')
@@ -57,6 +62,7 @@ COL_TRANSPORTER_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_
57 62
 COL_TRANSPORTER_NOT_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_not_carrying')
58 63
 COL_EATABLE = IncrementedNamedInt.get('intelligine.col.eatable')
59 64
 COL_SMELL = IncrementedNamedInt.get('intelligine.col.smell')
65
+COL_PUT_OUTSIDE = IncrementedNamedInt.get('intelligine.col.put_outside')
60 66
 
61 67
 INSTANCE_CLASS = IncrementedNamedInt.get('intelligine.instance_class')
62 68
 

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1389 - 1389
intelligine/sandbox/exploration/map.tmx


+ 108 - 108
intelligine/sandbox/test/test.tmx Dosyayı Görüntüle

@@ -933,9 +933,9 @@
933 933
    <tile gid="241"/>
934 934
    <tile gid="241"/>
935 935
    <tile gid="241"/>
936
-   <tile gid="241"/>
937
-   <tile gid="241"/>
938
-   <tile gid="241"/>
936
+   <tile gid="0"/>
937
+   <tile gid="0"/>
938
+   <tile gid="0"/>
939 939
    <tile gid="241"/>
940 940
    <tile gid="241"/>
941 941
    <tile gid="241"/>
@@ -1031,12 +1031,12 @@
1031 1031
    <tile gid="241"/>
1032 1032
    <tile gid="241"/>
1033 1033
    <tile gid="241"/>
1034
-   <tile gid="241"/>
1035
-   <tile gid="241"/>
1036
-   <tile gid="241"/>
1037
-   <tile gid="241"/>
1038
-   <tile gid="241"/>
1039
-   <tile gid="241"/>
1034
+   <tile gid="0"/>
1035
+   <tile gid="0"/>
1036
+   <tile gid="0"/>
1037
+   <tile gid="0"/>
1038
+   <tile gid="0"/>
1039
+   <tile gid="0"/>
1040 1040
    <tile gid="241"/>
1041 1041
    <tile gid="241"/>
1042 1042
    <tile gid="241"/>
@@ -1129,14 +1129,14 @@
1129 1129
    <tile gid="241"/>
1130 1130
    <tile gid="241"/>
1131 1131
    <tile gid="241"/>
1132
-   <tile gid="241"/>
1133
-   <tile gid="241"/>
1134
-   <tile gid="241"/>
1135
-   <tile gid="241"/>
1136
-   <tile gid="241"/>
1137
-   <tile gid="241"/>
1138
-   <tile gid="241"/>
1139
-   <tile gid="241"/>
1132
+   <tile gid="0"/>
1133
+   <tile gid="0"/>
1134
+   <tile gid="0"/>
1135
+   <tile gid="0"/>
1136
+   <tile gid="0"/>
1137
+   <tile gid="0"/>
1138
+   <tile gid="0"/>
1139
+   <tile gid="0"/>
1140 1140
    <tile gid="241"/>
1141 1141
    <tile gid="241"/>
1142 1142
    <tile gid="241"/>
@@ -1229,14 +1229,14 @@
1229 1229
    <tile gid="241"/>
1230 1230
    <tile gid="241"/>
1231 1231
    <tile gid="241"/>
1232
-   <tile gid="241"/>
1233
-   <tile gid="241"/>
1234
-   <tile gid="241"/>
1235
-   <tile gid="241"/>
1232
+   <tile gid="0"/>
1233
+   <tile gid="0"/>
1234
+   <tile gid="0"/>
1235
+   <tile gid="0"/>
1236 1236
    <tile gid="242"/>
1237
-   <tile gid="241"/>
1238
-   <tile gid="241"/>
1239
-   <tile gid="241"/>
1237
+   <tile gid="0"/>
1238
+   <tile gid="0"/>
1239
+   <tile gid="0"/>
1240 1240
    <tile gid="241"/>
1241 1241
    <tile gid="241"/>
1242 1242
    <tile gid="241"/>
@@ -1329,14 +1329,14 @@
1329 1329
    <tile gid="241"/>
1330 1330
    <tile gid="241"/>
1331 1331
    <tile gid="241"/>
1332
-   <tile gid="241"/>
1333
-   <tile gid="241"/>
1334
-   <tile gid="241"/>
1335
-   <tile gid="241"/>
1336 1332
    <tile gid="0"/>
1337
-   <tile gid="241"/>
1338
-   <tile gid="241"/>
1339
-   <tile gid="241"/>
1333
+   <tile gid="0"/>
1334
+   <tile gid="0"/>
1335
+   <tile gid="0"/>
1336
+   <tile gid="0"/>
1337
+   <tile gid="0"/>
1338
+   <tile gid="0"/>
1339
+   <tile gid="0"/>
1340 1340
    <tile gid="241"/>
1341 1341
    <tile gid="241"/>
1342 1342
    <tile gid="241"/>
@@ -1428,15 +1428,15 @@
1428 1428
    <tile gid="241"/>
1429 1429
    <tile gid="241"/>
1430 1430
    <tile gid="241"/>
1431
-   <tile gid="241"/>
1432
-   <tile gid="241"/>
1433
-   <tile gid="241"/>
1434
-   <tile gid="241"/>
1435
-   <tile gid="241"/>
1436 1431
    <tile gid="0"/>
1437
-   <tile gid="241"/>
1438
-   <tile gid="241"/>
1439
-   <tile gid="241"/>
1432
+   <tile gid="0"/>
1433
+   <tile gid="0"/>
1434
+   <tile gid="0"/>
1435
+   <tile gid="0"/>
1436
+   <tile gid="0"/>
1437
+   <tile gid="0"/>
1438
+   <tile gid="0"/>
1439
+   <tile gid="0"/>
1440 1440
    <tile gid="241"/>
1441 1441
    <tile gid="241"/>
1442 1442
    <tile gid="241"/>
@@ -1526,16 +1526,16 @@
1526 1526
    <tile gid="241"/>
1527 1527
    <tile gid="241"/>
1528 1528
    <tile gid="241"/>
1529
-   <tile gid="241"/>
1530
-   <tile gid="241"/>
1531
-   <tile gid="241"/>
1532
-   <tile gid="241"/>
1533
-   <tile gid="241"/>
1534
-   <tile gid="241"/>
1535
-   <tile gid="241"/>
1529
+   <tile gid="0"/>
1530
+   <tile gid="0"/>
1531
+   <tile gid="0"/>
1532
+   <tile gid="0"/>
1536 1533
    <tile gid="0"/>
1537 1534
    <tile gid="241"/>
1538
-   <tile gid="241"/>
1535
+   <tile gid="0"/>
1536
+   <tile gid="0"/>
1537
+   <tile gid="0"/>
1538
+   <tile gid="0"/>
1539 1539
    <tile gid="241"/>
1540 1540
    <tile gid="241"/>
1541 1541
    <tile gid="241"/>
@@ -1626,15 +1626,15 @@
1626 1626
    <tile gid="241"/>
1627 1627
    <tile gid="241"/>
1628 1628
    <tile gid="241"/>
1629
-   <tile gid="241"/>
1630
-   <tile gid="241"/>
1631
-   <tile gid="241"/>
1632
-   <tile gid="241"/>
1633
-   <tile gid="241"/>
1629
+   <tile gid="0"/>
1630
+   <tile gid="0"/>
1631
+   <tile gid="0"/>
1632
+   <tile gid="0"/>
1634 1633
    <tile gid="241"/>
1635 1634
    <tile gid="241"/>
1636 1635
    <tile gid="0"/>
1637
-   <tile gid="241"/>
1636
+   <tile gid="0"/>
1637
+   <tile gid="0"/>
1638 1638
    <tile gid="241"/>
1639 1639
    <tile gid="241"/>
1640 1640
    <tile gid="241"/>
@@ -1726,10 +1726,10 @@
1726 1726
    <tile gid="241"/>
1727 1727
    <tile gid="241"/>
1728 1728
    <tile gid="241"/>
1729
-   <tile gid="241"/>
1730
-   <tile gid="241"/>
1731
-   <tile gid="241"/>
1732
-   <tile gid="241"/>
1729
+   <tile gid="0"/>
1730
+   <tile gid="0"/>
1731
+   <tile gid="0"/>
1732
+   <tile gid="0"/>
1733 1733
    <tile gid="241"/>
1734 1734
    <tile gid="241"/>
1735 1735
    <tile gid="241"/>
@@ -1826,22 +1826,22 @@
1826 1826
    <tile gid="241"/>
1827 1827
    <tile gid="241"/>
1828 1828
    <tile gid="241"/>
1829
-   <tile gid="241"/>
1830
-   <tile gid="241"/>
1831
-   <tile gid="241"/>
1832
-   <tile gid="241"/>
1833
-   <tile gid="241"/>
1834
-   <tile gid="241"/>
1835
-   <tile gid="241"/>
1829
+   <tile gid="0"/>
1830
+   <tile gid="0"/>
1831
+   <tile gid="0"/>
1832
+   <tile gid="0"/>
1833
+   <tile gid="0"/>
1834
+   <tile gid="0"/>
1835
+   <tile gid="0"/>
1836 1836
    <tile gid="0"/>
1837 1837
    <tile gid="241"/>
1838 1838
    <tile gid="241"/>
1839 1839
    <tile gid="241"/>
1840
-   <tile gid="241"/>
1841
-   <tile gid="241"/>
1842
-   <tile gid="241"/>
1843
-   <tile gid="241"/>
1844
-   <tile gid="241"/>
1840
+   <tile gid="0"/>
1841
+   <tile gid="0"/>
1842
+   <tile gid="0"/>
1843
+   <tile gid="0"/>
1844
+   <tile gid="0"/>
1845 1845
    <tile gid="241"/>
1846 1846
    <tile gid="241"/>
1847 1847
    <tile gid="241"/>
@@ -1926,22 +1926,22 @@
1926 1926
    <tile gid="241"/>
1927 1927
    <tile gid="241"/>
1928 1928
    <tile gid="241"/>
1929
-   <tile gid="241"/>
1930
-   <tile gid="241"/>
1931
-   <tile gid="241"/>
1932
-   <tile gid="241"/>
1933
-   <tile gid="241"/>
1934
-   <tile gid="241"/>
1935
-   <tile gid="241"/>
1929
+   <tile gid="0"/>
1930
+   <tile gid="0"/>
1931
+   <tile gid="0"/>
1936 1932
    <tile gid="0"/>
1937 1933
    <tile gid="241"/>
1938 1934
    <tile gid="241"/>
1939 1935
    <tile gid="241"/>
1936
+   <tile gid="0"/>
1940 1937
    <tile gid="241"/>
1941 1938
    <tile gid="241"/>
1942 1939
    <tile gid="241"/>
1943
-   <tile gid="241"/>
1944
-   <tile gid="241"/>
1940
+   <tile gid="0"/>
1941
+   <tile gid="0"/>
1942
+   <tile gid="0"/>
1943
+   <tile gid="0"/>
1944
+   <tile gid="0"/>
1945 1945
    <tile gid="241"/>
1946 1946
    <tile gid="241"/>
1947 1947
    <tile gid="241"/>
@@ -2026,22 +2026,22 @@
2026 2026
    <tile gid="241"/>
2027 2027
    <tile gid="241"/>
2028 2028
    <tile gid="241"/>
2029
-   <tile gid="241"/>
2030
-   <tile gid="241"/>
2031
-   <tile gid="241"/>
2032
-   <tile gid="241"/>
2029
+   <tile gid="0"/>
2030
+   <tile gid="0"/>
2031
+   <tile gid="0"/>
2032
+   <tile gid="0"/>
2033 2033
    <tile gid="241"/>
2034 2034
    <tile gid="241"/>
2035 2035
    <tile gid="241"/>
2036 2036
    <tile gid="1"/>
2037 2037
    <tile gid="241"/>
2038
-   <tile gid="241"/>
2039
-   <tile gid="241"/>
2040
-   <tile gid="241"/>
2041
-   <tile gid="241"/>
2042
-   <tile gid="241"/>
2043
-   <tile gid="241"/>
2044
-   <tile gid="241"/>
2038
+   <tile gid="0"/>
2039
+   <tile gid="0"/>
2040
+   <tile gid="0"/>
2041
+   <tile gid="0"/>
2042
+   <tile gid="0"/>
2043
+   <tile gid="0"/>
2044
+   <tile gid="243"/>
2045 2045
    <tile gid="241"/>
2046 2046
    <tile gid="241"/>
2047 2047
    <tile gid="241"/>
@@ -2137,11 +2137,11 @@
2137 2137
    <tile gid="241"/>
2138 2138
    <tile gid="241"/>
2139 2139
    <tile gid="241"/>
2140
-   <tile gid="241"/>
2141
-   <tile gid="241"/>
2142
-   <tile gid="241"/>
2143
-   <tile gid="241"/>
2144
-   <tile gid="241"/>
2140
+   <tile gid="0"/>
2141
+   <tile gid="0"/>
2142
+   <tile gid="0"/>
2143
+   <tile gid="0"/>
2144
+   <tile gid="0"/>
2145 2145
    <tile gid="241"/>
2146 2146
    <tile gid="241"/>
2147 2147
    <tile gid="241"/>
@@ -2237,11 +2237,11 @@
2237 2237
    <tile gid="0"/>
2238 2238
    <tile gid="241"/>
2239 2239
    <tile gid="241"/>
2240
-   <tile gid="241"/>
2241
-   <tile gid="241"/>
2242
-   <tile gid="241"/>
2243
-   <tile gid="241"/>
2244
-   <tile gid="241"/>
2240
+   <tile gid="0"/>
2241
+   <tile gid="0"/>
2242
+   <tile gid="0"/>
2243
+   <tile gid="0"/>
2244
+   <tile gid="0"/>
2245 2245
    <tile gid="241"/>
2246 2246
    <tile gid="241"/>
2247 2247
    <tile gid="241"/>
@@ -2331,11 +2331,11 @@
2331 2331
    <tile gid="241"/>
2332 2332
    <tile gid="241"/>
2333 2333
    <tile gid="241"/>
2334
-   <tile gid="241"/>
2334
+   <tile gid="0"/>
2335 2335
    <tile gid="0"/>
2336 2336
    <tile gid="243"/>
2337 2337
    <tile gid="0"/>
2338
-   <tile gid="241"/>
2338
+   <tile gid="0"/>
2339 2339
    <tile gid="241"/>
2340 2340
    <tile gid="241"/>
2341 2341
    <tile gid="241"/>
@@ -2431,11 +2431,11 @@
2431 2431
    <tile gid="241"/>
2432 2432
    <tile gid="241"/>
2433 2433
    <tile gid="241"/>
2434
-   <tile gid="241"/>
2435 2434
    <tile gid="0"/>
2436 2435
    <tile gid="0"/>
2437 2436
    <tile gid="0"/>
2438
-   <tile gid="241"/>
2437
+   <tile gid="0"/>
2438
+   <tile gid="0"/>
2439 2439
    <tile gid="241"/>
2440 2440
    <tile gid="241"/>
2441 2441
    <tile gid="241"/>
@@ -2531,11 +2531,11 @@
2531 2531
    <tile gid="241"/>
2532 2532
    <tile gid="241"/>
2533 2533
    <tile gid="241"/>
2534
-   <tile gid="241"/>
2535
-   <tile gid="241"/>
2536
-   <tile gid="241"/>
2537
-   <tile gid="241"/>
2538
-   <tile gid="241"/>
2534
+   <tile gid="0"/>
2535
+   <tile gid="0"/>
2536
+   <tile gid="0"/>
2537
+   <tile gid="0"/>
2538
+   <tile gid="0"/>
2539 2539
    <tile gid="241"/>
2540 2540
    <tile gid="241"/>
2541 2541
    <tile gid="241"/>

+ 13 - 4
intelligine/simulation/molecule/DirectionMolecule.py Dosyayı Görüntüle

@@ -7,6 +7,9 @@ from intelligine.synergy.event.move.direction import get_direction_for_degrees
7 7
 
8 8
 class DirectionMolecule():
9 9
 
10
+    WAY_UP = 'u'
11
+    WAY_DOWN = 'd'
12
+
10 13
     _positions_key = None
11 14
 
12 15
     @classmethod
@@ -15,16 +18,19 @@ class DirectionMolecule():
15 18
         context.metas.list.add(MOLECULES, MOLECULES, point, assert_not_in=False)
16 19
 
17 20
     @classmethod
18
-    def get_direction_for_point(cls, context, point, molecule_type):
21
+    def get_direction_for_point(cls, context, point, molecule_type, molecule_way=WAY_UP):
19 22
         flavour = context.molecules().get_flavour(point)
20 23
         molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
21 24
 
22 25
         distance = molecule.get_distance()
23
-        around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance
26
+        around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance #  TODO <= ?
27
+        if molecule_way == cls.WAY_DOWN:
28
+            around_molecule_filter = lambda around_molecule: around_molecule.get_distance() >= distance
24 29
         around_molecules_points = cls._get_around_molecules(context, point, molecule_type,
25 30
                                                             molecule_filter=around_molecule_filter)
26 31
 
27
-        if not around_molecules_points:
32
+        if not around_molecules_points \
33
+           or (len(around_molecules_points) == 1 and around_molecules_points[0][0] == point):
28 34
             raise NoMolecule()
29 35
 
30 36
         shuffle(around_molecules_points)
@@ -36,9 +42,12 @@ class DirectionMolecule():
36 42
             if around_molecule_sorted[1].get_intensity() == max_intensity:
37 43
                 around_molecules_max.append(around_molecule_sorted)
38 44
 
45
+        reverse = False
46
+        if molecule_way == cls.WAY_DOWN:
47
+            reverse = True
39 48
         around_molecules_sorted_by_distance = sorted(around_molecules_max,
40 49
                                                       key=lambda x: x[1].get_distance(),
41
-                                                      reverse=False)
50
+                                                      reverse=reverse)
42 51
 
43 52
         go_to_point = around_molecules_sorted_by_distance[0][0]
44 53
 

+ 16 - 3
intelligine/simulation/object/brain/AntBrain.py Dosyayı Görüntüle

@@ -1,15 +1,16 @@
1
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
1 2
 from intelligine.simulation.object.brain.Brain import Brain
2 3
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
3
-from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
4 4
 from intelligine.cst import MODE, MODE_EXPLO, MODE_GOHOME, PHEROMON_DIR_EXPLO, \
5 5
     BRAIN_PART_TAKE, BRAIN_PART_PUT, MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MODE_HOME, \
6
-    SMELL_FOOD, SMELL_EGG
6
+    SMELL_FOOD, SMELL_EGG, MODE_GO_OUTSIDE, MOLECULE_SEARCHING_WAY, MODE_SEARCH_AROUND
7 7
 from intelligine.cst import MOLECULE_SEARCHING
8 8
 from intelligine.cst import BRAIN_PART_MOVE
9 9
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
10 10
 from intelligine.simulation.object.brain.part.transport.AntTakeBrainPart import AntTakeBrainPart
11 11
 from intelligine.synergy.object.Food import Food
12 12
 from intelligine.synergy.object.ant.Egg import Egg
13
+from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
13 14
 from synergine.core.exceptions import NotFound
14 15
 
15 16
 
@@ -51,6 +52,10 @@ class AntBrain(Brain):
51 52
             molecule_direction_type = None
52 53
         elif mode == MODE_HOME:
53 54
             molecule_direction_type = PHEROMON_DIR_EXPLO
55
+        elif mode == MODE_GO_OUTSIDE:
56
+            molecule_direction_type = None
57
+        elif mode == MODE_SEARCH_AROUND:
58
+            molecule_direction_type = PHEROMON_DIR_EXPLO
54 59
         else:
55 60
             raise NotImplementedError()
56 61
 
@@ -61,6 +66,7 @@ class AntBrain(Brain):
61 66
             self._host.get_movement_molecule_gland().disable()
62 67
 
63 68
     def _update_molecule_searching(self, mode):
69
+        way = DirectionMolecule.WAY_UP
64 70
         if mode == MODE_EXPLO:
65 71
             molecule_searching = PHEROMON_DIR_EXPLO
66 72
         elif mode == MODE_GOHOME:
@@ -68,13 +74,20 @@ class AntBrain(Brain):
68 74
         elif mode == MODE_NURSE:
69 75
             molecule_searching = PHEROMON_DIR_NONE
70 76
         elif mode == MODE_HOME:
71
-            # TODO: Ca depend de ce que fait la fourmis, si s'occupe des oeufs, etc
72 77
             molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
78
+        elif mode == MODE_GO_OUTSIDE:
79
+            #  TODO: Dans l'idée c'est sortir, donc il faudrait remonter toutes les smells ...
80
+            molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
81
+            way = DirectionMolecule.WAY_DOWN
82
+        elif mode == MODE_SEARCH_AROUND:
83
+            molecule_searching = PHEROMON_DIR_NONE
73 84
         else:
74 85
             raise NotImplementedError()
75 86
 
76 87
         self._molecule_searching = molecule_searching
88
+        self._molecule_searching_way = way
77 89
         self._context.metas.value.set(MOLECULE_SEARCHING, self._host.get_id(), molecule_searching)
90
+        self._context.metas.value.set(MOLECULE_SEARCHING_WAY, self._host.get_id(), way)
78 91
 
79 92
     def get_movement_mode(self):
80 93
         return self._movement_mode

+ 36 - 6
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py Dosyayı Görüntüle

@@ -1,12 +1,14 @@
1
+from synergine.core.Core import Core
1 2
 from intelligine.shorcut.brain import get_brain_class
2 3
 from intelligine.simulation.object.brain.part.move.AntStar.ByPass import ByPass
3 4
 from intelligine.simulation.object.brain.part.move.AntStar.Host import Host
4 5
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
5 6
 from intelligine.synergy.event.move.direction import directions_modifiers, get_position_with_direction_decal
6 7
 from synergine_xyz.cst import POSITION
7
-from intelligine.core.exceptions import NoMolecule
8
+from intelligine.core.exceptions import NoMolecule, ExplorationAlreadyResolved, MovementModeExpired
8 9
 from intelligine.cst import MOLECULE_SEARCHING, MODE_EXPLO, MODE_HOME, MODE, MODE_GOHOME, \
9
-    EXPLORATION_VECTOR, MOLECULES_DIRECTION
10
+    EXPLORATION_VECTOR, MOLECULES_DIRECTION, PUT_FAIL_COUNT, MODE_GO_OUTSIDE, MOLECULE_SEARCHING_WAY, COL_PUT_OUTSIDE, \
11
+    MODE_SEARCH_AROUND
10 12
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
11 13
 
12 14
 
@@ -26,7 +28,10 @@ class AntMoveBrainPart(MoveBrainPart):
26 28
     def get_direction(cls, context, object_id):
27 29
         move_mode = context.metas.value.get(MODE, object_id)
28 30
         if move_mode == MODE_GOHOME:
29
-            return cls._get_direction_with_exploration_vector(context, object_id)
31
+            try:
32
+                return cls._get_direction_with_exploration_vector(context, object_id)
33
+            except ExplorationAlreadyResolved:
34
+                raise MovementModeExpired(mode=MODE_SEARCH_AROUND)
30 35
         else:
31 36
             try:
32 37
                 return cls._get_direction_with_molecules(context, object_id)
@@ -39,9 +44,15 @@ class AntMoveBrainPart(MoveBrainPart):
39 44
     def _get_direction_with_molecules(cls, context, object_id):
40 45
         object_point = context.metas.value.get(POSITION, object_id)
41 46
         molecule_type = context.metas.value.get(MOLECULE_SEARCHING, object_id)
47
+        molecule_way = context.metas.value.get(MOLECULE_SEARCHING_WAY, object_id)
42 48
         try:
43
-            direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type)
49
+            direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type, molecule_way)
44 50
         except NoMolecule:
51
+
52
+            movement_mode = context.metas.value.get(MODE, object_id)
53
+            if movement_mode == MODE_GO_OUTSIDE:
54
+                raise
55
+
45 56
             try:
46 57
                 direction = cls._get_direction_of_molecule(context, object_point, molecule_type)
47 58
             except NoMolecule:
@@ -49,8 +60,8 @@ class AntMoveBrainPart(MoveBrainPart):
49 60
         return direction
50 61
 
51 62
     @staticmethod
52
-    def _get_molecule_direction_for_point(context, point, molecule_type):
53
-        return DirectionMolecule.get_direction_for_point(context, point, molecule_type)
63
+    def _get_molecule_direction_for_point(context, point, molecule_type, molecule_way):
64
+        return DirectionMolecule.get_direction_for_point(context, point, molecule_type, molecule_way)
54 65
 
55 66
     @staticmethod
56 67
     def _get_direction_of_molecule(context, point, molecule_type):
@@ -66,6 +77,10 @@ class AntMoveBrainPart(MoveBrainPart):
66 77
 
67 78
     @classmethod
68 79
     def _get_direction_with_exploration_vector(cls, context, object_id):
80
+        exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
81
+        if exploration_vector == (0, 0):
82
+            raise ExplorationAlreadyResolved()
83
+
69 84
         ant_star = cls._get_by_pass_brain(context, object_id)
70 85
         ant_star.advance()
71 86
         return ant_star.get_host().get_moved_to_direction()
@@ -102,15 +117,30 @@ class AntMoveBrainPart(MoveBrainPart):
102 117
         """
103 118
         movement_mode = self._host_brain.get_movement_mode()
104 119
 
120
+        # TODO: Algo de depl. dans les brain part (ex. put)
121
+        put_fail_count = self._context.metas.value.get(PUT_FAIL_COUNT, self._host.get_id(), allow_empty=True,
122
+                                                       empty_value=0)
123
+        put_fail_count_max = Core.get_configuration_manager().get('ant.max_put_fail_count', 20)
124
+
105 125
         if movement_mode == MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
106 126
             self._arrived_at_home()
107 127
 
128
+        if movement_mode == MODE_SEARCH_AROUND and self._on_home_smell(self._context, self._host.get_id()):
129
+            self._arrived_at_home()
130
+
108 131
         elif movement_mode == MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
109 132
             self._start_new_exploration()
110 133
 
111 134
         elif movement_mode == MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
112 135
             self._init_exploration_vector()
113 136
 
137
+        elif movement_mode == MODE_HOME and put_fail_count >= put_fail_count_max:
138
+            self._host.get_brain().switch_to_mode(MODE_GO_OUTSIDE)
139
+            self._host._add_col(COL_PUT_OUTSIDE)  #  TODO: protege pas necessaire ?
140
+
141
+        elif movement_mode == MODE_GO_OUTSIDE and not self._on_home_smell(self._context, self._host.get_id()):
142
+            self._start_new_exploration()
143
+
114 144
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
115 145
 
116 146
     @classmethod

+ 8 - 2
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py Dosyayı Görüntüle

@@ -2,7 +2,7 @@ from intelligine.synergy.object.Food import Food
2 2
 from synergine.core.Core import Core
3 3
 from intelligine.core.exceptions import CantFindWhereToPut
4 4
 from intelligine.cst import MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, MODE_NURSE, TYPE_NURSERY, \
5
-    MODE_HOME, TYPE_RESOURCE_EATABLE, MODE_GOHOME, CARRY
5
+    MODE_HOME, TYPE_RESOURCE_EATABLE, MODE_GOHOME, CARRY, PUT_FAIL_COUNT, MODE_SEARCH_AROUND
6 6
 from intelligine.simulation.object.brain.part.transport.TransportBrainPart import TransportBrainPart
7 7
 from synergine_xyz.cst import POSITION, POSITIONS
8 8
 
@@ -13,7 +13,8 @@ class AntPutBrainPart(TransportBrainPart):
13 13
     _mode_matches.update({
14 14
         MODE_NURSE: [TYPE_NURSERY],
15 15
         MODE_HOME: [TYPE_RESOURCE_EATABLE],
16
-        MODE_GOHOME: []
16
+        MODE_GOHOME: [],
17
+        MODE_SEARCH_AROUND: []
17 18
     })
18 19
 
19 20
     _types_matches = {
@@ -23,6 +24,11 @@ class AntPutBrainPart(TransportBrainPart):
23 24
 
24 25
     @classmethod
25 26
     def can_put(cls, context, object_id, object_near_id):
27
+        put_fail_count = context.metas.value.get(PUT_FAIL_COUNT, object_id, allow_empty=True, empty_value=0)
28
+        put_fail_count_max = Core.get_configuration_manager().get('ant.max_put_fail_count', 20)
29
+        if put_fail_count >= put_fail_count_max:
30
+            return False
31
+
26 32
         # Si l'objet à coté fait partie des objets concernés par le mode du porteur
27 33
         if cls._match_with_mode(context, object_id, object_near_id):
28 34
             # Et si les objet sont rangeable enssemble:

+ 3 - 2
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py Dosyayı Görüntüle

@@ -1,7 +1,7 @@
1 1
 from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
2 2
 from intelligine.synergy.object.ressource.Ressource import Resource
3 3
 from intelligine.cst import MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, \
4
-    MODE_GOHOME, MODE_NURSE, TYPE_NURSERY, MODE_HOME
4
+    MODE_GOHOME, MODE_NURSE, TYPE_NURSERY, MODE_HOME, MODE_SEARCH_AROUND
5 5
 
6 6
 
7 7
 class AntTakeBrainPart(TakeBrainPart):
@@ -10,7 +10,8 @@ class AntTakeBrainPart(TakeBrainPart):
10 10
     _mode_matches = {
11 11
         MODE_EXPLO: [TYPE_RESOURCE_EXPLOITABLE],
12 12
         MODE_NURSE: [TYPE_NURSERY],
13
-        MODE_GOHOME: []
13
+        MODE_GOHOME: [],
14
+        MODE_SEARCH_AROUND: []
14 15
     }
15 16
 
16 17
     def __init__(self, host_brain):

+ 2 - 1
intelligine/synergy/Colony.py Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 from synergine.synergy.collection.SynergyCollection import SynergyCollection
2 2
 from intelligine.synergy.event.move.MoveAction import MoveAction
3 3
 from intelligine.synergy.event.attack.NearAttackableAction import NearAttackableAction
4
+from intelligine.synergy.event.transport.PutOutsideAction import PutOutsideAction
4 5
 from intelligine.synergy.event.transport.TakeableAction import TakeableAction
5 6
 from intelligine.synergy.event.transport.PutableAction import PutableAction
6 7
 from intelligine.synergy.event.CycleAction import CycleAction
@@ -11,7 +12,7 @@ class Colony(SynergyCollection):
11 12
     def __init__(self, configuration):
12 13
         super().__init__(configuration)
13 14
         self._actions = [MoveAction, NearAttackableAction, TakeableAction, PutableAction,
14
-                         CycleAction]
15
+                         CycleAction, PutOutsideAction]
15 16
         self._start_position = configuration.get_start_position()
16 17
 
17 18
     def get_start_position(self):

+ 4 - 0
intelligine/synergy/event/move/MoveAction.py Dosyayı Görüntüle

@@ -15,6 +15,10 @@ class MoveAction(Action):
15 15
         self._move_to_direction = None
16 16
 
17 17
     def run(self, obj, context, synergy_manager):
18
+        if self._parameters.get(MoveEvent.PARAM_NEW_MODE, None):
19
+            obj.get_brain().switch_to_mode(self._parameters[MoveEvent.PARAM_NEW_MODE])
20
+            return
21
+
18 22
         try:
19 23
             self._apply_move(obj, context)
20 24
         except ActionAborted:

+ 5 - 1
intelligine/synergy/event/move/MoveEvent.py Dosyayı Görüntüle

@@ -1,4 +1,4 @@
1
-from intelligine.core.exceptions import UnableToFoundMovement
1
+from intelligine.core.exceptions import UnableToFoundMovement, MovementModeExpired
2 2
 from intelligine.synergy.event.move.direction import get_position_with_direction_decal
3 3
 from intelligine.shorcut.brain import get_brain_part
4 4
 from synergine.core.exceptions import NotConcernedEvent
@@ -12,6 +12,7 @@ class MoveEvent(Event):
12 12
 
13 13
     PARAM_POSITION = 'pos'
14 14
     PARAM_DIRECTION = 'dir'
15
+    PARAM_NEW_MODE = 'mod'
15 16
 
16 17
     _mechanism = Mechanism
17 18
     _concern = COL_WALKER
@@ -21,6 +22,9 @@ class MoveEvent(Event):
21 22
             direction = self._get_direction(object_id, context)
22 23
         except UnableToFoundMovement:
23 24
             raise NotConcernedEvent()
25
+        except MovementModeExpired as movement_expired:
26
+            parameters[self.PARAM_NEW_MODE] = movement_expired.get_switch_to_mode()
27
+            return parameters
24 28
 
25 29
         object_point = context.metas.value.get(POSITION, object_id)
26 30
         move_to_point = get_position_with_direction_decal(direction, object_point)

+ 19 - 0
intelligine/synergy/event/transport/PutOutsideAction.py Dosyayı Görüntüle

@@ -0,0 +1,19 @@
1
+from intelligine.cst import CANT_CARRY_STILL, BRAIN_PART_PUT, COL_PUT_OUTSIDE, MODE_EXPLO
2
+from intelligine.synergy.event.transport.PutOutsideEvent import PutOutsideEvent
3
+from intelligine.synergy.event.transport.PutableAction import PutableAction
4
+
5
+
6
+class PutOutsideAction(PutableAction):
7
+    _listen = PutOutsideEvent
8
+
9
+    def run(self, obj, context, synergy_manager):
10
+        # TODO: Refact avec pare,t
11
+        obj_transported = obj.get_carried()
12
+        obj_transported.set_carried_by(None)
13
+        obj.put_carry(obj_transported, self._parameters['position_to_put'])
14
+        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
15
+        obj.reinit_put_fail_count()
16
+
17
+        #  obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
18
+        obj._remove_col(COL_PUT_OUTSIDE)
19
+        obj.get_brain().switch_to_mode(MODE_EXPLO)  # TODO: dans le brain.done

+ 30 - 0
intelligine/synergy/event/transport/PutOutsideEvent.py Dosyayı Görüntüle

@@ -0,0 +1,30 @@
1
+from synergine.core.exceptions import NotConcernedEvent
2
+from synergine_xyz.cst import POSITION
3
+from intelligine.cst import COL_PUT_OUTSIDE
4
+from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
5
+from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
6
+from intelligine.synergy.event.Event import Event
7
+
8
+
9
+# TODO: NearEvent ?
10
+class PutOutsideEvent(Event):
11
+
12
+    _concern = COL_PUT_OUTSIDE
13
+
14
+    def _prepare(self, object_id, context, parameters={}):
15
+        # TODO: DEV code ailleurs (._)
16
+        if AntMoveBrainPart._on_home_smell(context, object_id):
17
+            raise NotConcernedEvent()
18
+
19
+        current_position = context.metas.value.get(POSITION, object_id)
20
+        around_positions = context.get_around_points_of(current_position)
21
+
22
+        for around_position in around_positions:
23
+            # TODO DEV: ... ._
24
+            if AntPutBrainPart._position_have_free_space_around(context, around_position):
25
+                if AntPutBrainPart._position_is_enought_place(context, around_position):
26
+                    # TODO: Constant ?
27
+                    parameters['position_to_put'] = around_position
28
+                    return parameters
29
+
30
+        raise NotConcernedEvent()

+ 3 - 3
intelligine/synergy/event/transport/PutableAction.py Dosyayı Görüntüle

@@ -11,13 +11,12 @@ class PutableAction(Action):
11 11
     _listen = PutableEvent
12 12
     _depend = [MoveAction]
13 13
 
14
-    def __init__(self, object_id, parameters):
15
-        super().__init__(object_id, parameters)
16
-
17 14
     def run(self, obj, context, synergy_manager):
18 15
         obj_transported = obj.get_carried()
19 16
 
20 17
         if not self._parameters[PutableEvent.PARAM_PUT_TO]:
18
+            if self._parameters[PutableEvent.PARAM_HOME_FAIL]:
19
+                obj.increment_put_fail_count()
21 20
             raise ActionAborted()
22 21
 
23 22
         for position_to_put in self._parameters[PutableEvent.PARAM_PUT_TO]:
@@ -30,6 +29,7 @@ class PutableAction(Action):
30 29
             obj_transported.set_carried_by(None)
31 30
             obj.put_carry(obj_transported, position_to_put)
32 31
             context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
32
+            obj.reinit_put_fail_count()
33 33
 
34 34
             obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
35 35
 

+ 4 - 1
intelligine/synergy/event/transport/PutableEvent.py Dosyayı Görüntüle

@@ -13,6 +13,7 @@ class PutableEvent(NearEvent):
13 13
 
14 14
     PARAM_PUT = 'put'
15 15
     PARAM_PUT_TO = 'put_to'
16
+    PARAM_HOME_FAIL = 'home_fail'
16 17
     _mechanism = AroundMechanism
17 18
     _concern = COL_TRANSPORTER_CARRYING
18 19
     _near_name = 'objects_ids_putable'
@@ -37,12 +38,14 @@ class PutableEvent(NearEvent):
37 38
                     put_position = brain_part.get_put_position(context, object_id, object_near_id)
38 39
                     parameters[self.PARAM_PUT].append(object_near_id)
39 40
                     parameters[self.PARAM_PUT_TO].append(put_position)
41
+                    parameters[self.PARAM_HOME_FAIL] = False
40 42
                     return parameters  # Si a terme on veut tous les calculer a l'avance, ne pas retourner ici
41 43
                 except CantFindWhereToPut:
42 44
                     pass  # On continu la booucle
43 45
 
44 46
         # Si a terme on veut tous les calculer a l'avance, raise que si rien trouve
45
-        raise NotConcernedEvent()
47
+        parameters[self.PARAM_HOME_FAIL] = True
48
+        return parameters
46 49
 
47 50
     @staticmethod
48 51
     def _can_put(object_id, context):

+ 14 - 2
intelligine/synergy/object/ant/Ant.py Dosyayı Görüntüle

@@ -2,7 +2,7 @@ from intelligine.core.exceptions import MoleculeException
2 2
 from intelligine.synergy.object.Bug import Bug
3 3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4 4
     COL_FIGHTER, MODE_EXPLO, MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
-    COL_TRANSPORTER_CARRYING, MODE_NURSE, MODE_HOME, CARRY
5
+    COL_TRANSPORTER_CARRYING, MODE_NURSE, MODE_HOME, CARRY, PUT_FAIL_COUNT
6 6
 from intelligine.synergy.object.Food import Food
7 7
 from intelligine.simulation.object.molecule.MovementMoleculeGland import MovementMoleculeGland
8 8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
@@ -25,6 +25,7 @@ class Ant(Bug):
25 25
         #  TODO: Comme pour lorsque une action put est faite, lancer un algo de choix de la mission a suivre.
26 26
         self._brain.switch_to_mode(MODE_EXPLO)
27 27
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
28
+        self._put_fail_count = 0
28 29
 
29 30
     def die(self):
30 31
         super().die()
@@ -85,4 +86,15 @@ class Ant(Bug):
85 86
                 pass
86 87
 
87 88
     def get_colony(self):
88
-        return self.get_collection()
89
+        return self.get_collection()
90
+
91
+    def get_put_fail_count(self):
92
+        return self._put_fail_count
93
+
94
+    def increment_put_fail_count(self):
95
+        self._put_fail_count += 1
96
+        self._context.metas.value.set(PUT_FAIL_COUNT, self.get_id(), self._put_fail_count)
97
+
98
+    def reinit_put_fail_count(self):
99
+        self._put_fail_count = 0
100
+        self._context.metas.value.set(PUT_FAIL_COUNT, self.get_id(), self._put_fail_count)