Permalink
Browse files

Begin the implementation of the issue system.

The first issue that will be implemented must be the surpopulation,
because we can easily assume it would be a root cause for colonization.
  • Loading branch information...
1 parent 19bf9f9 commit 7743507c800f5c0ff7ec3737853a99603f8395ef @laarmen committed Mar 9, 2012
Showing with 45 additions and 1 deletion.
  1. +45 −1 faction_ai.py
View
@@ -24,6 +24,17 @@ def __init__(self):
galaxy = Galaxy()
+class Issue(object):
+ pass
+
+class Surpopulation(Issue):
+ def __init__(self, system):
+ self.system = system
+ self.remaining = system.population - system.sysresources.max_population
+ def get_resolution_conditions(self):
+ # TODO
+ return []
+
class SystemResources(object):
def __init__(self, coords):
self.x, self.y, self.z = coords
@@ -51,6 +62,11 @@ def __init__(self, sysresources, economy, government, population):
def get_surroundings(self):
return galaxy.hypercube(16, self.sysresources, 3)
+ def introspect(self):
+ if self.population >= self.max_population and not self.signaled['surpopulation']:
+ self.signaled['surpopulation'] = Surpopulation(self)
+ self.faction.register_issue(self.signaled['surpopulation'])
+
class Faction(object):
def __init__(self, origin):
@@ -64,6 +80,34 @@ def __init__(self, origin):
def register_issue(self, issue, tree = None):
raise NotImplementedError
+# The way I want to go for the issue management is to have several trees of issues,
+# each node containing an issue and its dependencies as children nodes. As long as
+# the dependencies are not resolved, we don't treat the issue.
+# An issue can be here a general problem (surpopulation) or a specific need such as 1 ton
+# of minerals, or some specific needed in a specific system.
+# The issue registration is always delegated to the Faction implementations because some
+# regimes can ignore some benign requests, etc...
def Federation(Faction):
- pass
+ def register_issue(self, issue, tree = None):
+ if isinstance(issue, Surpopulation):
+ print 'A system is too crowded !'
+ if tree = None: # tree can easily be [], so we can't use the 'or' trick.
+ tree = []
+ self.issue_trees.append(tree)
+ subtree = []
+ tree.append((issue, subtree))
+ for c in issue.get_resolution_conditions():
+ self.assess_condition(c, subtree)
+
+def main():
+ # Select a system suitable for the origin.
+ sol_like = (lambda n, depth:
+ n.element.max_population == 5 and n.element.inhabitable and n.element.minerals >= 2 and n.element.terraformable and not n.element.terraformable)
+ recurs_pred = lambda n, depth: [] if sol_like(n, depth) else [x for x in (n.left_child, n.right_child) if x]
+
+ sol = System(galaxy.subset(sol_like, recurs_pred)[0], "capitalist", "lib_democratic") # Let's assume there is at least one result.
+
+ sol.population = 10 # Sol is in surpopulation.
+ earth_federation = Federation(sol)
+ factions = [earth_federation]

0 comments on commit 7743507

Please sign in to comment.