Total Complexity | 11 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled |
||
5 | class MoleculeGland(): |
||
6 | |||
7 | def __init__(self, host, context): |
||
8 | self._molecule_type = None |
||
9 | self._host = host |
||
10 | self._context = context |
||
11 | self._enabled = False |
||
12 | |||
13 | def set_molecule_type(self, molecule_type): |
||
14 | self._molecule_type = molecule_type |
||
15 | |||
16 | def get_molecule_type(self): |
||
17 | if self._molecule_type is None: |
||
18 | raise Exception("molecule_type not specified") |
||
19 | return self._molecule_type |
||
20 | |||
21 | def get_molecule(self): |
||
22 | raise NotImplementedError() |
||
23 | |||
24 | def appose(self): |
||
25 | if not self._enabled: |
||
26 | raise MoleculeGlandDisabled() |
||
27 | |||
28 | try: |
||
29 | DirectionMolecule.appose(self._context, |
||
30 | self._host.get_position(), |
||
31 | self.get_molecule()) |
||
32 | except BestMoleculeHere as best_molecule_here: |
||
33 | self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance()) |
||
34 | |||
35 | def disable(self): |
||
36 | self._enabled = False |
||
37 | |||
38 | def enable(self): |
||
39 | self._enabled = True |
||
40 | |||
41 | def is_enabled(self): |
||
42 | return self._enabled |